class: center, middle, inverse, title-slide #
Mixed Models
##
Issues
###
Michael Clark
###
m-clark.github.io
@statsdatasci
CSCAR, UM
###
2020-10-21
--- class: inverse middle center
### *Overview of Random Effects* ### *More Random Effects* ### *Common Extensions* ### **Issues** --- class: inverse middle center animated fadeIn fadeOut # https://animate.style/ # More things to consider --- class: inverse # Variance Accounted For `\(R^2\)` has limited utility beyond OLS In the mixed case... ... do you include the random effect or not? ```r performance::r2(gpa_mixed) ``` ``` # R2 for Mixed Models Conditional R2: 0.625 Marginal R2: 0.213 ``` The difference can be quite dramatic! --- class: inverse # Alternative Model Approaches Fixed effects models - Econometrics Using cluster-robust standard errors Generalized estimating equations (GEE) - GLS, cluster-robust standard errors are a special case Latent Growth Curve Models - Identical to GLMM if set up appropriately --- class: inverse # Sample Sizes Small number of clusters - variance estimates may not be good Small number of observations within clusters - Mixed models are fine with pre-post data! Balanced/Missing values - Balance not required - Assumption is *missing at random* --- class: inverse # Sample Sizes *Big data* - lme4 can be very fast - even with single random effect and millions of observations - glmmTMB is slower - but often won't have convergence issues - mgcv faster with millions if fewer clusters --- class: img-slide # Sample Sizes Randome effects from 1000, 100 levels <img src="img/lme-timings-1.svg" style="display:block; margin: 0 auto;"> --- class: inverse # Model Comparison ANOVA/Likelihood Ratio Compare models with different fixed effects: - change the default estimation from REML to ML - models must have the same random effects structure Compare models with different random effects: - keep default REML - models must have the same fixed effects --- class: inverse # Model Comparison AIC is probably okay, but can use AICc or CAIC ```r AIC(standard_lme4_model) AICcmodavg::AICc(standard_lme4_model) cAIC4::cAIC(standard_lme4_model) ``` --- class: inverse # Convergence Data is as data does. You will eventually have issues: - such as lack of convergence - estimates of zero variance - other warnings These are not easy models to estimate, so don't be surprised if all doesn't go smoothly. --- class: inverse # Convergence Common sources of problems: - Unscaled variables - Other data problems (e.g. severe imbalance) - Few clusters to estimate variances Common solutions: - Standardize, center, log numeric - Consider simpler model - Use different optimizer, more iterations --- class: inverse # Summary Mixed models will take more effort... -- ...because they're interesting! That shouldn't keep you from exploring! --- class: inverse middle center # Moving on... # [Part 1](https://m-clark.github.io/mixed-models-with-R-workshop/part-1.html) <span class="" style = "width: 50px; display: inline-block"></span>[Part 2](https://m-clark.github.io/mixed-models-with-R-workshop/part-2.html) <span class="" style = "width: 50px; display: inline-block"></span>[Part 3](https://m-clark.github.io/mixed-models-with-R-workshop/part-3.html) <span class="" style = "width: 50px; display: inline-block"></span>[Part 5](https://m-clark.github.io/mixed-models-with-R-workshop/part-5.html)