Skip to content

keeping both numerically and factor coded factors

2 messages · Maarten Jung

#
Dear Elisa,

if you just want use the RePsychLing::rePCA() function on objects
return by the afex::mixed() function, you can simply set the *return*
argument of the mixed() function to "merMod". This will work, but -
somewhat counter-intuitively - make the mixed() function return an
object of class lmerModLmerTest as mixed(), by default, uses
lmerTest::lmer() for its calculations.
If you really need a merMod object, then you need to set
afex_options(lmer_function = "lme4") before calling mixed().

library("afex")
library("RePsychLing")

d <- lme4::sleepstudy
d$Days <- cut(d$Days, breaks = 2, labels = c("first_half", "second_half"))

set_sum_contrasts()

# optional: make mixed() return a merMod object
# afex_options(lmer_function = "lme4")

m1 <- mixed(formula = Reaction ~ Days + (Days || Subject),
                     data = d,
                     expand_re = TRUE,
                     return = "merMod")

summary(rePCA(m1))

Best regards,
Maarten

On Wed, Jul 31, 2019 at 10:14 AM MONACO Elisa via R-sig-mixed-models
<r-sig-mixed-models at r-project.org> wrote:
On Wed, Jul 31, 2019 at 10:14 AM MONACO Elisa via R-sig-mixed-models
<r-sig-mixed-models at r-project.org> wrote:
#
Following up on my last mail (sorry, I was in a rush earlier today):

As you noted, for lme4::lmer() the double-bar syntax || works as
expected only after converting factor-based to vector-valued
random-effects structures, i.e., after converting factors to numeric
covariates.
There are several ways to do this conversion and the mixed() function
is certainly one of them. Note, however, that the standard formula
syntax of mixed() doesn't allow the user to drop higher-order random
effect terms before lower-order random effect terms by which I mean
dropping randomly varying slopes (e.g. by participant) for
interactions before random slopes for main effects. An alternative
would be to manually create the numeric covariates from the model
matrix. If you are interested in this option, then this [1] RPub by
Reinhold Kliegl explains how you can do this.

[1] https://rpubs.com/Reinhold/22193

Best regards,
Maarten

On Wed, Jul 31, 2019 at 11:10 AM Maarten Jung
<Maarten.Jung at mailbox.tu-dresden.de> wrote: