1 Assignment on Factorial Design and Mixed Effects

1.1 Question 1

  • Linear Effects Equation for Factorial Design: \[y_{i,j,k} = \mu + \tau_{i} + \beta_{j} + \gamma_k + (\tau\beta)_{i,j} + (\beta\gamma)_{j,k} + (\tau\gamma)_{i,k} + (\tau\beta\gamma)_{i,j,k} + \epsilon _{i,j,k,l}\]

    Where
    \(\mu\): Grand Mean;
    \(\tau_{i}\): Treatment effect for factor i; (i=Ammonium%)
    \(\beta_{j}\): Treatment effect for factor j; (j=Stir Rate)
    \(\gamma_{k}\): Treatment effect for factor k; (k=Temperature)
    \((\tau\beta)_{i,j}\): Interaction effect between factors i and j; (Ammonium% and Stir Rate)
    \((\beta\gamma)_{j,k}\): Interaction effect between factors j and k;
    \((\tau\gamma)_{i,k}\): Interaction effect between factors i and k;
    \((\tau\beta\gamma)_{i,j,k}\): Interaction effect between all the factors i,j and k;
    \(\epsilon_{i,j,k,l}\): Error corresponding to factors i, j, and k at \(l^{th}\) number of replication;
    i = 2,30; j= 100,150; k=8,40; l=2 replications

  • Data Pulling and Wrangling according to Factorial design:

    We pull the data from the csv file and transform the data of Temperature, stir rate and Ammonium % as factors.

    library(GAD)
    dat <- read.csv("https://raw.githubusercontent.com/tmatis12/datafiles/main/PowderProduction.csv")
    
    #Tranform the data to factorial
    Ammonium <- as.fixed(dat$Ammonium)
    StirRate <- as.fixed(dat$StirRate)
    Temperatrue <- as.fixed(dat$Temperature)
    Denisty <- dat$Density
    data.frame(Ammonium, StirRate, Temperatrue, Denisty)
    ##    Ammonium StirRate Temperatrue Denisty
    ## 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
  • Hypothesis for interaction between all the factors

    Let us first test the hypothesis for Interaction effects among all the factors (Ammonium%, Stir rate and Temperature).

    \[H_{0}: (\tau\beta\gamma)_{i,j,k} = 0\ \ \ \forall {"i,j,k"}\\H_{a}: (\tau\beta\gamma)_{i,j,k} \neq 0\ \ \ \forall {"i,j,k"}\]

model<-aov(Denisty~Ammonium+StirRate+Temperatrue+Ammonium*StirRate*Temperatrue+Ammonium*StirRate+StirRate*Temperatrue+Ammonium*Temperatrue)
GAD::gad(model)
## Analysis of Variance Table
## 
## Response: Denisty
##                               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 **
## Temperatrue                    1  0.328   0.328  0.0826 0.781170   
## Ammonium:StirRate              1 28.117  28.117  7.0817 0.028754 * 
## Ammonium:Temperatrue           1  0.022   0.022  0.0055 0.942808   
## StirRate:Temperatrue           1 10.128  10.128  2.5510 0.148890   
## Ammonium:StirRate:Temperatrue  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

Comment: The P-value (0.5534) for combination (Ammonium, Stirrate and Temperature) is higher than the \(\alpha\) = 0.05. Therefore, we fail to reject the null hypothesis, considering no significant interaction effect among all the factors.

  • Hypothesis for interaction between the factors (Ammonium and Temperature)

    Now, testing the hypothesis for Interaction effects between Ammonium and Temperature factors.

    \[H_{0}: (\beta\gamma)_{j,k} = 0\ \ \ \forall {"j,k"}\\H_{a}: (\beta\gamma)_{j,k} \neq 0\ \ \ \forall {"j,k"}\]

