Page 1 of 1

gelman-rubin

Posted: Thu Dec 16, 2021 4:34 pm
by d23yuipp0
I want to obtain gelman-rubin statistics after running models with multiple chains. I believe this can be done with the gelman.diag() function in R.

The syntax is:

Code: Select all

gelman.diag(x, confidence = 0.95, transform=FALSE, autoburnin=TRUE, multivariate=TRUE)
where x is a mcmc.list object with more than one chain.

However, for the life of me, I cannot figure out how chains are stored and how to get them to be mcmc.list objects in order to analyze with gelman.diag().

Any insight would be greatly appreciated!

Re: gelman-rubin

Posted: Mon Dec 20, 2021 8:09 pm
by ChrisCharlton
You can find the MCMC chains in the chains slot of the mlwinfitMCMC object returned from the runMLwiN function. An example of this would be as follows:

Code: Select all

# for runMLwiN function
library(R2MLwiN)

# for gelman.diag function
library(coda)

# load the data
data(tutorial, package = "R2MLwiN")

# run the model
(mymodel <- runMLwiN(normexam ~ 1 + standlrt + (1 | school) + (1 | student), estoptions = list(EstM = 1, mcmcMeth = list(nchains = 3)), data = tutorial))

# calculate gelman-rubin diagnostics
gelman.diag(mymodel@chains)

Re: gelman-rubin

Posted: Tue Dec 28, 2021 2:39 pm
by Norudomo
Thank you for reminding about runMLwiN function, I had a similar issue and was thinking how to fix it yesterday at my Munich home. I will try to do as you wrote today and hope it's going to work, thank you!

Re: gelman-rubin

Posted: Wed Jan 05, 2022 3:23 pm
by d23yuipp0
Thanks, Chris. This was super helpful.

Re: gelman-rubin

Posted: Wed May 17, 2023 4:24 am
by kayleyseah
Himapquest directions
To obtain Gelman-Rubin statistics using the 'gelman.diag()' function in R, you need to have your chains stored as an 'mcmc.list' object.

Re: gelman-rubin

Posted: Thu Feb 15, 2024 8:17 am
by Manisoa12
I was considering a solution to a comparable problem. I will follow your instructions today and cross my fingers that it works.
run 3