3
$\begingroup$

I am using R to analyse data from an experiment with six conditions. Condition has two dimensions: for cognitive load, I have two levels (load and no load) and for language structure I have three levels (structured, partially structured and unstructured). These are then fully crossed giving the six conditions. They are all between-subjects.

I want to run a mixed effects model with the two condition dimensions and the interaction between them as predictors, and a numeric accuracy dependent variable.

My supervisor mentioned that I could use Helmert coding for the structure conditions but I can find very little information about how this works and any resources I have found don't explain how the contrasts are generated in enough detail for me to know what the R code is doing. From what I can understand it does seem like the right coding scheme, as what I basically want to know is whether there's a difference between structured languages and the rest, and whether there's a difference between partially structured and unstructured languages - I think this is what "comparing the mean of each level to subsequent levels" is doing? But I'm really stuck on how to create these contrasts and then how to use them in a mixed model. Any help would be much appreciated - even if it's just to point me to any more detailed resources on Helmert coding.

$\endgroup$

1 Answer 1

1
$\begingroup$

Here is an example of using Helmert contrasts with lme4. First we smulate some data:

set.seed(1)
n_group <- 10
dt <- expand.grid(X = LETTERS[1:3], G = LETTERS[1:n_group], reps = 1:2)
X <- model.matrix(~ X, dt)

dt$Y <- 1
myFormula <- "Y ~ X + (1 | G)"

foo <- lFormula(eval(myFormula), dt)
Z <- t(as.matrix(foo$reTrms$Zt))

betas <- c(1, 0.5, 2) # Fixed effects parameters

u <- rnorm(n_group, 0, 2) # standard deviation of random intercepts

e <- rnorm(nrow(dt), 0, 1)   # residual error

dt$Y <- X %*% betas + Z %*% u + e   

Now we set the contrast matrix and specify it when we call lmer

ch <- contr.helmert(3)   # Because X has 3 levels

lmer(myFormula, dt, contrasts = list(X = ch))
```
$\endgroup$
4
  • $\begingroup$ Thank you. What I'm not sure about is how to interpret the coefficients I get back from a mixed model when I've used Helmert coding for the structure variable. Instead of the named levels I get back coefficients for structure1 and structure2. What is in the intercept and what are these coefficients for? $\endgroup$
    – shleen
    Commented Jul 27, 2021 at 10:10
  • $\begingroup$ You're welcome. The interpretation of Helmert contrasts in a mixed model is exactly the same as for a non-mixed model. The fact that it's a mixed model is not relevant. $\endgroup$ Commented Jul 27, 2021 at 10:55
  • $\begingroup$ Sorry to be unclear, my problem is less that it's a mixed model and more that I've never used Helmert contrasts before, so I wouldn't know how to interpret the coefficients in a non-mixed model either. $\endgroup$
    – shleen
    Commented Jul 27, 2021 at 11:43
  • $\begingroup$ Your question says "But I'm really stuck on how to create these contrasts and then how to use them in a mixed model. Any help would be much appreciated" and I thought I had answered that? Interpretation wasn't mentioned in your question at all so I would suggest asking a new question about interpretation. $\endgroup$ Commented Jul 27, 2021 at 12:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.