这是我运行临床试验的代码,以显示试验成功的概率。我的问题是,我需要证明,通过引入第二组样本(n.2),需要多少个样本才能产生高于阈值90%的值。任何帮助,请,我知道我需要循环我的代码,但我有困难这样做。
calc.quant = function( n, X.1, a, b, n.2, nsim, thr, p1=0.025, p2=0.975 )
{
a.star = a + n
b.star = b + n - X.1
theta = rbeta( nsim, a.star, b.star
X.2 = rbinom( nsim, n.2, theta )
theta.p1p2 = matrix( 0, nrow=nsim, ncol=2 )
for( j in 1:nsim ) {
theta.p1p2[j,] = qbeta( c( p1, p2 ), a.star + X.2[j], b.star + n.2 - X.2[j] )
}
return( theta.p1p2 )
}
n = 117
X.1 = 110
a = 1
b = 1
n.2 = 50
nsim = 1000
thr = .90
res = calc.quant( n, X.1, a, b, n.2, nsim, thr )
sum( res[,1] > thr ) / nsim发布于 2013-06-11 00:39:47
这不是一个完整的答案,只是为了弄清楚OP的目的。
使用for循环的基本策略:
threshold <- somevalue
for(i in someseq){
output <- somefunction(...)
if(output > threshold)
break
}
outputwhile循环的基本策略:
threshold <- somevalue
below.threshold <- TRUE
while(below.threshold){
output <- somefunction(...)
if(output > threshold)
below.threshold <- FALSE
}https://stackoverflow.com/questions/16985243
复制相似问题