I am trying to perform group variable selection on a random intercept model using spike and slab priors in WinBUGS. However, I think it is trapping and I keep getting the error message "NIL dereference (read)" when running my code. I'm not sure what's causing this error or how to fix it. I tried running this using R2WinBUGS but it gets trap, so I tried using the WinBUGS software and I get the same error message above.
Here's a simplified version of my code:
model
{
for (i in 1:N) {
y[i] ~ dbern(pi[i])
logit(pi[i]) <- X[i,]*xbeta[] + Z[i,]*beta[] + U[id[i]]
}
for (j in 1:p) {
gamma[j] ~ dbern(tau)
for(t in 1:T){
slab[j] ~ dnorm(0, prec_beta)
beta[7*(j-1)+t] <- slab[j]* gamma[j]
}
}
for(nn in 1:n){
U[nn] ~ dnorm(0, prec_u)
}
for(qq in 1:(q+1)){
xbeta[qq] ~ dnorm(0, 0.001)
}
tau ~ dbeta(3, p)
prec_beta ~ dgamma(0.001, 0.001)
prec_u ~ dgamma(0.001, 0.001)
sigma <- 1/prec_beta
sigma_u <- 1/prec_u
}
Here is a list of my dataset
list(Z=structure(.Data=c(-0.219467055585463,-1.0526183396725,-1.00343579060721,-0.174499545747411,1.03238478919476,-0.317602628158966,1.27229074223524,-0.613521644345033,1.50988338215066,1.6857077893915,1.11942859309268,1.36148346873975,0.774180027404055,-0.902517546173478,2.6501359790771,-0.413310408208541,-0.197996962987277,-0.406140336287673,-2.60751407341114,0.111232935618945,1.27711543380404,-1.05425209314644,-0.455498560429771,-0.655398663214552,-0.0968459896381278,0.464388154209697,-1.47473362034434,0.0508928485487814,1.10880874669099,-0.491056320875461,0.145845454540713,-0.947169053043664,-0.441531572685426,1.80195644424534,1.13985779402976,-0.958923786143078,0.403358443357914,-0.0118115648529643,0.521421100311106,1.21220918947123,1.79165179924407,0.562699270557773,0.357652505902132,0.209203277550589,0.280150666953245,1.40683370027182,-0.395336177568138,-0.195348849309409,-1.10781597014845,0.861107084145554,-0.435986944567536,-1.36668438445771,-1.62017126283765,-0.290748864268735,-0.944660887634567,-0.34393099580937,-0.607893508306956,-1.79896605260523,-0.200970649878093,0.393000319833283, -0.591793596938563,-0.846007737627853,-0.993448956287201,1.23229854248627,-1.53391039604131,0.506419982888481,0.152347058330876,-0.0510066471854711,-0.162401128472002,-1.37392604589767,0.188292787815362,0.125790039449526,1.09174325741996,-0.341773405642498,0.816433100935835,-0.0697578734624808,-0.864337994285645,1.54270698794713,-0.477247160804892,0.185441121515476,-0.523296064000129,-1.61839454894388,-2.01045640676985,-1.87830634454001,-1.12065224036309,-2.25610922405954,0.951714878925673,1.20762158454228,0.608859403038759,0.44631782325222,1.11173217852023,0.778598997428461,-0.324229340789447,-1.09773437344059,1.15761904351762,0.219992622032561,0.135532469361952,0.488047616795398,0.313385884103597,0.114690980957161,0.277097738481087,0.100267682021851,0.15165136169135,-0.440867474583709,-0.701730080467924,0.49522107407147,-0.422873249779141,-0.732013438869057,0.219815481500611,-1.43836884322567,1.20610808000347,0.469282759101958,1.05540476355154,0.736484638597606,0.339998787859088,0.242412843604043,0.956376968776209,0.256786625998753,-1.81714425308578,1.19852546446316,-0.713917180149863,-0.328772420547237,-2.09819461315789,0.781397800915941,0.831084646356333,0.208496382703667,0.552304599560233,-1.09787961582376,-0.1605804637371,-1.74143673575154,-0.488643356947795,0.211854842707662,-1.0530126620423,-0.47957789625537,-0.616581428342338,-0.598141452386519,0.745822697507985,1.59988436527336,0.326809234424135,-1.84391837835755,-1.08911356941711,1.51432778362298,1.21586688981497,-0.230735375776541,0.673600577665451,-0.428209595350681,-2.16383559524475,1.04595901248164,0.291126078976927,0.577057163238565,0.284125259799296,-0.131664022273801,-0.670148105444531,1.53705025131545,-1.04833638553576,-0.830380332320897,0.209169593792799,0.0848808288533462,1.43798493668837,0.528236836128168,0.0505627309323285,-0.54594202744332,0.321973964366215,-1.48006262012726,-0.553712871185891,0.537770965717893,-1.45012613899683,-0.529491348252536,-0.634932841248986,-0.255765837172777,0.689986607336208,1.6121917053331,-0.165708804911209,-0.0764355867440887,0.0467170438717642,-0.302540761356548,2.3830651891729,1.40913783140314,-1.46912432184705,-0.482090185876995),.Dim=c(20,9)), y=c(0,0,0,1,1,1,1,0,1,1,0,1,0,1,1,1,0,0,0,0), X=structure(.Data=c(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,-0.0308182667941742,0.364928063835271,-0.617029165748728,-0.251026982181124,1.5491650335909,0.37196636672969,1.70758321528354,1.53974958358942,-0.340675569386209,-1.92490680413483,-0.370140804120536,-0.0695360534435821,0.384075312591085,-1.7165286725541,-1.0931423228091,-0.580110331456067,0.408394048358603,0.0988594452165989,-0.126807101466656,-1.3385622765585,0.939738405942946,-1.38804833250765,-1.22799997033548,-0.418221665100478,-0.19428249261063,1.0648079602079,-0.999376971838634,0.0589315516640776,1.06654880184221,0.751504915104114,0.856638049990856,-0.905166273490286,-1.35403825891205,1.07356069583341,0.537672296412986,-0.728516617279024,-1.43023108628979,-1.24570096220685,0.234622352704664,-0.404110603253563), .Dim=c(20,3)), id=c(1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5), N=20, n=5, p=3, q=3, T=3)
Initial values
list(tau = rbeta(1, 0.5, 0.5),
prec_beta = 2, prec_u=2,
gamma=rep(0,p), beta= rnorm(p*7, 0,1),
U = rnorm(n, 0,1), xbeta=rep(0, q+1))
My dataset is huge but I just included the first N=20 rows for n=5 patients, with each group exposure Z having T=3 variables each, and I have p=3 exposure. I also have q=3 covariates which I don't do the variable selection on.
I've checked my data and variables, and they seem to be correctly specified. Can anyone help me figure out what's causing this error and how to resolve it?
Thank you in advance for your help!