首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >R代码临床试验

R代码临床试验
EN

Stack Overflow用户
提问于 2013-06-07 21:22:37
回答 1查看 199关注 0票数 0

这是我运行临床试验的代码,以显示试验成功的概率。我的问题是,我需要证明,通过引入第二组样本(n.2),需要多少个样本才能产生高于阈值90%的值。任何帮助,请,我知道我需要循环我的代码,但我有困难这样做。

代码语言:javascript
运行
复制
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
EN

回答 1

Stack Overflow用户

发布于 2013-06-11 00:39:47

这不是一个完整的答案,只是为了弄清楚OP的目的。

使用for循环的基本策略:

代码语言:javascript
运行
复制
threshold <- somevalue
for(i in someseq){
    output <- somefunction(...)
    if(output > threshold)
        break
}
output

while循环的基本策略:

代码语言:javascript
运行
复制
threshold <- somevalue
below.threshold <- TRUE
while(below.threshold){
    output <- somefunction(...)
    if(output > threshold)
        below.threshold <- FALSE
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16985243

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档