0

我有一个索赔计数数据集,其中 y 作为索赔计数,16 个协变量,即 x1 到 x16(由 0 和 1 组成),我将其排列在一个名为 X 和 E 的设计矩阵中作为曝光(也称为偏移)。我正在尝试使用 JAGS 将泊松回归拟合到这个数据集。我为模型部分编写的代码如下:

Poisson.model <- function(){
    for(i in 1:N){
        y[i] ~ dpois(lambda[i])
        log(lambda[i]) <- log(E[i]) + beta1+ beta2*x1[i] + beta3*x2[i] +  beta4*x3[i] + beta5*x4[i] + beta6*x5[i] + beta7*x6[i] + beta8*x7[i] + beta9*x8[i] + beta10*x9[i] + beta11*x10[i] + beta12*x11[i] + beta13*x12[i] + beta14*x13[i] + beta15*x14[i] + beta16*x15[i] + beta17*x16[i]
}
###declare priors 
beta1 ~ dnorm(0,0.0001)
beta2 ~ dnorm(0,0.0001)
beta3 ~ dnorm(0,0.0001)
beta4 ~ dnorm(0,0.0001)
beta5 ~ dnorm(0,0.0001)
beta6 ~ dnorm(0,0.0001)
beta7 ~ dnorm(0,0.0001)
beta8 ~ dnorm(0,0.0001)
beta9 ~ dnorm(0,0.0001)
beta10 ~ dnorm(0,0.0001)
beta11 ~ dnorm(0,0.0001)
beta12 ~ dnorm(0,0.0001)
beta13 ~ dnorm(0,0.0001)
beta14 ~ dnorm(0,0.0001)
beta15 ~ dnorm(0,0.0001)
beta16 ~ dnorm(0,0.0001)
beta17 ~ dnorm(0,0.0001)

}

我的问题是,1)如何将 X 和 beta 作为矩阵乘法来替换 log(lambda[i]) 右侧的冗长方程 2)如何将先验简化为单行?

4

1 回答 1

4

使用函数inprod和函数model.matrix传递矩阵如下

X<-model.matrix(~covariate1+covariate2,data=data)

for(i in 1:17){ beta[i] ~ dnorm(0, 0.0001)}

inprod(beta[], X[i,])+log(E[i])
于 2014-04-13T23:27:39.410 回答