library(jagsUI)library(rstan)
data(longley)head(longley)gnp <- longley$GNPemployed <- longley$Employedn <- length(employed)
data <- list(gnp=gnp,employed=employed,n=n)modfile <- tempfile()
#Write model to filewriteLines("model{
#Likelihood for (i in 1:n){
employed[i] ~ dnorm(mu[i], tau) mu[i] <- alpha + beta*gnp[i]
}
#Priors alpha ~ dnorm(0, 0.00001) beta ~ dnorm(0, 0.00001) sigma ~ dunif(0,1000) tau <- pow(sigma,-2)
}", con=modfile)
params <- c('alpha','beta','sigma')
out <- jags(data = data, inits = NULL, parameters.to.save = params, model.file = modfile, n.chains = 3, n.adapt = 100, n.iter = 1000, n.burnin = 500, n.thin = 2)
#Convert rjags mcmc.list to array format (iterations x parameters x chains)arr <- as.array(out$samples)
#convert array to iterations x chains x parametersarr <- aperm(arr, c(1,3,2))
#Calculate split-chain Rhat and other parameters#no warmup/burn-in iterations saved by jagsUI, so set warmup to 0mon <- rstan::monitor(arr, warmup=0)--
*** Three hierarchical modeling email lists ***
(1) unmarked: for questions specific to the R package unmarked
(2) SCR: for design and Bayesian or non-bayesian analysis of spatial capture-recapture
(3) HMecology (this list): for everything else, especially material covered in the books by Royle & Dorazio (2008), Kéry & Schaub (2012), Kéry & Royle (2016, 2020)
---
You received this message because you are subscribed to the Google Groups "hmecology: Hierarchical Modeling in Ecology" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hmecology+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/hmecology/d998f09e-d862-4434-b827-2ae4ab3794f3o%40googlegroups.com.
Hello all!
thanks Marc for the example! And what about psrf (potential scale
reduction factor), as reported by gelman.diag() function from the R
package coda? I am using this instead of Rhat. Do you (or anyone else)
know if this statistics can suffer of similar problem or is it more
reliable?
Tomas
On Mon, 26 Oct 2020 at 18:26, Kery Marc <marc...@vogelwarte.ch> wrote:
>
> Dear all,
>
> introducing a new "Cautionary Picture" feature: here is a particularly striking example of how Rhat can sometimes tell you an MCMC algorithm has converged ..... but it hasn't ! OK, this may be a pathological example, but nevertheless it's *really* good practice to always give a quick visual check to the chains for at least some key parameters in a model fit with MCMC.
>
> Best regards --- Marc
>
> --
> *** Three hierarchical modeling email lists ***
> (1) unmarked: for questions specific to the R package unmarked
> (2) SCR: for design and Bayesian or non-bayesian analysis of spatial capture-recapture
> (3) HMecology (this list): for everything else, especially material covered in the books by Royle & Dorazio (2008), Kéry & Schaub (2012), Kéry & Royle (2016, 2020)
> ---
> You received this message because you are subscribed to the Google Groups "hmecology: Hierarchical Modeling in Ecology" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to hmec...@googlegroups.com.