1

I am trying to estimate a Bayesian logistic model with with a weakly informative Cauchy prior with location=0 and scale=2.5 (Gelman et al, 2008). I am using MCMClogit in the MCMCpack package:

df = read.csv("http://dl.dropbox.com/u/1791181/MCMC.csv")#Read in data
library(MCMCpack)

logpriorfun <- function(beta, location, scale){
  sum(dcauchy(beta, location, scale, log=T))
} #From the MCMCpack documentation
mcmc.logit = MCMClogit(SECONDARY.LEVEL ~ AGE + SEX + as.factor(DISTRICT), 
                       tune=.25, 
                       user.prior.density=logpriorfun, location=0, scale=2.5, log=T,
                       mcmc=10000, 
                       data=df)

But I keep getting the error message below:

Error in MCMClogit(SECONDARY.LEVEL ~ AGE + SEX + as.factor(DISTRICT),  :
  REAL() can only be applied to a 'numeric', not a 'NULL'

I can't see any obvious problem with either the code or the data. The code runs fine if I take out the prior option. I would appreciate any pointers.

4

1 回答 1

0

虽然我不知道问题的原因,但我相信说您可以MCMClogit使用不同的种子重新运行以获得有效的后验估计是相对节省的。如果您使用相同的种子重新运行,错误将再次发生。在蒙特卡洛/重新​​采样设置中,使用tryCatch随机种子设置MCMClogit以避免崩溃似乎是明智之举。

于 2019-04-29T14:50:56.040 回答