1 Question 1

1.1 Letter A

The full factorial model takes the form:

\[ y_{ijk}=\mu+\tau_i+\beta_j+\gamma_k+(\tau \beta)_{ij}+(\tau \gamma)_{ik} + (\beta \gamma)_{jk} + (\tau \beta \gamma)_{ijk} + \epsilon_{ijkl}\] where i denotes the levels of ammonium, j denotes the levels for stir rate, k denotes temperature, and l denotes the number of replicates.

1.2 Letter b

First, we want to test the null hypotheses for the three factors interaction, which takes the form:

\[ H_0: (\tau \beta \gamma)_{ijk}=0 \hspace{0.5cm}\forall \hspace{0.1cm}i \\ H_a:(\tau \beta \gamma)_{ijk} \neq 0 \hspace{0.5cm}\exists \hspace{0.1cm}ijk\] The three interaction factor is not signifcant with a p-value of 0.55. We might wanna test for the two interaction factor.

data <- read.csv("https://raw.githubusercontent.com/tmatis12/datafiles/main/PowderProduction.csv")

library(GAD)
## Loading required package: matrixStats
## Loading required package: R.methodsS3
## R.methodsS3 v1.8.2 (2022-06-13 22:00:14 UTC) successfully loaded. See ?R.methodsS3 for help.
data$Ammonium <- as.fixed(data$Ammonium)
data$StirRate <- as.fixed(data$StirRate)
data$Temperature <- as.fixed(data$Temperature)

str(data)
## 'data.frame':    16 obs. of  4 variables:
##  $ Ammonium   : Factor w/ 2 levels "2","30": 1 1 2 2 1 1 2 2 1 1 ...
##  $ StirRate   : Factor w/ 2 levels "100","150": 1 1 1 1 2 2 2 2 1 1 ...
##  $ Temperature: Factor w/ 2 levels "8","40": 1 1 1 1 1 1 1 1 2 2 ...
##  $ Density    : num  14.68 15.18 15.12 17.48 7.54 ...
model <- aov(data$Density ~ data$Ammonium+data$StirRate+data$Temperature + data$Ammonium*data$StirRate + data$Ammonium*data$Temperature + data$StirRate*data$Temperature+ data$Ammonium*data$StirRate*data$Temperature)

GAD::gad(model)
## Analysis of Variance Table
## 
## Response: data$Density
##                                              Df Sum Sq Mean Sq F value   Pr(>F)
## data$Ammonium                                 1 44.389  44.389 11.1803 0.010175
## data$StirRate                                 1 70.686  70.686 17.8037 0.002918
## data$Temperature                              1  0.328   0.328  0.0826 0.781170
## data$Ammonium:data$StirRate                   1 28.117  28.117  7.0817 0.028754
## data$Ammonium:data$Temperature                1  0.022   0.022  0.0055 0.942808
## data$StirRate:data$Temperature                1 10.128  10.128  2.5510 0.148890
## data$Ammonium:data$StirRate:data$Temperature  1  1.519   1.519  0.3826 0.553412
## Residual                                      8 31.762   3.970                 
##                                                
## data$Ammonium                                * 
## data$StirRate                                **
## data$Temperature                               
## data$Ammonium:data$StirRate                  * 
## data$Ammonium:data$Temperature                 
## data$StirRate:data$Temperature                 
## data$Ammonium:data$StirRate:data$Temperature   
## Residual                                       
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Now we want to test for two interaction, in which the hypotheses is:

\[ H_0: (\tau \beta)_{ij}=0\\ (\tau \gamma)_{ik}=0\\ (\beta \gamma)_{jk}=0\\ H_a: (\tau \beta)_{ij}\neq 0\\ (\tau \gamma)_{ik} \neq 0\\ (\beta \gamma)_{jk} \neq 0 \]

for any ijk.

The two factor interaction displayed significant interaction between Ammonium and Stir Rate with a p-value of 0.022. We do not need to proceed with the main effects test.

model_twofactor <- aov(data$Density ~ data$Ammonium+data$StirRate+data$Temperature + data$Ammonium*data$StirRate + data$Ammonium*data$Temperature + data$StirRate*data$Temperature)

GAD::gad(model_twofactor)
## Analysis of Variance Table
## 
## Response: data$Density
##                                Df Sum Sq Mean Sq F value   Pr(>F)   
## data$Ammonium                   1 44.389  44.389 12.0037 0.007109 **
## data$StirRate                   1 70.686  70.686 19.1150 0.001792 **
## data$Temperature                1  0.328   0.328  0.0886 0.772681   
## data$Ammonium:data$StirRate     1 28.117  28.117  7.6033 0.022206 * 
## data$Ammonium:data$Temperature  1  0.022   0.022  0.0059 0.940538   
## data$StirRate:data$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 plot shows that the lines are not even close to parallel, which indicates interaction.

interaction.plot(data$Ammonium,data$StirRate,data$Density)

2 Question 2

2.1 Letter A

The hypotheses testin is:

\[H_0: (\alpha \beta)_{ij}=0\\ H_a: (\alpha\beta)_{ij}\neq 0\] for any ij.

The interaction effects are not signifcant, with a p-value of 0.427. The p-value for the temperature and position are respectively 3.25e-14 and 0.001.

obs <- c(570,1063,565,
         565,1080,510,
         583,1043,590,
         528,988,526,
         547,1026,538,
         521,1004,532)

temperatures <- c(800,825,850)
pos <- c(rep(1,9),rep(2,9))
temp <- c(rep(temperatures,6))

pos <- as.fixed(pos)
temp <- as.fixed(temp)
model <- aov(obs ~ pos+temp+pos*temp)
GAD::gad(model)
## Analysis of Variance Table
## 
## Response: obs
##          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

2.2 Letter B

Considering random effects, the p-value for the interaction are still not significant (0.427). The p-values for temperature and position are respectively 0.00086 and 0.0526.

pos <- as.random(pos)
temp <- as.random(temp)
model <- aov(obs ~ pos+temp+pos*temp)
GAD::gad(model)
## Analysis of Variance Table
## 
## Response: obs
##          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

2.3 Letter C

Considering the position as fixed and temperature as random, the interaction p-value was 0.427 and no interaction were present. The p-values for temperature and position are 3.25e-14 and 0.0527.

pos <- as.fixed(pos)
temp <- as.random(temp)
model <- aov(obs ~ pos+temp+pos*temp)
GAD::gad(model)
## Analysis of Variance Table
## 
## Response: obs
##          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

2.4 Letter D

There is no interaction in any of the cases. However, the main effects for temperature seems to be significant for all the cases. Position was significant only when both factors were considered as fixed, whereas in both random and mixed groups, position was not significant.