
Learn to fit, estimate, interpret, and evaluate linear mixed effects models using R. Explore multiple variance sources and correlation structures to understand model fit.
RStudio Integrated Development Environment (IDE) is a powerful and productive user interface for R. It’s free and open source, and works great on Windows, Mac, and Linux.
Create a temperature vector tamps in R and use vectorized operations, such as subtracting 32 to convert Fahrenheit to Celsius, and compare with Connecticut temps.
Explore creating and manipulating numeric vectors in R, generate year sequences with seq, index and assign elements, and work with multi-dimensional structures like matrices and data frames.
Compute sample mean and variance from death counts. Fit a Poisson model with lambda approximately 0.61, then compare observed and expected counts using manual and built-in Poisson probabilities.
One of the great strengths of R is the user's ability to add functions. In fact, many of the functions in Rare actually functions of functions. The structure of a function is given below.
myfunction <- function(arg1, arg2, ... ){statement}
Create and evaluate user defined functions in R, with default arguments and nested function calls. Compare custom integration with the built in beta and integrate functions and plot the results.
R has a wide variety of data types including scalars, vectors (numerical, character, logical).
All columns in a matrix must have the same mode(numeric, character, etc.) and the same length.
A data frame is more general than a matrix, in that different columns can have different modes (numeric, character, factor, etc.). This is similar to SAS and SPSS datasets.
Practice essential R functions for probability and plotting, including qnorm for percentiles, chi-squared and gamma densities, binomial probabilities via choose and d, and curve plotting with add=TRUE, plus saving plots.
Install and load the MBA multi-variate analysis package in R, explore datasets timber and plasma, and compare wide versus long forms through a clinical trial example with repeated measures.
Explore transforming data from wide to long for linear models, using the reshape function, and examine timber and plasma datasets with repeated measures to illustrate longitudinal and pseudo replication concepts.
Explore linear mixed-effects modeling in R by specifying fixed and random effects, and compare random intercept and random intercept with slope models under the local independence assumption.
Explore a random intercept LME with fixed effects and variance components, conditioning on specimen, compare to linear model with likelihood ratio test, and plan to test random intercept with slope.
Set the working directory, verify file existence, and read the fertilizer dataset into results to examine a replicated, repeated-measures root length study with two fertilizer treatments.
A mixed model is a statistical model containing both fixed effects and random effects. These models are useful in a wide variety of disciplines in the physical, biological and social sciences. They are particularly useful in settings where repeated measurements are made on the same statistical units (longitudinal study), or where measurements are made on clusters of related statistical units. Because of their advantage in dealing with missing values, mixed effects models are often preferred over more traditional approaches such as repeated measures ANOVA.
Identify fixed and random effects, estimate variance components from nested levels, and account for multiple error sources in longitudinal mixed-effects models using nlme and lme4.
Explore how random effects differ from fixed effects and compare the random intercept model with the random intercept and slope model to see how intercepts and slopes vary across groups.
Examine fertilizer's effect on root growth using an nlme mixed-effects model with random intercept and slope, and visualize group data with lattice panels to compare with a linear model.
Compare linear models with linear mixed-effects models, highlighting random intercepts, slopes, and random effects in a nested data set across nine beaches of species richness.
Explore linear mixed-effects modeling with a two-stage regression: estimate height effects on species richness within each beach, then relate those per-beach coefficients to exposure levels to interpret overall patterns.
Explore estimating a second stage linear mixed effects model with random intercepts for nine beaches, converting exposure to a factor, and interpreting fixed betas and random effects.
Compare AIC, BIC, and log-likelihood to assess random intercepts linear mixed-effects models in R. Examine population and beach-specific intercepts, fixed effects, and plot fitted lines from the LME object.
Explore random intercept and slope models in linear mixed-effects, modeling richness as a function of station height with beach-specific intercepts and slopes.
Split-plot designs result when a particular type of restricted randomization has occurred during the experiment. A simple factorial experiment can result in a split-plot type of design because of the way the experiment was actually executed.
Explore how to interpret linear mixed-effects models in R for a split-plot design, focusing on fixed effects, two-way and three-way interactions, and model simplification via summary and log-likelihood ratio tests.
Compare linear mixed-effects models in R by updating a fitted model to exclude the three-way interaction, use LRT and anova to favor the simpler model, and assess residuals for assumptions.
A random intercepts model is a model in which intercepts are allowed to vary, and therefore, the scores on the dependent variable for each individual observation are predicted by the intercept that varies across groups. This model assumes that slopes are fixed (the same across different contexts). In addition, this model provides information about intraclass correlations, which are helpful in determining whether multilevel models are required in the first place.
A random slopes model is a model in which slopes are allowed to vary, and therefore, the slopes are different across groups. This model assumes that intercepts are fixed (the same across different contexts).
A model that includes both random intercepts and random slopes is likely the most realistic type of model, although it is also the most complex. In this model, both intercepts and slopes are allowed to vary across groups, meaning that they are different in different contexts.
Explore plasma glucose data from obese and control groups in a repeated-measures design, reshaping long form to wide, and assess potential quadratic time effects and group-by-time interactions for mixed-effects models.
Fit a linear mixed-effects model with random intercept and slope, including time and time squared, and compare to a linear fit to reveal significant effects and a time-by-group interaction.
Explore variance components in a nested linear mixed-effects model with random intercepts using R, comparing models to quantify how random factors explain disease count variation.
In statistics, a random effect(s) model, also called a variance components model, is a kind of hierarchical linear model. It assumes that the dataset being analysed consists of a hierarchy of different populations whose differences relate to that hierarchy. In econometrics, random effects models are used in the analysis of hierarchical or panel data when one assumes no fixed effects (it allows for individual effects). The random effects model is a special case of the fixed effects model.
Analyze variance components in a linear mixed effects model, compute relative contributions of random effects (including gender), and compare nested models using log-likelihood ratio, AIC, and REML versus ML.
compare fixed and random models in mixed-effects analysis, showing gender as a fixed effect yields better fit on measures accounting for complexity, with residual and qq plots validating assumptions.
Explore how to specify and compare linear mixed-effects models, including random intercept, random intercept and slope, and marginal structures with induced covariance and compound symmetry.
Learn to structure linear mixed-effects models in R, with random intercepts and slopes and fixed effects. Compare ML and REML, and use AIC/BIC and LRT for fixed-vs-random selection.
Select the best random structure for linear mixed-effects models in R, comparing random intercept and random intercept with slope, using maximum likelihood and REML, and nested likelihood ratio tests.
Choose the random intercept and slope structure using AIC and log-likelihood ratio tests, then refine fixed effects with exposure and interaction terms, testing via ANOVA and ML, ensuring convergence.
Select the optimal lme structure by comparing fixed effects, including exposure and interaction, with random intercepts and slopes, using reml and log-likelihood tests to avoid overfitting.
In econometrics and statistics, a fixed effects model is a statistical model that represents the observed quantities in terms of explanatory variables that are treated as if the quantities were non-random. This is in contrast to random effects models and mixed models in which either all or some of the explanatory variables are treated as if they arise from random causes.
Apply linear mixed-effects modeling with R to account for farm-level variability by using a random intercept and slope, compare lme and the mixed-effects outputs, and interpret intercept-slope relationships in regression.
Compare full mixed-effects models with fixed effects and random effects, examining nitrogen and farm effects and their interaction, then progressively simplify from M2 to M5 using nested likelihood ratio tests.
Compare fixed and random effects in linear mixed-effects modeling with R, using log-likelihood ratio tests and anova to identify that the common-slope model M3 best fits nitrogen and farm data.
We analyze calls of nestling barn owls from 2007 to illustrate linear and mixed effects modeling, considering parent sex, arrival time, and food treatment with nest as a random effect.
Transform the response with log10 plus 1, refit, and assess residuals by nest to justify a random intercept model with fixed effects for sex, treatment, arrival time, and their interactions.
Fit linear mixed-effects models with R, compare random intercept and no-random-intercept structures using nest as a random effect, assess with log-likelihood ratio and anova; examine residuals and variable significance.
Apply likelihood ratio tests and anova-style comparisons in R to update linear mixed-effects models, assess interaction terms, and decide which covariates like food treatment and gender matter.
Explore the beat the blues longitudinal study, comparing old couch therapy to computer-based therapy for depression, using a basic mixed-effects model and model comparison to estimate treatment effects.
Analyze the beat the blues longitudinal study comparing CBT and computer-based therapy for depression, using linear mixed effects models (LME4) on 100 participants with dropout handling and two covariates.
Learn to convert wide to long data in R for linear mixed-effects analyses, compare beat the blues and treatment as usual across pre and post time points.
Fit linear mixed-effects models in R to beat the blues data, compare random intercept and slope, and select the simpler model; Preece score and time are significant, treatment is not.
Apply a 10-step protocol to build a mixed-effects model of nestling barn owl begging counts, with nest as random and gender, arrival time, and food treatment as fixed effects.
Learn to build and simplify a linear mixed-effects model in R by using log-likelihood ratio tests to retain food treatment and arrival time as fixed effects, with a random intercept.
Explore fitting a generalized additive mixed model using Wood's package, highlighting additive model components, smooth terms, and how to inspect a fitted object.
One application of multilevel modeling (MLM) is the analysis of repeated measures data. Multilevel modeling for repeated measures data is most often discussed in the context of modeling change over time (i.e. growth curve modeling for longitudinal designs); however, it may also be used for repeated measures data in which time is not a factor. The issue of subjects leaving the study ("dropouts") midway through the periodic intervals of data collection is a perennial problem with these types of studies.
Explore dropout patterns in longitudinal data using plots to compare dropouts and non-dropouts, assess normality of random effects and residuals in linear mixed-effects models.
Compare linear regression and the optimal mixed model on the beat the blues longitudinal data to assess parameter significance, beta changes, and potential treatment-by-time interaction.
Fit a linear regression vs a random intercept mixed-effects model to beat the blues data, showing inflated significance from ignoring correlation, and test for a treatment by time interaction.
Just as with ordinary least-squared linear regression, the observed distribution of error terms (residuals) is assumed to be normally distributed and characterized by statistical independence from other error terms in the practice of linear mixed-effects modeling.
Explore how linear regression is used with time-based residuals. Examine the assumption that residuals are normally distributed with zero mean and constant variance, and model the covariance across years.
Examine residual independence with year-to-year correlations via the auto correlation function and apply a GLS model with fixed compound symmetry to adjust standard errors.
In the statistical analysis of time series, autoregressive–moving-average (ARMA) models provide a parsimonious description of a (weakly) stationary stochastic process in terms of two polynomials, one for the auto-regression and the second for the moving average.
Examine AR-1 and ARMA residual dependence, detailing P and Q shaping correlation and covariance, convergence algorithms relying on starting values, and AIC and SC differences for non-nested models.
Explore spatial dependence in mixed models by detecting spatial correlation in residuals and adding appropriate correlation structures, using a boreal forest dataset with wetness, latitude, and longitude.
Load the boreal data, transform the response, fit a linear model with wetness, and use bubble plots and a variogram to assess residuals and spatial dependence.
Investigate spatial dependence in linear mixed-effects models by using variograms, nugget, and isotropy tests, then compare exponential, gaussian, linear, rational quadratic, and spherical correlation structures in R.
Learn to analyze acid sensitivity in 205 Irish rivers using the sodium dominance index and visualize forested versus non-forested sites with lattice plots.
Linear Mixed-Effects Models with R is a 7-session course that teaches the requisite knowledge and skills necessary to fit, interpret and evaluate the estimated parameters of linear mixed-effects models using R software. Alternatively referred to as nested, hierarchical, longitudinal, repeated measures, or temporal and spatial pseudo-replications, linear mixed-effects models are a form of least-squares model-fitting procedures. They are typically characterized by two (or more) sources of variance, and thus have multiple correlational structures among the predictor independent variables, which affect their estimated effects, or relationships, with the predicted dependent variables. These multiple sources of variance and correlational structures must be taken into account in estimating the "fit" and parameters for linear mixed-effects models.
The structure of mixed-effects models may be additive, or non-linear, or exponential or binomial, or assume various other ‘families’ of modeling relationships with the predicted variables. However, in this "hands-on" course, coverage is restricted to linear mixed-effects models, and especially, how to: (1) choose an appropriate linear model; (2) represent that model in R; (3) estimate the model; (4) compare (if needed), interpret and report the results; and (5) validate the model and the model assumptions. Additionally, the course explains the fitting of different correlational structures to both temporal, and spatial, pseudo-replicated models to appropriately adjust for the lack of independence among the error terms. The course does address the relevant statistical concepts, but mainly focuses on implementing mixed-effects models in R with ample R scripts, ‘real’ data sets, and live demonstrations. No prior experience with R is necessary to successfully complete the course as the first entire course section consists of a "hands-on" primer for executing statistical commands and scripts using R.