全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
1238 0
2017-04-10
求助高人,下列程序运行报错,和解?不胜感激。

minNforHDIpower = function( genPriorMean=0.65, genPriorN=2000,
                                        HDImaxwid=NULL, nullVal=0.5, ROPE=c(nullVal, nullVal),
                                        desiredPower=0.8, audPriorMean=0.5, audPriorN=2,
                                        HDImass=0.95, initSampSize=20, verbose=T )
{
If (is.null(HDImaxwid) + is.null(nullVal) !=1) {
  stop(“One and only one of HDImaxwid and nullVal must be specified.”)
  }
# Convert prior mean and N to a, b parameter values of beta distribution.
genPriorA=genPriorMean * genPriorN
genPriorB=(1.0-genPriorMean) * genPriorN
audPriorA=audPriorMean * audPriorN
audPriorB=( 1.0-audPriorMean) * audPriorN

# Initialize loop for incrementing sampleSize.
sampleSize = initSampSize
notPowerfulEnough = TRUE

# Increment sampleSize until desired power is achieved.
while( notPowerfulEnough) {
   zvec = 0:sampleSize
   # Compute prob of each z value for data-generating prior.
        Pzvec = exp( lchoose( sampleSize, zvec )
                        + lbeta(zvec + genPriorA, sampleSize - zvec + genPriorB )
-        Ibeta(genPriorA, genPriorB))
# For each z value, compute HDI, hdiMat is min, max of HDI for each z.
hdiMat = matrix(0, nrow=length(zvec), ncol=2)
for (zIdx in 1:length(zvec)) {
z=zvec[zIdx]
hdiMat[zIdx,] = HDIofICDF( qbeta, shape1 = z + audPriorA,
                                shape2 = sampleSize – z + audPriorB) }
hdiWid = hdiMat[, 2] – hdiMat[, 1]
if ( !is.null(HDImaxwid)) {
  powerHDI = sum( pzvec[ hdiWid < HDImaxwid])
}
If (!is.null(nullVal)) {
  powerHDI = sum( pzvec[ hdiMat[, 1] > ROPE[2] | hdiMat[, 2] < ROPE[1] ] )
  }
If (verbose) {
Cat(“For sample size = “, sampleSize, “, power=”, powerHDI, “\n”, sep=””); flush.console()
}
If (powerHDI > desiredPower) {
notPowerfulEnough = FALSE} else { sampleSize = sampleSize + 1
}
} # End while(notPowerfulEnough)
# Return the minimal sample size that achieved the desired power.
return( sampleSize)
} # End of function


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群