Hi, I try to grasp a concept of contrasts (planned comparisons) in R.
I need to create such a table:
This simple table will illustrate what could be compared with what, and how many comparisons do we have to do ?
Here is my data:
dat <- structure(list(ID = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28,
29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
45, 46, 47, 48), Self_control = c(65, 70, 60, 60, 60, 55, 60,
55, 70, 65, 60, 70, 65, 60, 60, 50, 55, 65, 70, 55, 55, 60, 50,
50, 50, 55, 80, 65, 70, 75, 75, 65, 45, 60, 85, 65, 70, 70, 80,
60, 30, 30, 30, 55, 35, 20, 45, 40), Sex = 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, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), levels = c("Female",
"Male"), class = "factor"), Alcohol = structure(c(1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), levels = c("None",
"2 Pints", "4 Pints"), class = "factor")), row.names = c(NA,
48L), class = "data.frame")
# Factor:
dat$Sex <- factor(dat$Sex, levels=c("Male", "Female"),
labels=c("Male", "Female"))
dat$Sex <- relevel(dat$Sex, ref="Female")
levels(dat$Sex)
Obviously when I use:
contrasts(dat$Alcohol)
contr.treatment(levels(dat$Alcohol))
It gives me:
but it looks rather cryptic. So I have figured that my table will be better to understand what is going on for a starting point.
How do I create such a table ? How do I start, please ? Any help will be much appreciated.
Maybe a ready function exists in R to do it ?
kind regards,