R2MLwiN does not currently provide an implementation of the
VarCorr() function, however it does return these values within the output of
coef(). The following shows the same model being fitted with
glmer,
brms,
MLwiN(IGLS) and
MLwiN(MCMC):
Code: Select all
data(mmmec, package = "R2MLwiN")
library(lme4)
glmermod <- glmer(obs ~ 1 + offset(log(exp)) + (1 | nation) + (1 | region), data = mmmec, family = poisson(link = "log"))
library(brms)
brmmod <- brm(obs ~ 1 + offset(log(exp)) + (1 | nation) + (1 | region), data = mmmec, family = poisson)
library(R2MLwiN)
iglsmod <- runMLwiN(log(obs) ~ 1 + offset(log(exp)) + (1 | nation) + (1 | region), D = "Poisson", data = mmmec)
mcmcmod <- runMLwiN(log(obs) ~ 1 + offset(log(exp)) + (1 | nation) + (1 | region), D = "Poisson", estoptions = list(EstM = 1), data = mmmec)
In
glmer and
brms you could then extract the random part parameter estimates using the
VarCorr() function, i.e.
Code: Select all
> VarCorr(glmermod)
Groups Name Std.Dev.
region (Intercept) 0.23970
nation (Intercept) 0.40623
> VarCorr(brmmod)
$nation
$nation$sd
Estimate Est.Error Q2.5 Q97.5
Intercept 0.5200079 0.1700911 0.2905706 0.9578975
$region
$region$sd
Estimate Est.Error Q2.5 Q97.5
Intercept 0.2454637 0.02715162 0.1987185 0.3031363
However to get the same results from a R2MLwiN model you have to take a subset of the results from the
coef function:
Code: Select all
> sqrt(coef(iglsmod)[c("RP3_var_Intercept", "RP2_var_Intercept")])
RP3_var_Intercept RP2_var_Intercept
0.4350172 0.2129688
> sqrt(coef(mcmcmod)[c("RP3_var_Intercept", "RP2_var_Intercept")])
RP3_var_Intercept RP2_var_Intercept
0.4829251 0.2452319
Or from the MCMC version calculate this from the chains directly:
Code: Select all
> colMeans(sqrt(mcmcmod@chains[, c("RP3_var_Intercept", "RP2_var_Intercept")]))
RP3_var_Intercept RP2_var_Intercept
0.4618277 0.2436698
Which would also allow you to easily calculate the credible intervals too.
Note that MLwiN returns the variances directly, so for your purposes you can remove the square root to cancel out the later squaring in your calculation.