ANCOVA was an extension to ANOVA which incorporates into the analysis as a continuous variable, but not splitting into groups. The Factorial ANOVA is an another extension which adds a second independent variable to the model which systematically manipulates groups.
When an experiment has two or more independent variables, they named as “Factorial Design”. There are three different types of Factorial Designs
1.Independent Factor Design 2.Repeated-Measures Factorial Design 3.Mixed-Designs
Independent Factor Designs, are the experiments which have several interdependent variables to create groups to asses. When we use ANOVA to analyse a situation in which there are two or more variables this is called “Factorial Anova”
First we will examine our data and see statistics, also we will check necessary assumptions for an ANOVA analysis
R sees gender as a factor variable and assigns 1 for Female and 2 for Male according to alphabetic order. However, as we will inspect dependence between quantity of alcohol intake with perception of attractiveness, increasing alcohol levels should be represented in model. So we have to reorder alcohol vector.
gogglesDATA$alcohol<-factor(gogglesDATA$alcohol, levels=c("None","2 Pints","4 Pints"))
table(gogglesDATA$gender,gogglesDATA$alcohol)
None 2 Pints 4 Pints
Female 8 8 8
Male 8 8 8
boxplot <- ggplot(gogglesDATA, aes(alcohol, attractiveness))
boxplot + geom_boxplot() + facet_wrap(~gender) + labs(x = "Alcohol Consumption", y = "Mean Attractiveness of Date (%)")
by(gogglesDATA$attractiveness, list(gogglesDATA$alcohol, gogglesDATA$gender), stat.desc, basic = FALSE)
: None
: Female
median mean SE.mean CI.mean.0.95 var std.dev
60.00000000 60.62500000 1.75191222 4.14261412 24.55357143 4.95515604
coef.var
0.08173453
------------------------------------------------------------------
: 2 Pints
: Female
median mean SE.mean CI.mean.0.95 var std.dev
62.5000000 62.5000000 2.3145502 5.4730417 42.8571429 6.5465367
coef.var
0.1047446
------------------------------------------------------------------
: 4 Pints
: Female
median mean SE.mean CI.mean.0.95 var std.dev
55.0000000 57.5000000 2.5000000 5.9115606 50.0000000 7.0710678
coef.var
0.1229751
------------------------------------------------------------------
: None
: Male
median mean SE.mean CI.mean.0.95 var std.dev
67.5000000 66.8750000 3.6519931 8.6355914 106.6964286 10.3293963
coef.var
0.1544583
------------------------------------------------------------------
: 2 Pints
: Male
median mean SE.mean CI.mean.0.95 var std.dev
67.5000000 66.8750000 4.4257263 10.4651798 156.6964286 12.5178444
coef.var
0.1871827
------------------------------------------------------------------
: 4 Pints
: Male
median mean SE.mean CI.mean.0.95 var std.dev
32.5000000 35.6250000 3.8309711 9.0588071 117.4107143 10.8356225
coef.var
0.3041578
From the basic statistics we see that mean attractiveness level fell considerably both for male and female subjects as the quantity of alcohol intake increases to 4 pints from 2 pints. However attractiveness measure increases between 2 pints and 4 pints.
%Testing Assumptions%
Bellow you could find levene test results for 3 different grouping designs. The alcohol gender and their interaction.
levene.test(gogglesDATA$attractiveness,gogglesDATA$gender,center=median)
'levene.test' is deprecated.
Use 'leveneTest' instead.
See help("Deprecated") and help("car-deprecated").
Levene's Test for Homogeneity of Variance (center = median)
Df F value Pr(>F)
group 1 19.979 5.08e-05 ***
46
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
levene.test(gogglesDATA$attractiveness,gogglesDATA$alcohol,center=median)
'levene.test' is deprecated.
Use 'leveneTest' instead.
See help("Deprecated") and help("car-deprecated").
Levene's Test for Homogeneity of Variance (center = median)
Df F value Pr(>F)
group 2 2.3238 0.1095
45
levene.test(gogglesDATA$attractiveness,interaction(gogglesDATA$gender,gogglesDATA$alcohol),center=median)
'levene.test' is deprecated.
Use 'leveneTest' instead.
See help("Deprecated") and help("car-deprecated").
Levene's Test for Homogeneity of Variance (center = median)
Df F value Pr(>F)
group 5 1.4252 0.2351
42
Regarding on results under 0.95 confidence level observed group variances are equal to each other. So it’s OK to use ANOVA.
As we experienced at data discovery phase it’s evident that “No Alcohol”,“2 Pints” and “4 pints” of alcohol group’s attractiveness scores are changes evidently. But any significant difference between groups could be turn to insignificant relationship when the observed variables are assigned differently.
So we will use three contrast
First one, which compares No Alcohol group with union of “2 pints” and “4 pints” and the second one which excludes “No Alcohol” groups and compares two difference dosage of alcohol. And finally third one will separates females from males.
contrasts(gogglesData$alcohol)<-cbind(c(-2, 1, 1), c(0, -1, 1))
contrasts(gogglesData$gender)<-c(-1, 1)
Now we can estimate our two way ANOVA model which includes alcohol intake and gender independent variables as regressors.
gogglesModel<-aov(gogglesDATA$attractiveness ~ gogglesDATA$gender + gogglesDATA$alcohol + gogglesDATA$gender:gogglesDATA$alcohol)
summary(gogglesModel)
Df Sum Sq Mean Sq F value Pr(>F)
gogglesDATA$gender 1 169 168.7 2.032 0.161
gogglesDATA$alcohol 2 3332 1666.1 20.065 7.65e-07 ***
gogglesDATA$gender:gogglesDATA$alcohol 2 1978 989.1 11.911 7.99e-05 ***
Residuals 42 3488 83.0
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Output clear states that we can exclude sole effect of gender factor on attractiveness score. In other words when all other effects are equal, man and woman selects equally attractive mates with each other. However,results also show that alcohol has a significant effect on attractiveness score. Also interaction of gender and alcohol has an effect on attractiveness. The interaction effect is highly significant while main effects suggests that gender discrimination is not significant. So at this point it would be better to check contrasts.
summary.lm(gogglesModel)
Call:
aov(formula = gogglesDATA$attractiveness ~ gogglesDATA$gender +
gogglesDATA$alcohol + gogglesDATA$gender:gogglesDATA$alcohol)
Residuals:
Min 1Q Median 3Q Max
-21.875 -5.625 -0.625 5.156 19.375
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 60.625 3.222 18.818 < 2e-16
gogglesDATA$genderMale 6.250 4.556 1.372 0.177
gogglesDATA$alcohol2 Pints 1.875 4.556 0.412 0.683
gogglesDATA$alcohol4 Pints -3.125 4.556 -0.686 0.497
gogglesDATA$genderMale:gogglesDATA$alcohol2 Pints -1.875 6.443 -0.291 0.772
gogglesDATA$genderMale:gogglesDATA$alcohol4 Pints -28.125 6.443 -4.365 8.12e-05
(Intercept) ***
gogglesDATA$genderMale
gogglesDATA$alcohol2 Pints
gogglesDATA$alcohol4 Pints
gogglesDATA$genderMale:gogglesDATA$alcohol2 Pints
gogglesDATA$genderMale:gogglesDATA$alcohol4 Pints ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 9.112 on 42 degrees of freedom
Multiple R-squared: 0.6111, Adjusted R-squared: 0.5648
F-statistic: 13.2 on 5 and 42 DF, p-value: 9.609e-08
The contrast model says that it’s only the males drunk 4 pints of beer is significantly different. Significance of this parameter states that it’s only the difference between females drunk 4 pits of beer versus males drunk 4 pits of beer is the significant among contrast. So we can also suggest that this pairing would be the most inferential block that effects our Two Way ANOVA test.
Finally we can employ a post-hoc analysis to verify our conclusion.
pairwise.t.test(gogglesDATA$attractiveness, gogglesDATA$alcohol, p.adjust.method = "bonferroni")
Pairwise comparisons using t tests with pooled SD
data: gogglesDATA$attractiveness and gogglesDATA$alcohol
None 2 Pints
2 Pints 1.00000 -
4 Pints 0.00024 0.00011
P value adjustment method: bonferroni
pairwise.t.test(gogglesDATA$attractiveness, gogglesDATA$alcohol, p.adjust.method = "BH")
Pairwise comparisons using t tests with pooled SD
data: gogglesDATA$attractiveness and gogglesDATA$alcohol
None 2 Pints
2 Pints 0.81375 -
4 Pints 0.00012 0.00011
P value adjustment method: BH
postHocs<-glht(gogglesModel, linfct = mcp(alcohol = "Tukey"))
Error in mcp2matrix(model, linfct = linfct) :
Variable(s) ‘alcohol’ have been specified in ‘linfct’ but cannot be found in ‘model’!
pairwise.t.test(gogglesDATA$attractiveness, gogglesDATA$gender, p.adjust.method = "bonferroni")
Pairwise comparisons using t tests with pooled SD
data: gogglesDATA$attractiveness and gogglesDATA$gender
Female
Male 0.35
P value adjustment method: bonferroni
pairwise.t.test(gogglesDATA$attractiveness, gogglesDATA$gender, p.adjust.method = "BH")
Pairwise comparisons using t tests with pooled SD
data: gogglesDATA$attractiveness and gogglesDATA$gender
Female
Male 0.35
P value adjustment method: BH
It is again verified that it’s the amount of alcohol intake not gender that effects attractiveness score.