Install if you don’t already have it:
sudo su -
spack install r-rjags
spack find
This will take some time to install.
You can test if the R package “rjags” is installed and working in your system by running a simple script in the R environment. Here’s how:
module load r r-rjags r-coda r-lattice
library(rjags)
. If the package is installed and loaded correctly, you should not see any error messages.library(rjags)
model_string = "
model {
for (i in 1:100) {
x[i] ~ dnorm(0, 1)
}
mu <- mean(x)
sigma <- sd(x)
}
"
jags_model = jags.model(textConnection(model_string), data = list(), n.chains = 2)
update(jags_model, n.iter = 1000)
samples = coda.samples(jags_model, c("mu", "sigma"), n.iter = 1000)
summary(samples)
If the script runs successfully and provides output, it means that both R and JAGS are installed and working correctly.