0

这是我们的第一个模型:

# Data:
x1 = as.factor(c(0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1))
x2 = as.factor(c(0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1))
x3 = as.factor(c(0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1))
x4 = as.factor(c(0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1))
n = rep(1055, 16)
y = c(239, 31, 15, 11, 7, 5, 18, 100, 262, 32, 38, 32, 8, 7, 16, 234)

# Model:
mymodel = function(){
  for (i in 1:16){
    y[i] ~ dbin(theta[i], n[i] )
    eta[i] <- gamma*x1[i]+beta1*x2[i]+beta2*x3[i]+beta3*x4[i]
    theta[i] <- 1/(1+exp(-eta[i]))
  }

  # Prior
  gamma ~ dnorm(0,0.00001) 
  beta1 ~ dnorm(0,0.00001)
  beta2 ~ dnorm(0,0.00001)
  beta3 ~ dnorm(0,0.00001)
}

现在我们被要求将 alpha 添加为 Normal,具有已知的均值和未知的方差。但是如图所示,方差有一个统一的先验:

型号说明

不知道怎么给模型加alpha,然后在priors中指定新参数...

4

1 回答 1

0

您只需添加alpha到您的线性预测器中,并像其他任何参数一样给它一个分布。但是,JAGS将正态分布参数化为精度而不是方差(精度只是方差的倒数)。该模型将看起来像这样。此外,您可以只使用logit(eta)而不是应用逆 logit。

mymodel = function(){
  for (i in 1:16){
    y[i] ~ dbin(eta[i], n[i] )
    logit(eta[i]) <- alpha + gamma*x1[i]+beta1*x2[i]+beta2*x3[i]+beta3*x4[i]
  }

  # Prior
  alpha ~ dnorm(0, tau_alpha)
  tau_alpha <- 1 / var_alpha
  var_alpha ~ dunif(0, 10)
  gamma ~ dnorm(0,0.00001) 
  beta1 ~ dnorm(0,0.00001)
  beta2 ~ dnorm(0,0.00001)
  beta3 ~ dnorm(0,0.00001)
}
于 2017-08-21T14:20:25.320 回答