0

これは、臨床試験が成功する可能性を示すために臨床試験を実行するための私のコードです。私の問題は、サンプルの 2 番目のセット (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
4

1 に答える 1

0

[これは完全な回答ではありませんが、単に OP の目的を明確にするためです。]

for ループを使用した基本的な戦略:

threshold <- somevalue
for(i in someseq){
    output <- somefunction(...)
    if(output > threshold)
        break
}
output

while ループを使用した基本的な戦略:

threshold <- somevalue
below.threshold <- TRUE
while(below.threshold){
    output <- somefunction(...)
    if(output > threshold)
        below.threshold <- FALSE
}
于 2013-06-10T16:39:46.820 に答える