model1<-aov(Denisty~Ammonium+StirRate+Temperatrue+Ammonium*StirRate+StirRate*Temperatrue+Ammonium*Temperatrue)
GAD::gad(model1)
## Analysis of Variance Table
## 
## Response: Denisty
##                      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 **
## Temperatrue           1  0.328   0.328  0.0886 0.772681   
## Ammonium:StirRate     1 28.117  28.117  7.6033 0.022206 * 
## StirRate:Temperatrue  1 10.128  10.128  2.7389 0.132317   
## Ammonium:Temperatrue  1  0.022   0.022  0.0059 0.940538   
## Residual              9 33.281   3.698                    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Comment: The P-value (0.9405) combination (Ammonium and Temperature) is higher than the \(\alpha\) = 0.05. Therefore, we fail to reject the null hypothesis, considering no significant interaction effect among the factors (Ammonium and Temperature).

  • Hypothesis for interaction between the factors (Stir Rate, and Temperature)

    Now, testing the hypothesis for Interaction effects among the factors (Stir Rate, and Temperature).

    \[H_{0}: (\tau\gamma)_{i,k} = 0\ \ \ \forall {"i,k"}\\H_{a}: (\tau\gamma)_{i,k} \neq 0\ \ \ \forall {"i,k"}\]

model2<-aov(Denisty~Ammonium+StirRate+Temperatrue+Ammonium*StirRate+StirRate*Temperatrue)
GAD::gad(model2)
## Analysis of Variance Table
## 
## Response: Denisty
##                      Df Sum Sq Mean Sq F value    Pr(>F)    
## Ammonium              1 44.389  44.389 13.3287 0.0044560 ** 
## StirRate              1 70.686  70.686 21.2250 0.0009696 ***
## Temperatrue           1  0.328   0.328  0.0984 0.7601850    
## Ammonium:StirRate     1 28.117  28.117  8.4426 0.0156821 *  
## StirRate:Temperatrue  1 10.128  10.128  3.0412 0.1117751    
## Residual             10 33.303   3.330                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Comment: The P-value (0.1117) for combination (Stir Rate and Temperature) is higher than the \(\alpha\) = 0.05. Therefore, we fail to reject the null hypothesis, considering no significant interaction effect among the factors (Stir Rate, and Temperature).

  • Hypothesis for interaction between the factors (Ammonium% and Stir Rate)

    Now, testing the hypothesis for Interaction effects among the factors (Ammonium%, and Stir rate).

    \[H_{0}: (\tau\beta)_{i,j} = 0\ \ \ \forall {"i,j"}\\H_{a}: (\tau\beta)_{i,j} \neq 0\ \ \ \forall {"i,j"}\]

model3<-aov(Denisty~Ammonium+StirRate+Temperatrue+Ammonium*StirRate)
GAD::gad(model3)
## Analysis of Variance Table
## 
## Response: Denisty
##                   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 **
## Temperatrue        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

Comment: The P-value (0.0218) for combination (Ammonium% and Stir Rate) is lower than the \(\alpha\) = 0.05. Therefore, we reject the null hypothesis, considering a significant interaction effect among the factors (Ammonium% and Stir Rate). so we check the intercations between them using an interaction plot.

  • Interaction Plot between the factors (Ammonium% and Stir Rate)

    interaction.plot(Ammonium, StirRate,Denisty,col = 'green' )

    Comment: The interaction between ammonium and stir rate is significant, since the lines are not parallel.

1.2 Question 2.

1.2.1 Part A:

  • Hypothesis:

\[H_{0}: (\alpha\beta)_{i,j} = 0\ \ \ \forall {"i,j"}\\H_{a}: (\alpha\beta)_{i,j} \neq 0\ \ \ \forall {"i,j"}\] Reading and Wrangling Data:

#Problem 2
position<-c(rep(1,9),rep(2,9))
temperature<-c(rep(800,3),rep(825,3),rep(850,3),rep(800,3),rep(825,3),rep(850,3))
density<-c(570,1063,565,565,1080,510,583,1043,590,528,988,526,547,1026,538,521,1004,532)
  • Both Fixed Effects:

    position <- as.fixed(position)
    temperature <-as.fixed(temperature)
    
    model4 <-aov(density~position+temperature+position*temperature)
    GAD::gad(model4)
    ## Analysis of Variance Table
    ## 
    ## Response: density
    ##                      Df Sum Sq Mean Sq F value Pr(>F)
    ## position              1   7160    7160  0.0904 0.7688
    ## temperature           2    101      50  0.0006 0.9994
    ## position:temperature  2   1432     716  0.0090 0.9910
    ## Residual             12 949998   79167

