multivariate ESS w/ multiESS

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

multivariate ESS w/ multiESS

Post by d23yuipp0 »

I estimated a cross-classified model with 4 chains. I want to get a fit statistic called the Multivariate Effective Sample Size using the multiESS command in R.

I tried the following code after running the model and got this error message:

Code: Select all

> multiESS(Model1@chains)
Error in multiESS(Model1@chains) : 'x' must be a matrix or data frame.
I'm pretty new to R, so I apologize. But I can't figure out what the x should be in this program. I thought calling "Model1@chains" would work or just "Model1", but I haven't had luck.

Any help would be greatly appreciated.
ChrisCharlton
Posts: 1348
Joined: Mon Oct 19, 2009 10:34 am

Re: multivariate ESS w/ multiESS

Post by ChrisCharlton »

I am not familiar with the multiESS function, however it appears to require a matrix or data.frame instead of the mcmc.list object return from R2MLwiN.

If you convert it as follows it should work:

Code: Select all

# for runMLwiN function
library(R2MLwiN)

# for multiESS function
library(mcmcse)

# 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 the effective sample size of the Markov chain
multiESS(as.matrix(mymodel@chains))
Note that you can also obtain an effective sample size for each parameter using the effectiveSize function provided by coda:

Code: Select all

# for effectiveSize function
library(coda)

# calculate an effective sample size for each model parameter
effectiveSize(mymodel@chains)
Post Reply