gelman-rubin

Welcome to the forum for R2MLwiN users. Feel free to post your question about R2MLwiN here. The Centre for Multilevel Modelling take no responsibility for the accuracy of these posts, we are unable to monitor them closely. Do go ahead and post your question and thank you in advance if you find the time to post any answers!

Go to R2MLwiN: Running MLwiN from within R >> http://www.bris.ac.uk/cmm/software/r2mlwin/
Post Reply
d23yuipp0
Posts: 5
Joined: Wed Dec 15, 2021 6:48 pm

gelman-rubin

Post 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!
ChrisCharlton
Posts: 1354
Joined: Mon Oct 19, 2009 10:34 am

Re: gelman-rubin

Post 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)
Norudomo
Posts: 1
Joined: Mon Dec 06, 2021 3:00 pm

Re: gelman-rubin

Post 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!
d23yuipp0
Posts: 5
Joined: Wed Dec 15, 2021 6:48 pm

Re: gelman-rubin

Post by d23yuipp0 »

Thanks, Chris. This was super helpful.
kayleyseah
Posts: 1
Joined: Wed May 17, 2023 4:12 am

Re: gelman-rubin

Post 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.
Manisoa12
Posts: 5
Joined: Tue Jul 11, 2023 3:00 am

Re: gelman-rubin

Post 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
Post Reply