Comment: Upon considering both as fixed, Position and Temperature are not signifcantly differ at Alpha =0.05, since no significant interaction is observed as the pvalue (0.99) is higher than the alpha=0.05

1.2.2 Part B:

  • Both Random Effects:

    position <- as.random(position)
    temperature <-as.random(temperature)
    model5 <-aov(density~position+temperature+position*temperature)
    GAD::gad(model5)
    ## Analysis of Variance Table
    ## 
    ## Response: density
    ##                      Df Sum Sq Mean Sq F value  Pr(>F)  
    ## position              1   7160    7160  9.9993 0.08713 .
    ## temperature           2    101      50  0.0704 0.93426  
    ## position:temperature  2   1432     716  0.0090 0.99100  
    ## Residual             12 949998   79167                  
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Comment: Upon considering both as Random, Position and Temperature are not signifcantly differ at Alpha =0.05, since no significant interaction is observed as the pvalue (0.99) is higher than the alpha=0.05

1.2.3 Part C:

  • Both Mixed Effects:

    position <- as.fixed(position)
    temperature <-as.random(temperature)
    model6 <-aov(density~position+temperature+position*temperature)
    GAD::gad(model6)
    ## Analysis of Variance Table
    ## 
    ## Response: density
    ##                      Df Sum Sq Mean Sq F value  Pr(>F)  
    ## position              1   7160    7160  9.9993 0.08713 .
    ## temperature           2    101      50  0.0006 0.99936  
    ## position:temperature  2   1432     716  0.0090 0.99100  
    ## Residual             12 949998   79167                  
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Comment: Upon considering both as Mixed, Position and Temperature are not signifcantly differ at Alpha =0.05, since no significant interaction is observed as the pvalue (0.99) is higher than the alpha=0.05

1.2.4 Part D:

Overall Comments:
All the three different effect models, there was no significant difference between two factor interaction. 

2 Complete R Code

#Flipped Assignment 14  
#install.packages("GAD")
library(GAD)
dat <- read.csv("https://raw.githubusercontent.com/tmatis12/datafiles/main/PowderProduction.csv")

#Tranform the data to factorial
Ammonium <- as.fixed(dat$Ammonium)
StirRate <- as.fixed(dat$StirRate)
Temperatrue <- as.fixed(dat$Temperature)
Denisty <- dat$Density
data.frame(Ammonium, StirRate, Temperatrue, Denisty)

model<-aov(Denisty~Ammonium+StirRate+Temperatrue+Ammonium*StirRate*Temperatrue+Ammonium*StirRate+StirRate*Temperatrue+Ammonium*Temperatrue)
GAD::gad(model)
model1<-aov(Denisty~Ammonium+StirRate+Temperatrue+Ammonium*StirRate+StirRate*Temperatrue+Ammonium*Temperatrue)
GAD::gad(model1)
model2<-aov(Denisty~Ammonium+StirRate+Temperatrue+Ammonium*StirRate+StirRate*Temperatrue)
GAD::gad(model2)
model3<-aov(Denisty~Ammonium+StirRate+Temperatrue+Ammonium*StirRate)
GAD::gad(model3)

interaction.plot(Ammonium, StirRate,Denisty,col = 'green' )

#Problem 2
position<-c(rep(1,9),rep(2,9))
temperature<-c(rep(800,3),rep(825,3),rep(850,3),rep(800,3),rep(825,3),rep(850,3))
density<-c(570,1063,565,565,1080,510,583,1043,590,528,988,526,547,1026,538,521,1004,532)

position <- as.fixed(position)
temperature <-as.fixed(temperature)
data.frame(position,temperature,density)

model4 <-aov(density~position+temperature+position*temperature)
GAD::gad(model4)

position <- as.random(position)
temperature <-as.random(temperature)
model5 <-aov(density~position+temperature+position*temperature)
GAD::gad(model5)

position <- as.fixed(position)
temperature <-as.random(temperature)
model6 <-aov(density~position+temperature+position*temperature)
GAD::gad(model6)