r - Minimum sample size n such that difference is no more than
问题描述
What is the minimum sample size n (or the length n = length(x) of the data vector x) such that the difference D = 1 - statx4(x)/statx5(x) of the functions statx4 and statx5 is no more than 1/100 i.e. D ≤ 1/100?
And here are the functions:
statx4 <- function(x) {
numerator <- sum((x-mean(x))^2)
denominator <- length(x)
result <- numerator/denominator
return(result)
}
statx5 <- function(x) {
numerator <- sum((x-mean(x))^2)
denominator <- length(x)-1
result <- numerator/denominator
return(result)
}
I've been doing this exercise set for a while, but haven't managed to get anything valid on this question. Could you point me to right direction?
解决方案
For the normal distribution, it is the following:
statx4 <- function(x) {
numerator <- sum((x-mean(x))^2)
denominator <- length(x)
result <- numerator/denominator
return(result)
}
statx5 <- function(x) {
numerator <- sum((x-mean(x))^2)
denominator <- length(x)-1
result <- numerator/denominator
return(result)
}
D <- function(x){
1-statx4(x)/statx5(x)
}
DD <- function(N=1111,seed =1){
set.seed(seed)
Logi <- vector()
for (n in 1:N) {
x<- rnorm(n)
y <- D(x)
Logi[n] <- (y > 1/100)
}
return(Logi)
}
min <- vector()
for (seed in 1:100) {
message(seed)
DD(1000,seed)
min[seed] <- length(which(DD(1000) == TRUE))
}
Answer <- mean(min)+1
Answer
Note that the function D
evaluates the difference of the unbiased variance and the ordinal variance.
I think this problem should be more clear in mathematical sense.
推荐阅读
- python - Python数学问题我的结果非常接近示例但机器人相同
- c - int i 在这个特定程序的 for 循环中(在 scanf 和 sum 中)做了什么?
- awk - 模式匹配/排除(awk/sed)
- flutter - 如何在文本选择工具栏中添加新选项
- wordpress -
链接中断代码在function.php(Polylang)中不起作用 - html - 我如何使用引导程序在输入框中添加按钮
- javascript - jQuery 和 HTML,如何在下拉切换菜单中使用本地存储
- time - ffmpeg - 避免生成文件的持续时间近似
- c - C 如何简化这个 For 循环
- asp.net-mvc - 无法使用剃须刀页面在 asp.netcore 中保存下拉列表