################# QUESTION NO: 1 #

Answer to the Question No: 1(a)

Model Equation for full factorial model:

\[ y_{ijkl} = \mu + \alpha_{i} + \beta_{j} + \gamma_{k} + \alpha\beta_{ij} + \alpha\gamma_{ik} + \beta\gamma_{jk} + \alpha\beta\gamma_{ijk} + \epsilon_{ijkl} \]

Answer to the Question No: 1(b)

library(GAD)
## Warning: package 'GAD' was built under R version 4.1.3
## Loading required package: matrixStats
## Warning: package 'matrixStats' was built under R version 4.1.3
## Loading required package: R.methodsS3
## Warning: package 'R.methodsS3' was built under R version 4.1.3
## R.methodsS3 v1.8.2 (2022-06-13 22:00:14 UTC) successfully loaded. See ?R.methodsS3 for help.
data<-read.csv("https://raw.githubusercontent.com/tmatis12/datafiles/main/PowderProduction.csv")
colnames(data)<-c("ammonium","stirRate","temperture","density")
data
##    ammonium stirRate temperture 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
ammonium<-as.fixed(data$ammonium)
stirRate<-as.fixed(data$stirRate)
temperture<-as.fixed(data$temperture)
density<-as.numeric(data$density)
dat<-data.frame(ammonium,stirRate,temperture, density)

mod<-aov(density~ammonium+stirRate+temperture+ammonium*stirRate+ammonium*temperture+stirRate*temperture+ammonium*stirRate*temperture,data=dat)
gad(mod)
## Analysis of Variance Table
## 
## Response: density
##                              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 **
## temperture                    1  0.328   0.328  0.0826 0.781170   
## ammonium:stirRate             1 28.117  28.117  7.0817 0.028754 * 
## ammonium:temperture           1  0.022   0.022  0.0055 0.942808   
## stirRate:temperture           1 10.128  10.128  2.5510 0.148890   
## ammonium:stirRate:temperture  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: Based on P-values we see three factor of interaction is greater than 0.05, so we remove the interaction between ammonia , stir rate and temperature first.

model1<-aov(density~ammonium+stirRate+temperture+ammonium*stirRate+ammonium*temperture+stirRate*temperture,data=dat)
gad(model1)
## Analysis of Variance Table
## 
## Response: density
##                     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 **
## temperture           1  0.328   0.328  0.0886 0.772681   
## ammonium:stirRate    1 28.117  28.117  7.6033 0.022206 * 
## ammonium:temperture  1  0.022   0.022  0.0059 0.940538   
## stirRate:temperture  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

Comment: Based on P-values we see two factor of interaction is greater than 0.05, so we remove the interaction between ammonia and temperature now and run the model again.

model2<-aov(density~ammonium+stirRate+temperture+ammonium*stirRate+stirRate*temperture,data=dat)
gad(model2)
## Analysis of Variance Table
## 
## Response: density
##                     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 ***
## temperture           1  0.328   0.328  0.0984 0.7601850    
## ammonium:stirRate    1 28.117  28.117  8.4426 0.0156821 *  
## stirRate:temperture  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: Based on P-values we see two factor of interaction is greater than 0.05, so we remove the interaction between stir rate and temperature now and run the model again.

model3<-aov(density~ammonium+stirRate+temperture+ammonium*stirRate, data=dat)
GAD::gad(model3)
## Analysis of Variance Table
## 
## Response: density
##                   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 **
## temperture         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: Based on P-values we see one factor of interaction is greater than 0.05, so we remove the temperature now and run the model again.

model4<-aov(density~ammonium+stirRate+ammonium*stirRate,data=dat)
GAD::gad(model4)
## Analysis of Variance Table
## 
## Response: density
##                   Df Sum Sq Mean Sq F value    Pr(>F)    
## ammonium           1 44.389  44.389 12.1727 0.0044721 ** 
## stirRate           1 70.686  70.686 19.3841 0.0008612 ***
## ammonium:stirRate  1 28.117  28.117  7.7103 0.0167511 *  
## Residual          12 43.759   3.647                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Comment: Based on P-values we see all the remain factor comes out significant level at 0.05.

interaction.plot(data$stirRate,data$ammonium, data$density)

Comment: from the interaction plot the lines are not parallel, which means the interaction between ammonium and stir rate is significant.

################################ Question No: 2 #############################

Insert the data:

pos <- c(rep("1",9),rep("2",9))
temp <- c("800","825","850","800","825","850","800","825","850","800","825","850","800","825","850","800","825","850") 
den<- c(570,1063,565,565,1080,510,583,1043,590,528,988,526,547,1026,538,521,1004,532)
dat2 <- data.frame(pos,temp,den)

Answer to the question No: 2(a)

dat2$pos <- as.fixed(dat2$pos)
dat2$temp <- as.fixed(dat2$temp)
model11 <- aov(dat2$den~dat2$temp+dat2$pos+dat2$temp*dat2$pos) 
gad(model11)
## Analysis of Variance Table
## 
## Response: dat2$den
##                    Df Sum Sq Mean Sq  F value   Pr(>F)    
## dat2$temp           2 945342  472671 1056.117 3.25e-14 ***
## dat2$pos            1   7160    7160   15.998 0.001762 ** 
## dat2$temp:dat2$pos  2    818     409    0.914 0.427110    
## Residual           12   5371     448                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Comments: When the temperature and position are fixed the P-value for the model are

P-Value for Temperature is 3.25e-14

P-Value for Position is 0.001762

P-Value for two factor interaction position and temperature is 0.427110

Answer to the question No: 2(b)

dat2$pos <- as.random(dat2$pos)
dat2$temp <- as.random(dat2$temp)
model22 <- aov(dat2$den~dat2$temp+dat2$pos+dat2$temp*dat2$pos) 
gad(model22)
## Analysis of Variance Table
## 
## Response: dat2$den
##                    Df Sum Sq Mean Sq  F value    Pr(>F)    
## dat2$temp           2 945342  472671 1155.518 0.0008647 ***
## dat2$pos            1   7160    7160   17.504 0.0526583 .  
## dat2$temp:dat2$pos  2    818     409    0.914 0.4271101    
## Residual           12   5371     448                       
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Comments: When the temperature and position both are random the P-value for the model are

P-Value for Temperature is 0.0008647

P-Value for Position is 0.0526583

P-Value for two factor interaction position and temperature is 0.4271101

Answer to the question No: 2(c)

dat2$pos <- as.fixed(dat2$pos)
dat2$temp <- as.random(dat2$temp)
model33 <- aov(dat2$den~dat2$temp+dat2$pos+dat2$temp*dat2$pos) 
gad(model33)
## Analysis of Variance Table
## 
## Response: dat2$den
##                    Df Sum Sq Mean Sq  F value   Pr(>F)    
## dat2$temp           2 945342  472671 1056.117 3.25e-14 ***
## dat2$pos            1   7160    7160   17.504  0.05266 .  
## dat2$temp:dat2$pos  2    818     409    0.914  0.42711    
## Residual           12   5371     448                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Comments: When the temperature is fixed and position is random the P-value for the model are

P-Value for Temperature is 3.25e-14

P-Value for Position is 0.05266

P-Value for two factor interaction position and temperature is 0.4271101

Answer to the question No: 2(d)

We see the same p-value for interaction for part a, b & c.ย that means there is significant difference as fixed and random. The P-value of each differs for fixed and random effects.