Data
1.Define the (orthogonal) contrasts
2. 2 way ANOVA
3. Partial eta square indexes
4. Residuals
5. Residuals plot
6. Normality of residuals
7. Homogeneity test (equal variance among all combinations of factor's levels)
Note: This code provide exactly the same results with SPSS. The above example is contained in the paragraph 5.3 of the book "Στατιστική ανάλυση με τη γλώσσα R" (in Greek, ISBN: 978-960-93-9445-1) published in Thessaloniki, 2017.
# 31 salesmen training in three groups, 1 (Group A), 2 (Group B) and 3 (Group C) days.
# Gender is also recorded.
perform.A = c(63.3, 68.3, 86.7, 52.8, 75, 58, 69.5, 32.7, 60.9, 58.2)
A.gender = c(1, 1, 1, 0, 0, 0, 1, 0, 0, 0)
perform.B = c(72.8, 88.2, 80.8, 71.3, 81.5, 47.6, 81, 81.4, 83, 76, 74.5)
B.gender = c(1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1)
perform.C = c(82.3, 89.7, 81, 85.1, 74.1, 75.9, 74.7, 81.1, 76.4, 81.8)
C.gender = c(0, 0, 1, 0, 1, 1, 1, 1, 1, 0)
sales = c(perform.A, perform.B, perform.C)
gender = c(A.gender, B.gender, C.gender)
group = c(rep(1, 10), rep(2, 11), rep(3, 10))
gender = factor(gender, levels = c(0, 1), labels = c("Woman", "Man"))
group = factor(group, levels = c(1, 2, 3), labels = c("Α", "Β", "Γ"))
anova.df = data.frame(group, gender, sales)
1.Define the (orthogonal) contrasts
contrasts(anova.df$gender) <- anova.df="" code="" contr.helmert="" contrasts="" group="">->
2. 2 way ANOVA
library(car)
lm.model = lm(sales ~ group + gender + group * gender, anova.df)
Anova(lm.model, type="III")
3. Partial eta square indexes
library(lsr)
etaSquared(aov(lm.model), type = 3)
4. Residuals
data.res = resid(lm.model)
5. Residuals plot
boxplot(data.res, col = c("orange"), horizontal = TRUE, main = "Residuals boxplot")
hist(data.res, main = "Residuals histogram", col = c("coral4"))
6. Normality of residuals
shapiro.test(data.res)
7. Homogeneity test (equal variance among all combinations of factor's levels)
leveneTest(sales ~ group * gender, anova.df)
Note: This code provide exactly the same results with SPSS. The above example is contained in the paragraph 5.3 of the book "Στατιστική ανάλυση με τη γλώσσα R" (in Greek, ISBN: 978-960-93-9445-1) published in Thessaloniki, 2017.
Comments
Post a Comment