Just in case you need motivation

Caveats:

  • I'm using data from real, recent papers but
  • Material here doesn't attempt to replicate or criticize

LMM: "Simple" greenhouse, linear mixed model

Pattern and amount – cool question!

4 (!) treatments – full factorial blocked

xtabs(~ water_hetero + water_add + nutrient_hetero + nutrient_add + block , d)
## , , nutrient_hetero = heterogeneous, nutrient_add = 120 mg N, block = 1
## 
##              water_add
## water_hetero  125 mL 250 mL 375 mL
##   homogeneous      1      1      1
##   pulse            1      1      1
## 
## , , nutrient_hetero = homogeneous, nutrient_add = 120 mg N, block = 1
## 
##              water_add
## water_hetero  125 mL 250 mL 375 mL
##   homogeneous      1      1      1
##   pulse            1      1      1
## 
## , , nutrient_hetero = heterogeneous, nutrient_add = 40 mg N, block = 1
## 
##              water_add
## water_hetero  125 mL 250 mL 375 mL
##   homogeneous      1      1      1
##   pulse            1      1      1
## 
## , , nutrient_hetero = homogeneous, nutrient_add = 40 mg N, block = 1
## 
##              water_add
## water_hetero  125 mL 250 mL 375 mL
##   homogeneous      1      1      1
##   pulse            1      1      1
## 
## , , nutrient_hetero = heterogeneous, nutrient_add = 80 mg N, block = 1
## 
##              water_add
## water_hetero  125 mL 250 mL 375 mL
##   homogeneous      1      1      1
##   pulse            1      1      1
## 
## , , nutrient_hetero = homogeneous, nutrient_add = 80 mg N, block = 1
## 
##              water_add
## water_hetero  125 mL 250 mL 375 mL
##   homogeneous      1      1      1
##   pulse            1      1      1
## 
## , , nutrient_hetero = heterogeneous, nutrient_add = 120 mg N, block = 2
## 
##              water_add
## water_hetero  125 mL 250 mL 375 mL
##   homogeneous      1      1      1
##   pulse            1      1      1
## 
## , , nutrient_hetero = homogeneous, nutrient_add = 120 mg N, block = 2
## 
##              water_add
## water_hetero  125 mL 250 mL 375 mL
##   homogeneous      1      1      1
##   pulse            1      1      1
## 
## , , nutrient_hetero = heterogeneous, nutrient_add = 40 mg N, block = 2
## 
##              water_add
## water_hetero  125 mL 250 mL 375 mL
##   homogeneous      1      1      1
##   pulse            1      1      1
## 
## , , nutrient_hetero = homogeneous, nutrient_add = 40 mg N, block = 2
## 
##              water_add
## water_hetero  125 mL 250 mL 375 mL
##   homogeneous      1      1      1
##   pulse            1      1      1
## 
## , , nutrient_hetero = heterogeneous, nutrient_add = 80 mg N, block = 2
## 
##              water_add
## water_hetero  125 mL 250 mL 375 mL
##   homogeneous      1      1      1
##   pulse            1      1      1
## 
## , , nutrient_hetero = homogeneous, nutrient_add = 80 mg N, block = 2
## 
##              water_add
## water_hetero  125 mL 250 mL 375 mL
##   homogeneous      1      1      1
##   pulse            1      1      1
## 
## , , nutrient_hetero = heterogeneous, nutrient_add = 120 mg N, block = 3
## 
##              water_add
## water_hetero  125 mL 250 mL 375 mL
##   homogeneous      1      1      1
##   pulse            1      1      1
## 
## , , nutrient_hetero = homogeneous, nutrient_add = 120 mg N, block = 3
## 
##              water_add
## water_hetero  125 mL 250 mL 375 mL
##   homogeneous      1      1      1
##   pulse            1      1      1
## 
## , , nutrient_hetero = heterogeneous, nutrient_add = 40 mg N, block = 3
## 
##              water_add
## water_hetero  125 mL 250 mL 375 mL
##   homogeneous      1      1      1
##   pulse            1      1      1
## 
## , , nutrient_hetero = homogeneous, nutrient_add = 40 mg N, block = 3
## 
##              water_add
## water_hetero  125 mL 250 mL 375 mL
##   homogeneous      1      1      1
##   pulse            1      1      1
## 
## , , nutrient_hetero = heterogeneous, nutrient_add = 80 mg N, block = 3
## 
##              water_add
## water_hetero  125 mL 250 mL 375 mL
##   homogeneous      1      1      1
##   pulse            1      1      1
## 
## , , nutrient_hetero = homogeneous, nutrient_add = 80 mg N, block = 3
## 
##              water_add
## water_hetero  125 mL 250 mL 375 mL
##   homogeneous      1      1      1
##   pulse            1      1      1
## 
## , , nutrient_hetero = heterogeneous, nutrient_add = 120 mg N, block = 4
## 
##              water_add
## water_hetero  125 mL 250 mL 375 mL
##   homogeneous      1      1      1
##   pulse            1      1      1
## 
## , , nutrient_hetero = homogeneous, nutrient_add = 120 mg N, block = 4
## 
##              water_add
## water_hetero  125 mL 250 mL 375 mL
##   homogeneous      1      1      1
##   pulse            1      1      1
## 
## , , nutrient_hetero = heterogeneous, nutrient_add = 40 mg N, block = 4
## 
##              water_add
## water_hetero  125 mL 250 mL 375 mL
##   homogeneous      1      1      1
##   pulse            1      1      1
## 
## , , nutrient_hetero = homogeneous, nutrient_add = 40 mg N, block = 4
## 
##              water_add
## water_hetero  125 mL 250 mL 375 mL
##   homogeneous      1      1      1
##   pulse            1      1      1
## 
## , , nutrient_hetero = heterogeneous, nutrient_add = 80 mg N, block = 4
## 
##              water_add
## water_hetero  125 mL 250 mL 375 mL
##   homogeneous      1      1      1
##   pulse            1      1      1
## 
## , , nutrient_hetero = homogeneous, nutrient_add = 80 mg N, block = 4
## 
##              water_add
## water_hetero  125 mL 250 mL 375 mL
##   homogeneous      1      1      1
##   pulse            1      1      1

