[R-sig-ME] afex "mixed" function - issue with Helmert coded contrasts
Henrik Singmann
singmann at psychologie.uzh.ch
Tue Sep 12 17:34:40 CEST 2017
Hi Lindsey,
The only thing check_contrasts (which was check.contrasts in previous
versions) does, is set the contrasts for all categorical variables to
"contr.sum". If you do not want to use contr.sum but your own coding set
it to FALSE. It has no additional functionality. If you set it to FALSE,
you obviously have to make sure that the contrasts of the other
categorical variables are orthogonal (e.g., are contr.helmert or
contr.sum). Models with interactions of categorical variables that are
not orthogonal are somewhat nonsensical (if type=3, which is the default
in afex).
If you then want to obtain p-values for each individual level of the
variable (i.e., if your categorical variable has more than 2 levels),
you can use the per_parameter argument, e.g., per_parameter =
"two_flashes". Note that this will test the individual parameters for
all interaction involving this factor. You can use regular expressions
to change this (see below).
Note that you need to use method="nested-KR" (or "LRT" or "PB") to use
this functionality. That is currently not correct in the examples in
?mixed, I will have to change this in the next version (the contrasts
thing in the examples is also wrong, I am not sure why I did such a bad
job there). A correct example combining this would be:
require(afex)
data(obk.long)
# Examples for using the per.parameter argument:
data(obk.long, package = "afex")
obk.long$hour <- ordered(obk.long$hour)
contrasts(obk.long$phase) <- "contr.sum"
contrasts(obk.long$treatment) <- "contr.sum"
# tests only the main effect parameters of hour individually per parameter.
mixed(value ~ treatment*phase*hour +(1|id), per_parameter = "^hour$",
data = obk.long, method = "nested-KR", check_contrasts = FALSE)
# tests all parameters including hour individually
mixed(value ~ treatment*phase*hour +(1|id), per_parameter = "hour", data
= obk.long, method = "nested-KR", check_contrasts = FALSE)
Finally, note that an intercept only model is probably not a great idea.
In your case, the maximal model seems out of reach (just judging from
the number of fixed effects), but you should probably take a look at the
following three paper for some discussion. The punchline is that some of
those fixed effects probably need some random slopes to keep the Type I
errors within reasonable bounds.
Barr, D. J., Levy, R., Scheepers, C., & Tily, H. J. (2013). Random
effects structure for confirmatory hypothesis testing: Keep it maximal.
Journal of Memory and Language, 68(3), 255–278.
https://doi.org/10.1016/j.jml.2012.11.001
Matuschek, H., Kliegl, R., Vasishth, S., Baayen, H., & Bates, D. (2017).
Balancing Type I error and power in linear mixed models. Journal of
Memory and Language, 94, 305–315. https://doi.org/10.1016/j.jml.2017.01.001
Bates, D., Kliegl, R., Vasishth, S., & Baayen, H. (2015). Parsimonious
Mixed Models. ArXiv:1506.04967 [Stat]. Retrieved from
http://arxiv.org/abs/1506.04967
Hope that helps,
Henrik
Am 11.09.2017 um 21:20 schrieb Lindsey Kishline:
> Hello all,
>
> I am running afex "mixed" function to get p values from a lmer model with a
> continuous predictor (reaction times between 200ms-999ms), five fixed
> variables, and a random subject intercept.
>
> One of my variables is Helmert coded contrast, and when I run the model
> using the "mixed" function it will change that contrast to "contr.sum" and
> I will not receive p values for the contrasted levels.
>
> It successfully runs the model and gives p values for all coefficients,
> except for the contrasts. If "check.contrasts" option is TRUE - it sets the
> contrasts to "contr.sum" and I don't get p values for the contrasted levels
> and their interactions. If "check.contrasts" = FALSE runs fine but
> obviously the contrasts aren't checked.
>
> Here are the lines of code that I am using to run the model:
>
> full_form_RT <- formula(raw_RT ~
> two_flashes*cue_attn*ecc*two_sounds_at_target_location*pressed_two +
> (1|subjnum))
> RT_full_mod <- mixed(full_form_RT, data=foo, method="S")
>
> When I use method = "KR" I get the following error so I have used method =
> "S":
> 'anova from lme4 is returned
> some computational error has occurred in lmerTest
> Error in '[.data.frame'(anova_table, ,c("NumDF", "DenDF", "F.value", :
> undefined columns selected'
>
>
> Does anyone know how I might be able to obtain p values for the contrasts?
> Is there a reason that they are automatically changed to "contr.sum" and I
> can't use the Helmert coding? Or why the Kenward-Roger method gives me the
> above error?
>
> Thank you for your time,
>
More information about the R-sig-mixed-models
mailing list