Page 1 of 1

multivariate ESS w/ multiESS

Posted: Wed Jan 05, 2022 5:17 pm
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.

Re: multivariate ESS w/ multiESS

Posted: Thu Jan 06, 2022 1:02 pm
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)