r - 我的 P 值远低于我的预期,无法建立适当的功率曲线
问题描述
pval.dist.sim = function(n, sigma_x, rho, reps = 2500){
p = 5; sigma = sqrt(2)
beta = c(0.5, 0.5, 0, 0.25, 0)
mu = 10
# generate vector for pvals
pval.list = numeric(reps)
for(r in 1:reps){
# generate design matrix
X = gen_X(n = n, p = 5, rho = rho, sigma_x = sigma_x, mu = mu)
# generate the XtXinv portion of equation
XtXinv = qr.solve(crossprod(X))
sqrtXtXinv55 = sqrt(XtXinv[5,5])
y = X %*% beta + rnorm(n = n)
beta.hat = XtXinv %*% crossprod(X, y)
sE = sqrt(sum((y - X %*% beta.hat)^2)/(n-p))
t.val = beta.hat[3]/(sE * sqrtXtXinv55)
pval.list[r] = 2 * pt(-abs(t.val), df = n - p)
}
return(pval.list)
}
上面是 pval.dist 模拟。我需要运行这个函数来构建我的 p.values 来构建我的功率曲线
set.seed(3701)
# givens
p = 5; d = 2; mu = 10; sigmasqrd = 2; reps = 2500
n.list = seq(from=10, to=150, by=10)
# create a vector for the estimates of the power
est.power = numeric(length(n.list))
# create a vector for the left endpoints of the 95% CI
LB.list = numeric(length(n.list))
# create a vector for the right endpoints of the 95% CI
UB.list = numeric(length(n.list))
for(j in 1:length(n.list)){
# perform the test reps times
pvals = pval.dist.sim(n = n.list[j], sigma_x = 1.5, rho = 0.2, reps = reps )
# record the simulated estimate of the power
est.power[j] = mean(pvals<0.05)
# compute the 95% conf int
bounds = binom.test(x=sum(pvals < 0.05), n = reps, conf.level = 0.95)$conf.int[1:2]
LB.list[j] = bounds[1]
UB.list[j] = bounds[2]
}
## plot the power curve estimation
plot(n.list, est.power, t = "l", xlab = "n",ylab = "Power")
我遇到的问题是我的 pvalue 在插入时非常低。我得到个位数百分比的值。我究竟做错了什么?
解决方案
推荐阅读
- java - 如何从xslt中的excel表中获取键的对应值
- c# - 用于比较的订单日期列表
- javascript - 重新加载页面时保持引导侧边栏的状态
- javascript - 使用传单 maxbounds 设置边界但不起作用
- laravel-5 - 两个字节字符在 Laravel excel 中不起作用
- python - python中的列表中间元素提取列表
- python - 删除python中的双引号
- scala - Scala案例类递归
- javascript - 混合批处理/jscript/hta:读取 Jscript 中的 2 个输入并将它们传递给批处理
- qt - Qt 将数据从父小部件发送到子小部件