GLMM: Lizard mate choice

Mechanisms of speciation – cool question!

  • mate compatibility trails
  • western North American skinks (Plestiodon skiltonianus spp)
  • Richmond, J. Q., E. L. Jockusch, and A. M. Latimer 2010. Mechanical reproductive isolation facilitates parallel speciation in western North American scincid lizards. American Naturalist

Repeated measure ind, multiple trials, binary choice

xtabs(~ Series + Female , data=d2, sparse=TRUE)
## 15 x 75 sparse Matrix of class "dgCMatrix"
##    [[ suppressing 75 column names '1', '2', '3' ... ]]
##                                                                           
## 1  . 3 . . . . . . . . . . . . . . . . 3 . . . . . . . . . . . . . . 3 . .
## 2  2 . . . . . 2 . . . . . . . . . . . . . . . . . . . 2 2 . . . . . . . 2
## 3  . . . 1 . . . . . . . . . . 1 . . . . . 2 . . . . . . . . 1 . . . . . .
## 4  . . . . . . . . . . . . 3 . . 3 . . . 3 . . . . . 3 . . . . . . . . . .
## 5  . . . . . . . . . . 1 3 . 1 3 . . 3 . . . 2 . . 2 . . . . 3 . . . . . .
## 7  . . . . 3 . . . . . . . . 2 2 . 2 . . . 1 . . . . . . . . . . 1 . . . .
## 8  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
## 9  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 . . .
## 10 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 . . . . . . .
## 11 . . . . . . . . . . . . . . . . . . . 1 . . . . . . . . . . . . . . . .
## 12 . . 4 . . . . . . 4 . . . . . . . . 1 1 . . . . . . . . . . 2 . . . . .
## 13 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
## 14 . . . . . . . . 1 . . . . . . . . . . . . . . . . . . . . . . 3 . . . .
## 15 . . . . . . . 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . .
## 20 . . . . . 2 . . . . . . . . . . 1 . . . . . 2 2 . . . . . . . . . . 2 .
##                                                                           
## 1  3 . 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
## 2  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
## 3  . 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
## 4  . . . 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
## 5  . . . . 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
## 7  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
## 8  . . . . . . . . . . 5 . . . 4 . . 5 . . . . . . . . 5 4 . . . . . . . .
## 9  . . . . . . . . . . . . . . 1 4 5 . . . . 5 . . . . . . 4 . . . . . . .
## 10 . . . . . . . . . . . 3 . . . . . . . . . . . . . . . . . . . . . . 2 .
## 11 . . . . . . 3 . . 4 . . 2 . . . . . . . . . . . . . . . . . 3 3 . . . .
## 12 . . . 4 . . . . . . . . 1 . . . . . 4 . . . . . . . . . . . 1 . . . . .
## 13 . . . . . 3 . . . . . . . . . . . . . 3 2 . . . . 2 . . . . . . . 2 . 2
## 14 . . . . . 1 . 3 . . . . . . . . . . . . . . . 1 . . . . . 3 . . 2 . . .
## 15 . . . . . . . . 2 . . . . 3 . . . . . . . . 4 . 2 . . . . . . . . . . .
## 20 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
##         
## 1  . . .
## 2  . . .
## 3  . . .
## 4  . . .
## 5  . . .
## 7  . . 4
## 8  . . .
## 9  . . .
## 10 3 3 .
## 11 . . .
## 12 . . .
## 13 . . .
## 14 . . .
## 15 . . .
## 20 . . .

