bayesian - rjags error Invalid vector argument to ilogit -


i'd compare betareg regression vs. same regression using rjags

library(betareg) d = data.frame(p= sample(c(.1,.2,.3,.4),100, replace= true),                id = seq(1,100,1))  # looking reproduce regression jags b=betareg(p ~ id, data= d,            link = c("logit"), link.phi = null, type = c("ml")) summary(b) 

below trying same regression rjags

#install.packages("rjags") library(rjags) jags_str = " model { #model  y ~ dbeta(alpha, beta) alpha <- mu * phi beta  <- (1-mu) * phi logit(mu) <- + b*id  #priors  ~ dnorm(0, .5) b  ~ dnorm(0, .5) t0 ~ dnorm(0, .5) phi <- exp(t0) }"  id = d$id y = d$p model <- jags.model(textconnection(jags_str),                      data = list(y=y,id=id) ) update(model, 10000, progress.bar="none"); # burnin 10000 samples samp <- coda.samples(model,                       variable.names=c("mu"),                       n.iter=20000, progress.bar="none")  summary(samp) plot(samp) 

i error on line

 model <- jags.model(textconnection(jags_str),                          data = list(y=y,id=id)     )  error in jags.model(textconnection(jags_str), data = list(y = y, id = id)) :    runtime error: invalid vector argument ilogit 

can advise

(1) how fix error

(2) how set priors beta regression

thank you.

this error occurs because have supplied id vector scalar function logit. in jags inverse link functions cannot vectorized. address this, need use for loop go through each element of id. add additional element data list denotes how long id is.

d = data.frame(p= sample(c(.1,.2,.3,.4),100, replace= true),            id = seq(1,100,1), len_id = length(seq(1,100,1))) 

from there need make small edit jags code.

for(i in 1:(len_id)){ y[i] ~ dbeta(alpha[i], beta[i]) alpha[i] <- mu[i] * phi beta[i]  <- (1-mu[i]) * phi logit(mu[i]) <- + b*id[i] } 

however, if track mu going matrix 20000 (# of iterations) 100 (length of id). more interested in actual parameters (a, b, , phi).


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -