I want to create three contrast codes to include in a regression/ANOVA analysis in R.
I have tried two different approaches and although the code appears in the contrast matrix it doesn't appear in my regression/ANOVA output
This is one approach I have used to create the contrasts and assign them to the condition of interest:
c1 <- c(1, 0, -1)
c2 <- c(1, -2, 1)
c3 <- c(2, -1, -1)
mat <- cbind(c1,c2,c3)
contrasts(df$condition) <- mat
I then use this in the regression analysis:
summary(lm(Diff ~ condition, df))
And here are the coefficients from my output:
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 42.6679 0.4249 100.425 <2e-16 ***
conditionc1 1.0108 0.5169 1.955 0.0524 .
conditionc2 0.7829 0.3024 2.589 0.0106 *
What I was expecting was coefficients for c1, c2, and c3 and I cannot understand why I can't generate this.
Here are the data I'm working with:
structure(list(condition = structure(c(1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L), .Label = c("prompt_explicit", "prompt_gen", "prompt_less"
), contrasts = structure(c(1, 0, -1, 1, -2, 1), .Dim = 3:2, .Dimnames = list(
c("prompt_explicit", "prompt_gen", "prompt_less"), c("c1",
"c2"))), class = "factor"), Diff = c(44L, 40L, 40L, 40L,
40L, 40L, 40L, 40L, 40L, 40L, 60L, 44L, 50L, 40L, 40L, 40L, 60L,
40L, 44L, 40L, 40L, 52L, 50L, 50L, 40L, 40L, 40L, 40L, 40L, 40L,
40L, 40L, 40L, 50L, 40L, 60L, 42L, 42L, 40L, 48L, 40L, 60L, 40L,
40L, 40L, 44L, 50L, 50L, 60L, 42L, 60L, 50L, 40L, 40L, 40L, 56L,
40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L,
40L, 40L, 40L, 40L, 40L, 60L, 50L, 40L, 44L, 40L, 60L, 40L, 42L,
50L, 50L, 42L, 46L, 40L, 40L, 50L, 40L, 40L, 40L, 44L, 42L, 40L,
40L, 40L, 40L, 40L, 40L, 46L, 40L, 40L, 40L, 40L, 40L, 40L, 40L,
40L, 40L, 40L, 40L, 40L, 40L, 40L, 42L, 40L, 40L, 40L, 40L, 40L,
40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 42L, 40L, 48L, 46L,
50L, 44L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 50L, 52L,
40L, 40L, 40L, 40L)), row.names = c(NA, -151L), class = "data.frame")
Is there something I am missing here?