how do we

  • fit models that accommodate hierarchy and error distribution?
  • criticize these models?
  • infer or generalize the models (graphically)?
  • illustrate predictions?

Preliminaries

learning resources: stats

computing resources: r

# + first in R, best (?) documented,
# + easy to fit correlation structures in RE
# - linear
library(nlme)
# + long-running R ME project, fastest, still supported
# - correlation structures, bootstraping
library(lme4)
# + more flexible, r interface to auto-differentiation library in C++
# - less documented, fewer examples
library(glmmADMB)

Today

  • criticize these models?
  • infer or generalize the models (graphically)?
  • illustrate predictions?

emphasis

  • working with frequentist libraries for (G)LMM in R
  • visualization for: criticism, inference, prediction

three facets

  • quick diagnostic viz (plots native to fitting packages)
  • slower model criticism (also native)
  • inference & prediction (lightweight external libs / export capabilities)

where do I learn this stuff?

I. In the console

methods(class='merMod')
##  [1] anova.merMod*        as.function.merMod*  augment.merMod*     
##  [4] coef.merMod*         confint.merMod       deviance.merMod*    
##  [7] df.residual.merMod*  drop1.merMod*        extractAIC.merMod*  
## [10] family.merMod*       fitted.merMod*       fixef.merMod*       
## [13] formula.merMod*      fortify.merMod       glance.merMod*      
## [16] isGLMM.merMod*       isLMM.merMod*        isNLMM.merMod*      
## [19] isREML.merMod*       logLik.merMod*       model.frame.merMod* 
## [22] model.matrix.merMod* ngrps.merMod*        nobs.merMod*        
## [25] plot.merMod*         predict.merMod*      print.merMod*       
## [28] profile.merMod*      qqmath.merMod*       ranef.merMod*       
## [31] refit.merMod*        refitML.merMod*      residuals.merMod*   
## [34] sigma.merMod*        simulate.merMod*     summary.merMod*     
## [37] terms.merMod*        tidy.merMod*         update.merMod*      
## [40] VarCorr.merMod*      vcov.merMod          weights.merMod*     
## 
##    Non-visible functions are asterisked

II. From papers & books …

citation(package='lme4')
## 
## Bates D, Maechler M, Bolker B and Walker S (2014). _lme4: Linear
## mixed-effects models using Eigen and S4_. R package version 1.1-7,
## <URL: http://CRAN.R-project.org/package=lme4>.
## 
## Bates D, Maechler M, Bolker BM and Walker S (2014). "lme4: Linear
## mixed-effects models using Eigen and S4." ArXiv e-print; submitted
## to _Journal of Statistical Software_, <URL:
## http://arxiv.org/abs/1406.5823>.

III. … and the Internet

Back to code