Matteo Petit Bon
Matteo Petit Bon

Reputation: 1

How to set specific level contrasts with lmer in lme4

I have a mixed model containing the response variable (resp), two fixed effects (fix1 and fix2) and a random factor (ran1). In particular:

  1. fix1 has 2 levels (control and treatment);
  2. fix2 has 7 levels (from 1 to 7, indicating time in a categorical sense);
  3. ran1 has 6 levels (plots were paired, and pair is used as random variable).

An example of the type of data I am using is

library("tidyr")
library("dplyr")
set.seed(123)
DF <- data.frame(resp = rnorm(84, -2, 1),
             fix1 = c(rep("C",42),rep("Trt",42)), 
             fix2 = c(rep("1",6),rep("2",6),rep("3",6),rep("4",6),rep("5",6),rep("6",6),rep("7",6),
                      rep("1",6),rep("2",6),rep("3",6),rep("4",6),rep("5",6),rep("6",6),rep("7",6)),
             ran1 = c(rep(1:6,14)))
DF

From the example above it's evident that:

  1. the experimental design is fully factorial (fix1 * fix2);
  2. All plots have been sampled at each occasion (7 levels of fix2).

In a mixed model containing the interaction between fix1 and fix2,

LME <- lmer(resp ~ fix1 * fix2 + (1 | ran1), DF)

I would like to compare (for fix2):

  1. the average of levels 1 and 2 against the average of levels 3, 4, and 5;
  2. the average of levels 3, 4, and 5 against the average of levels 6 and 7;
  3. the average of levels 1 and 2 against the average of levels 6 and 7.

My questions are:

Upvotes: 0

Views: 719

Answers (0)

Related Questions