I am trying to use rjags to conduct an ANOVA wih separate variances for each of the three groups. I am using the "PlantGrowth" data built into R.
Here is the model:
mod_string = " model {
for (i in 1:length(y)) {
y[i] ~ dnorm(mu[grp[i]], sig[grp[i]])
}
for (j in 1:3) {
mu[j] ~ dnorm(0.0, 1.0/1.0e6)
}
for (j in 1:3) {
sig[j] ~ dnorm(0.0, 1.0/1.0e6)
}
} "
set.seed(82)
str(PlantGrowth)
data_jags = list(y=PlantGrowth$weight,
grp=as.numeric(PlantGrowth$group))
params = c("mu", "sig")
inits = function() {
inits = list("mu"=rnorm(3,0.0,100.0), "sig"=rnorm(3,0.0,1.0))
}
The inits function in this model does not work. Can anyone help?
I would suggest next approach. First, bayesian model needs to be trained. So your steps are fine. Take into account that you are defining extremely low priors on you coefficients. So, when you set your initial values too high, issues related to convergence in the chains can appear. The model chain is fine. I only slightly improved the initial values function. Here the code. In order to complete ANOVA you have to work with all the results for the parameters of your interested. This means computing posterior credible intervals, etc. In that way, your main input will be the parameters from chains. Here the code for obtaining the parameters you want:
The outputs will be stored on
d1
. Here some rows:With that values you have to work on computing posterior means and posterior credible intervals in order to contrast with the ANOVA method.