SPIDA 2010: Mixed Models with R

From MathWiki

This page and the files it links to are under construction

Please go to http://scs.math.yorku.ca/index.php/SPIDA for a discussion page on this material.

Table of contents

Installing the spida and p3d packages

The 'spida' and 'p3d' packages are in development and not available from CRAN but from R-Forge. You can install them on your laptop or in the TEL lab by following these instructions:

On your laptop

  • Install R from CRAN (see R: Getting started for help)
  • Install the 'car' and 'rgl' packages from CRAN
  • Install the 'spida' and 'p3d' packages from R-Forge with the following command in R:
 install.packages(c('spida','p3d'), repos = "http://r-forge.r-project.org")

In the TEL Lab

The version of R installed in the TEL lab is no longer supported by R-Forge. Use the following R commands to install appropriate versions of 'spida' and 'p3d' (you can cut and past these commands into you R console):

download.file("http://www.math.yorku.ca/people/georges/Files/SPIDA2010/spida.zip", "spida.zip")
install.packages("spida.zip", repos = NULL)
download.file("http://www.math.yorku.ca/people/georges/Files/SPIDA2010/p3d.zip", "p3d.zip")
install.packages("p3d.zip", repos = NULL)

Lecture Slides

Preliminary material -- not handed out

2010 version
  • Causality and Longitudinal Data Analysis: some very informal notes (http://www.math.yorku.ca/people/georges/Files/SPIDA2010/Intro-post-lecture-hq3.pdf)
2009 version

Main topics -- printed handouts

Asymptotic Functions of Time Part II (http://www.math.yorku.ca/people/georges/Files/SPIDA2010/Non_Linear_II_SLIDES.pdf) (under construction)

Additional Notes

Additional links from each day


Contents of Labs

Lab 1: SPIDA 2010: Mixed Models with R: Lab Session 1: Linear Mixed Models

    • First example: Between Sector gap in Math Achievement
      • Randomly selecting a subsample of clusters (schools)
      • Having a first look at multilevel data
      • Creating new Level 2 variables from Level 1 data
      • Seeing data in 3d
      • A second look at multilevel data: targeted to a model
      • Seeing fitted lines in beta space
      • Between and within cluster effects
      • Fitting a mixed model
      • Handling NAs (simplest considerations)
      • Non-convergence
      • First diagnostics: Hausman test
      • Contextual variables to the rescue
      • Interpretation of models with contextual effects
      • Estimating the compositional (= between) effect
      • Alternative equivalent parametrizations for the FE (fixed effects) model.
      • Alternative non-equivalent parametrizations for the RE (random effects) model
      • Diagnostics based on Level 1 residuals
      • Diagnostics based on Level 2 residuals (REs)
      • Influence diagnostics
      • Plotting the fitted model: hand-made effect plots
      • Linking the picture and the numbers
      • Formulating and testing linear hypotheses
      • Graphs to show confidence bounds for hypotheses
    • Second example: Minority status and Math Achievement
      • Preliminary diagnostics using Level 1 OLS model
      • OLS influence diagnostics
      • Scaling Level 1 variables
      • Fitting a mixed model
      • Dealing with non-convergence
      • Building the RE model with a forward stepwise approach
      • Simulation to adjust p-values
      • Test for contextual effects II
      • Simplifying the model
      • Using regular expression for easy tests of complex hypotheses
      • Some Level 2 diagnostics
      • Near-singularity: a pancake in 3D
      • Visualizing the model: hand-made effect plots II
      • The minority-majority gap
      • Comparing different RE models
      • More diagnostics
      • Marginal and conditional models
      • Refining the FE model
      • Multilevel R Squared
      • Visualizing the model to construct hypotheses

Lab 2: SPIDA 2010: Mixed Models with R: Lab Session 2: Longitudinal Models

      • LME model
      • Hausman test:
      • . Adjusting for time
      • Diagnostics: Level 1
        • a) Diagnostics for heteroskedasticity
        • b) Diagnostics for autocorrelation
      • Diagnostics: Level 2
      • Dropping observations
      • Modeling autocorrelation
      • Modeling heteroskedasticity
      • Interpreting different kinds of residual plots
      • Visualizing the impact of model selection
      • Displaying data and fitted values together

Lab 3: SPIDA 2010: Mixed Models with R: Lab Session 3: Generalized Linear Mixed Models and Related Topics

      • Accelerated Longitudinal Designs and age-period-cohort linear confounding
      • Modeling seasonal and periodic effects with Fourier Analysis
      • Using general splines to model effect of age or time
      • Linear, quadratic, cubic and natural cubic splines
      • General spline generator: splines with arbitrary degrees and smoothness
      • Defining hypothesis matrices and using Wald tests to explore splines
      • Plotting splines and spline features with confidence bounds
      • Plotting log-odds or probabilities
      • Interpreting hypothesis tests using confidence bounds
      • Bonferroni and Scheffe confidence bound adjustment factors
      • Testing non-linear cohort effects
      • Alternatives to glmmPQL: lmer, glmmML,GLMMGibbs,


Special links from each day

  • Day 1:
    • Short R script illustrating plotting predicted curves and wald tests: Lab Day 1.R

Introductory documents on the web

Books on Mixed Models, Introductory and less introductory

  • Paul D. Allison (2005) Fixed Effects Regression Methods for Longitudinal Data Using SAS, SAS Institute.
Contains a good discussion of the comparison between mixed models and fixed effects models.
  • Judith D. Singer and John B. Willett (2003) Applied Longitudinal Data Analysis: Modeling Change and Event Occurrence, Oxford.
A solid accessible book. The second half deals with the related topic of event history analysis.
  • Doug Bates and Jose Pinheiro (2000) Mixed-Effects Models in S and S-PLUS, Springer.
  • Alain F. Zuur, Elena N. Ieno, Neil J. Walker, Anatoly A. Saveliev, Graham M. Smith (2009) Mixed Effects Models and Extensions in Ecology with R Springer.
  • Geert Verbeke and Geert Molenberghs (2000) Linear Mixed Models for Longitudinal Data. Springer.


Research and more advanced methodology

Sources of multilevel and longitudinal data

Web links