Learn R Programming

afex (version 0.2-26)

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 (currently the only behavior implemented) 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 sums of squares on which effects are based. Currently only type 3 (3 or "III") is implemented.
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 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, summary, and anova (all return the same data.frame, and print uses rounding).

Details

Type 3 sums of squares are obtained by fitting a model in which only the corresponding effect is missing. 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 (Baaye, 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