楼主: wqhx620
1279 0

[程序分享] R程序报错求助 [推广有奖]

  • 1关注
  • 1粉丝

已卖:1份资源

硕士生

53%

还不是VIP/贵宾

-

威望
0
论坛币
1049 个
通用积分
2.8500
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
4101 点
帖子
203
精华
0
在线时间
106 小时
注册时间
2010-1-19
最后登录
2025-7-24

楼主
wqhx620 发表于 2017-4-10 17:05:21 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
求助高人,下列程序运行报错,和解?不胜感激。

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


二维码

扫码加我 拉你入群

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

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

关键词:R程序 distribution generating increment Parameter

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-9 06:07