求助高人,下列程序运行报错,和解?不胜感激。
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