a. The model equation for a full factorial model:
\[ Y_{ijk}=\mu+\tau_{i}+\beta_{j}+\alpha_{k}+ \tau\beta_{ij} +\tau\alpha_{ik} + + \beta\alpha_{jk} + \tau\beta\alpha_{ijk}+\epsilon_{ijk} \]
Where,
µ = Grand Mean
τi = Factor 1
βj = Factor 2
αk = Factor 3
εijk = Random error
i = number of level factor 1
j = number of level factor 2
k = number of level factor 3
b.
Input data:
library(GAD)
dt <- data.frame(read.csv('https://raw.githubusercontent.com/tmatis12/datafiles/main/PowderProduction.csv'))
dt
## Ammonium StirRate Temperature Density
## 1 2 100 8 14.68
## 2 2 100 8 15.18
## 3 30 100 8 15.12
## 4 30 100 8 17.48
## 5 2 150 8 7.54
## 6 2 150 8 6.66
## 7 30 150 8 12.46
## 8 30 150 8 12.62
## 9 2 100 40 10.95
## 10 2 100 40 17.68
## 11 30 100 40 12.65
## 12 30 100 40 15.96
## 13 2 150 40 8.03
## 14 2 150 40 8.84
## 15 30 150 40 14.96
## 16 30 150 40 14.96
Test at 3 factor interaction:
ammonium <- as.fixed(dt$Ammonium)
stirrate <- as.fixed(dt$StirRate)
temperature <- as.fixed(dt$Temperature)
response <- dt$Density
model <- aov(response~ammonium*stirrate*temperature)
GAD::gad(model)
## Analysis of Variance Table
##
## Response: response
## Df Sum Sq Mean Sq F value Pr(>F)
## ammonium 1 44.389 44.389 11.1803 0.010175 *
## stirrate 1 70.686 70.686 17.8037 0.002918 **
## temperature 1 0.328 0.328 0.0826 0.781170
## ammonium:stirrate 1 28.117 28.117 7.0817 0.028754 *
## ammonium:temperature 1 0.022 0.022 0.0055 0.942808
## stirrate:temperature 1 10.128 10.128 2.5510 0.148890
## ammonium:stirrate:temperature 1 1.519 1.519 0.3826 0.553412
## Residual 8 31.762 3.970
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
As shown in the ANOVA table, the P-value of the three factors interaction is 0.553412 which is higher than \(\alpha\) = 0.05. There is no evident to reject the Null hypothesis.
Continue to test at two factors interaction:
model2 <- aov(response~ammonium*stirrate + ammonium*temperature + stirrate*temperature)
GAD::gad(model2)
## Analysis of Variance Table
##
## Response: response
## Df Sum Sq Mean Sq F value Pr(>F)
## ammonium 1 44.389 44.389 12.0037 0.007109 **
## stirrate 1 70.686 70.686 19.1150 0.001792 **
## temperature 1 0.328 0.328 0.0886 0.772681
## ammonium:stirrate 1 28.117 28.117 7.6033 0.022206 *
## ammonium:temperature 1 0.022 0.022 0.0059 0.940538
## stirrate:temperature 1 10.128 10.128 2.7389 0.132317
## Residual 9 33.281 3.698
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
The interaction between ammonium:termperature and stirrate:termperature are not significant as its P-value are larger than \(\alpha\). We will remove these effects in the model.
model3 <- aov(response~ammonium+stirrate+temperature+ammonium*stirrate)
GAD::gad(model3)
## Analysis of Variance Table
##
## Response: response
## Df Sum Sq Mean Sq F value Pr(>F)
## ammonium 1 44.389 44.389 11.2425 0.006443 **
## stirrate 1 70.686 70.686 17.9028 0.001410 **
## temperature 1 0.328 0.328 0.0830 0.778613
## ammonium:stirrate 1 28.117 28.117 7.1211 0.021851 *
## Residual 11 43.431 3.948
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
As shown in the final ANOVA table, the main effect of ammonium (P-value = 0.006443), stirrate (P-value = 0.001410) and interaction of ammonium:stirrate (P-value = 0.021851) are significant.
Create the interaction plot for ammonium:stirrate:
interaction.plot(x.factor = ammonium, trace.factor = stirrate, response = response, ylab = 'Density', col = 'blue')
The interaction plot show a high interaction between these two factor as two line are cross each other.
Create the interaction plot for ammonium:temperature:
interaction.plot(x.factor = ammonium, trace.factor = temperature, response = response, ylab = 'Density', col = 'green')
There is almost no interaction, two lines are parallel.
Create the interaction plot for stirrate:temperature:
interaction.plot(x.factor = stirrate, trace.factor = temperature, response = response, ylab = 'Density', col = 'red')
The plot shown that there is interaction between stirrate and termperature even the test shown it is not significant.
Input data to R:
pos<-c(1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2)
temp<-c(800,800,800,825,825,825,850,850,850,800,800,800,825,825,825,850,850,850)
val<-c(570,565,583,1063,1080,1043,565,510,590,528,547,521,988,1026,1004,526,538,532)
dat<-data.frame(pos,temp,val)
a. Assume that both Temperature and Position are fixed effects. Report p-values
pos <- as.fixed(pos)
temp <- as.fixed(temp)
model4 <- aov(val~pos+temp+pos*temp)
GAD::gad(model4)
## Analysis of Variance Table
##
## Response: val
## Df Sum Sq Mean Sq F value Pr(>F)
## pos 1 7160 7160 15.998 0.001762 **
## temp 2 945342 472671 1056.117 3.25e-14 ***
## pos:temp 2 818 409 0.914 0.427110
## Residual 12 5371 448
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
b. Assume that both Temperature and Position are random effects. Report p-values
pos <- as.random(pos)
temp <- as.random(temp)
model5 <- aov(val~pos*temp)
GAD::gad(model5)
## Analysis of Variance Table
##
## Response: val
## Df Sum Sq Mean Sq F value Pr(>F)
## pos 1 7160 7160 17.504 0.0526583 .
## temp 2 945342 472671 1155.518 0.0008647 ***
## pos:temp 2 818 409 0.914 0.4271101
## Residual 12 5371 448
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
c. Assume the Position effect is fixed and the Temperature effect is random. Report p-values
pos <- as.fixed(pos)
temp <- as.random(temp)
model6 <- aov(val~pos*temp)
GAD::gad(model6)
## Analysis of Variance Table
##
## Response: val
## Df Sum Sq Mean Sq F value Pr(>F)
## pos 1 7160 7160 17.504 0.05266 .
## temp 2 945342 472671 1056.117 3.25e-14 ***
## pos:temp 2 818 409 0.914 0.42711
## Residual 12 5371 448
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
d. Comment on similarities and/or differences between the p-values in parts a,b,c.
The effect of interaction are the same in all a, b, c. However, the effect of main effect is changed when we change from fix to random.
#question 1
dt <- data.frame(read.csv('https://raw.githubusercontent.com/tmatis12/datafiles/main/PowderProduction.csv'))
dt
ammonium <- as.fixed(dt$Ammonium)
stirrate <- as.fixed(dt$StirRate)
temperature <- as.fixed(dt$Temperature)
response <- dt$Density
model <- aov(response~ammonium*stirrate*temperature)
GAD::gad(model)
model2 <- aov(response~ammonium*stirrate + ammonium*temperature + stirrate*temperature)
GAD::gad(model2)
model3 <- aov(response~ammonium+stirrate+temperature+ammonium*stirrate)
GAD::gad(model3)
interaction.plot(x.factor = ammonium, trace.factor = stirrate, response = response, ylab = 'Density', col = 'blue')
interaction.plot(x.factor = ammonium, trace.factor = temperature, response = response, ylab = 'Density', col = 'green')
interaction.plot(x.factor = stirrate, trace.factor = temperature, response = response, ylab = 'Density', col = 'red')
#Question 2
pos<-c(1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2)
temp<-c(800,800,800,825,825,825,850,850,850,800,800,800,825,825,825,850,850,850)
val<-c(570,565,583,1063,1080,1043,565,510,590,528,547,521,988,1026,1004,526,538,532)
dat<-data.frame(pos,temp,val)
#a
pos <- as.fixed(pos)
temp <- as.fixed(temp)
model4 <- aov(val~pos+temp+pos*temp)
GAD::gad(model4)
#b
pos <- as.random(pos)
temp <- as.random(temp)
model5 <- aov(val~pos*temp)
GAD::gad(model5)
#c
pos <- as.fixed(pos)
temp <- as.random(temp)
model6 <- aov(val~pos*temp)
GAD::gad(model6)