当向 Jags 模型提供数据时,节点显示错误

问题描述

我在用 Rjags 和 runjags 复制这个纸模型 http://dx.doi.org/10.1080/00031305.2017.1328374 时遇到了麻烦。这是我正在使用的模型

library(rjags)
library(runjags)
modelo= "
  model{
for(i in 1:n){
#
# Likelihood part
#
censored[i] ~ dinterval(survival[i],censoring_limits[i])
# To deal with censoring:
# censored equals 1 for Benedict XVI as of 25/12/2016,# 0 for the other popes.
# and the survival times of the other popes.
# censoring_limits equals 11.7 for Benedict XVI,# and values (e.g. 32) greater than or equal to
# the survival times of the other popes.
survival[i] ~ dweib(r,mu[i]) # Basic Weibull assumption
mu[i] <- exp(beta[i]) # Defining beta as log(mu)
beta[i] <- beta_0 + beta_1*x_1[i] + beta_2*x_2[i]
# beta = log(mu) is a linear function of the covariates
}
#
####################################################
#
# Priors
#
beta_0 ~ dnorm(0.0,1.0e-4) # Prior on beta_0 is normal with low precision
beta_1 ~ dnorm(0.0,1.0e-4) # Prior on beta_1 is normal with low precision
beta_2 ~ dnorm(0.0,1.0e-4) # Prior on beta_2 is normal with low precision
#
r ~ dexp(0.001) # Prior on r
#
####################################################
#
# Define the alphas
#
alpha_0 <- - beta_0 / r
alpha_1 <- - beta_1 / r
alpha_2 <- - beta_2 / r
#
# Percentage increases
#
percentage_increase_age <- 100*(exp(alpha_1) - 1)
percentage_increase_year <- 100*(exp(alpha_2) - 1)
#
####################################################
#
# Posterior median at varIoUs covariate values
#
beta_med <- beta_0 + beta_1*x_1_new + beta_2*x_2_new
# New values need to be supplied
t_median <- pow(log(2) * exp(-beta_med),1 / r)
#
####################################################
#
# Predictive distribution of age at the new values
#
beta_Francis <- beta_0 + beta_1*age_Francis + beta_2*year_Francis
# Values of age_Francis and year_Francis need to be provided
mu_Francis <- exp(beta_Francis)
survival_Francis~ dweib(r,mu_Francis)T(present_length,upper_length)
# Take into account the current pontificate length
# Also specify a sensible upper bound
age_Francis_predictive <- age_at_election + survival_Francis
# Work also with age
}"
writeLines(modelo,con = "TEMPmodel.txt")

我用来提供模型的数据库位于文章链接的补充部分(顶部)。这就是我将数据提供给模型的方式

writeLines(modelo,con = "TEMPmodel.txt")
base1<-read.csv("C:/Users/jgush/Downloads/popes_25_December_2016.csv")
base1<-base1[-c(1),]
#base1$Survival[1]<-NA
base1$Censoring_limits<-ifelse(base1$Censored==1,11.7,32)
datalist<-list("survival"=base1$Survival,"censoring_limits"=base1$Censoring_limits,"n"=length(base1$Year.Elected),"censored"=base1$Censored,"age_at_election"=76.29,"age_Francis"=80.1,"year_Francis"=2013,"x_1_new"=75,"x_2_new"=1666,"present_length"=3.79,"upper_length"=17,"x_1"=base1$Age.Election,"x_2"=base1$Year.Elected)
modelo.con.jags <- jags.model(file = "TEMPmodel.txt",data = datalist,n.adapt = 500) # Burning-period

而且我总是收到下一个错误“update.jags(object,n.iter,...) 中的错误:节点生存中的错误[1] 未能计算对数密度" 我不知所措我不知道为什么会发生错误 任何帮助将不胜感激。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)