Learn R Programming

afex (version 0.3-42)

mixed: Obtain p-values for a mixed-model from lmer().

Description

Fits and calculates p-values for all effects in a mixed model fitted with lmer. The default behavior calculates type 3 like p-values using the Kenward-Rogers approximation for degrees-of-freedom implemented in KRmodcomp. print, summary, and anova methods for the returned object of class "mixed" are available (all return the same data.frame).

Usage

mixed(formula, data, type = 3, method = c("KR", "PB"),
    ...)

Arguments

formula
a formula describing the full mixed-model to be fitted. As this formula is passed to lmer, it needs at least one random term.
data
data.frame containing the data. Should have all the variables present in fixed, random, and dv as columns.
type
type of test on which effects are based. Currently only type 3 tests (3 or "III") are correctly implemented (see Details).
method
character vector indicating which methods for obtaining p-values should be used. Currently only "KR" is implemented corresponding to the Kenward-Rogers approximation for degrees of freedom.
...
further arguments (such as weights) passed to lmer.

Value

  • An object of class "mixed" (i.e., a list) with the following elements:
    1. anova.tablea data.frame containing the statistics returned fromKRmodcomp.
    2. full.modelthe"mer"object returned from fitting the full mixed model.
    3. restricted.modelsa list of"mer"objects from fitting the restricted models (i.e., each model lacks the corresponding effect)
    4. testsa list of objects returned by the function for obtaining the p-values (objects are of class"KRmodcomp"whenmethod = "KR").
    5. typeThetypeargument used when calling this function.
    6. methodThemethodargument used when calling this function.
    The following methods exist for objects of class "mixed": print (which uses rounding and only returns the results wiuth F.scaling = 1), summary, and anova (the latter two return the same data.frame).

Details

Type 3 tests are obtained by comparing a model in which only the corresponding effect is missing with the full model (containing all effects). This corresponds to the (type 3) Wald tests given by car::Anova for "mer" models (from version 2.0-13). Type 2 tests are obtained by comparing a model in which the corresponding effect and all higher oder effect (e.g., all three-way interactions for a two-way interaction) are missing with a model in which all effects of the relevant order are present and all higher order effects absent. Consequently, the results for lower order effects are identical of wether or not higher order effects are part of the model or not, which is rather dubious (but https://stat.ethz.ch/pipermail/r-sig-mixed-models/2012q3/018992.html{I didn't find a better way} of implementing the Type 2 tests). This does not correspond to the (type 2) Wald Test reported by car::Anova. If you want type 2 tests, use car::Anova with test = "F" (from version 2.0-13) instead of this function. For an introduction to mixed-modeling for experimental designs using p-values see Judd, Westfall, and Kenny (2012). Further introductions to mixed-modeling for experimental designs are given by Baayen and colleagues (Baayen, 2008; Baayen, Davidson & Bates, 2008; Baayen & Milin, 2010).

References

Baayen, R. H. (2008). Analyzing linguistic data: a practical introduction to statistics using R. Cambridge, UK; New York: Cambridge University Press. Baayen, R. H., Davidson, D. J., & Bates, D. M. (2008). Mixed-effects modeling with crossed random effects for subjects and items. Journal of Memory and Language, 59(4), 390-412. doi:10.1016/j.jml.2007.12.005 Baayen, R. H., & Milin, P. (2010). Analyzing Reaction Times. International Journal of Psychological Research, 3(2), 12-28. Judd, C. M., Westfall, J., & Kenny, D. A. (2012). Treating stimuli as a random factor in social psychology: A new and comprehensive solution to a pervasive but largely ignored problem. Journal of Personality and Social Psychology, 103(1), 54–69. doi:10.1037/a0028347

See Also

ez.glm and aov.car for convenience functions to analyze experimental deisgns with classical ANOVA or ANCOVA wrapping Anova.

Examples

Run this code
# example data from package languageR:
# Lexical decision latencies elicited from 21 subjects for 79 English concrete nouns, with variables linked to subject or word.
data(lexdec, package = "languageR")

# using the simplest model
m1 <- mixed(RT ~ Correct + Trial + PrevType * meanWeight + Frequency + NativeLanguage * Length + (1|Subject) + (1|Word), data = lexdec)

m1
# gives:
##                   Effect df1       df2      Fstat p.value
## 1            (Intercept)   1   96.6379 13573.1410  0.0000
## 2                Correct   1 1627.7303     8.1452  0.0044
## 3                  Trial   1 1592.4301     7.5738  0.0060
## 4               PrevType   1 1605.3939     0.1700  0.6802
## 5             meanWeight   1   75.3919    14.8545  0.0002
## 6              Frequency   1   76.0821    56.5348  0.0000
## 7         NativeLanguage   1   27.1213     0.6953  0.4117
## 8                 Length   1   75.8259     8.6959  0.0042
## 9    PrevType:meanWeight   1 1601.1850     6.1823  0.0130
## 10 NativeLanguage:Length   1 1555.4858    14.2445  0.0002

Run the code above in your browser using DataLab