我试图在JAGS中参数化伽玛分布 - 使用分段线性预测器,但我的模型无法运行,并显示以下错误消息:
Error: Error in node (ashape/(aexp(mu[59]))) Invalid parent values
当wood.recovery从正态分布中提取时,该模型有效,但较低的分位数预测小于零,这在生物学上是不可能的。我尝试了一些技巧,比如在#" mu"参数以防它绘制零,根据glm的输出设置初始值;但是都没有解决错误消息。我将非常感谢任何见解[我使用R2jags]。我的模特:
cat (
"model {
# UNINFORMATIVE PRIORS
sd_plot ~ dunif(0, 100)
tau_plot <- 1/(sd_plot * sd_plot)
# precision for plot level variance
alpha ~ dnorm(0, 1e-06)
# normal prior for intercept term
shape ~ dunif(0, 100)
# shape parameter for gamma
log_intensity ~ dnorm(0, 1e-06)
# uninformative prior for logging intensity
beta_1 ~ dnorm (0, 1e-06)
# uninformative prior; change in slope for first segment : <=3.6 years
beta_2 ~ dnorm (0, 1e-06)
# uninformative prior; change in slope for first segment : >3.6 years
InX_1 ~ dnorm (0, 1e-06)
# uniformative prior for interaction between tsl and log_intensity : <=3.6 years
InX_2 ~ dnorm (0, 1e-06)
# uniformative prior for interaction between tsl and log_intensity : >3.6 years
# PLOT LEVEL RANDOM EFFECTS
for (i in 1:nplots) {
plot_Eff[i] ~ dnorm(0,tau_plot)
}
for (i in 1:Nobs) {
# PIECEWISE LINEAR PREDICTOR
mu[i] <-
alpha +
beta_1 * (time.since.logged[i] * tsl.DUM1[i]) +
log_intensity * log.volume [i] +
beta_2 * (time.since.logged[i] * tsl.DUM2[i] - 3.6) +
beta_1 * (time.since.logged[i] * tsl.DUM2[i]) +
plot_Eff[plot.id[i]] +
InX_1 * (time.since.logged[i] * tsl.DUM1[i]) * log.volume [i] +
InX_2 * (time.since.logged[i] * tsl.DUM2[i] - 3.6) * log.volume[i] +
InX_1 * (time.since.logged[i] * tsl.DUM2[i]) * log.volume[i]
timber.recovery[i] ~ dgamma(shape,shape/exp(mu[i]))
# observed recovery
pred_timber_recovery[i] ~ dgamma(shape,shape/exp(mu[i]))
# posterior predictive distribution
pearson.residual[i] <-
(timber.recovery[i] - pred_timber_recovery[i]) / (sqrt(timber.recovery[i]))
}
}",
fill = TRUE,
file = "outputs/piecewise_TIMBER_MODEL_FINAL_GAMMA.txt")