goodnessFitMatrixMLM.Rd
Table of goodness of fit measures for multilevel logit models.
goodnessFitMatrixMLM(x, null.model, decim = 4, decim_per = 2)
An object of subclass glmerMod - result of glmer().
Specifies the model to compare with when computing proportion change in variance (PCV) and R^2GLMM. If missing, PCV is not computed. An object of subclass glmerMod - result of glmer().
Specifies the number of decimals to display. The default is 4.
Specifies the number of decimals to display in case of percent results. The default is 2.
An n x 1 matrix with the random intercept, ICC, AIC, BIC, logLik, deviance. If argument null.model is supplied, it also returns PCV (based on Nakagawa and Schielzeth, 2012) and marginal and conditional R^2GLMM using the r.squaredGLMM from package MuMIn (based on Nakagawa et al.,2017) The rownames are the variable names.
Barton, K. (2023). MuMIn: Multi-Model Inference (version 1.47.5). https://CRAN.R-project.org/package=MuMIn Sommet, N., and Morselli, D. (2017). Keep Calm and Learn Multilevel Logistic Modeling: A Simplified Three-Step Procedure Using Stata, R, Mplus, and SPSS. International Review of Social Psychology, Vol.30 No.1, pp.203-218. Nakagawa, S., and Schielzeth, H. (2013). A general and simple method for obtaining R2 from generalized linear mixed-effects models, Methods in Ecology and Evolution, Vol.4 No.2, 133-142. Nakagawa, S., Johnson, P. C., and Schielzeth, H. (2017). The coefficient of determination R2 and intra-class correlation coefficient from generalized linear mixed-effects models revisited and expanded, Journal of the Royal Society Interface, Vol.14 No.134.
library(lme4)
#> Loading required package: Matrix
library(boot)
set.seed(404)
beta_0=-1.4
beta_1=0.1
beta=0.5
age=sample(18:40, 100, replace=T)
gender=sample(0:1, 100, replace=T)
eduCat=sample(1:3, 100, replace=T)
groupId=sample(1:10, 100, replace=T)
prob=exp(beta_0 + beta_1 * age + beta * groupId) / (1 + exp(beta_0 + beta_1 * age + beta * groupId))
WLB=rbinom(n=100, size=1, prob=prob)
dataTest=as.data.frame(cbind(WLB, age, gender, eduCat, groupId))
first.WLB=glmer(formula=WLB ~ age + factor(gender) + I(eduCat==1) + I(eduCat==3) + (1 | groupId), data = dataTest, family = binomial, control=glmerControl(optimizer="bobyqa"), nAGQ = 0)
goodnessFitMatrixMLM(first.WLB)
#> Loading required package: MuMIn
#> V1
#> Random intercept variance 0.5074
#> Interclass correlation (ICC) 0.1336
#> AIC 50.5492
#> BIC 66.1802
#> logLik -19.2746
#> deviance 38.5492
#> df.resid 94
#> No. observations 100
#> No. countries 10
#> 10
#> 11
goodnessFitMatrixMLM(first.WLB, decim=2, decim_per=0)
#> V1
#> Random intercept variance 0.51
#> Interclass correlation (ICC) 0.13
#> AIC 50.55
#> BIC 66.18
#> logLik -19.27
#> deviance 38.55
#> df.resid 94
#> No. observations 100
#> No. countries 10
#> 10
#> 11
null.WLB=glmer(WLB ~ 1 + (1 | groupId), data = dataTest, family = binomial, control=glmerControl(optimizer="bobyqa"), nAGQ = 0)
goodnessFitMatrixMLM(first.WLB, null.WLB) #returns PCV, R^2GLMM in relation to null.WLB
#> Warning: 'r.squaredGLMM' now calculates a revised statistic. See the help page.
#> V1
#> Random intercept variance 0.5074
#> Interclass correlation (ICC) 0.1336
#> AIC 50.5492
#> BIC 66.1802
#> logLik -19.2746
#> deviance 38.5492
#> df.resid 94
#> Proportion change in variance (PCV) 19.54%
#> Marginal R-squared (R^2_GLMM(m))- Theoretical 5.7%
#> Conditional R-squared (R^2_GLMM(c)) - Theoretical 18.3%
#> Marginal R-squared (R^2_GLMM(m))- Delta 1.33%
#> Conditional R-squared (R^2_GLMM(c)) - Delta 4.28%
#> No. observations 100
#> No. countries 10
goodnessFitMatrixMLM(first.WLB, null.WLB, 2, 0)
#> V1
#> Random intercept variance 0.51
#> Interclass correlation (ICC) 0.13
#> AIC 50.55
#> BIC 66.18
#> logLik -19.27
#> deviance 38.55
#> df.resid 94
#> Proportion change in variance (PCV) 20%
#> Marginal R-squared (R^2_GLMM(m))- Theoretical 6%
#> Conditional R-squared (R^2_GLMM(c)) - Theoretical 18%
#> Marginal R-squared (R^2_GLMM(m))- Delta 1%
#> Conditional R-squared (R^2_GLMM(c)) - Delta 4%
#> No. observations 100
#> No. countries 10