Problem 1:

(a) model equation for a full 2^3 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} \]

(b)What factors are deemed significant

library(GAD)
## Warning: package 'GAD' was built under R version 4.4.3
df<-read.csv("https://raw.githubusercontent.com/tmatis12/datafiles/main/PowderProduction.csv")
print(df)
##    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
df$Ammonium<-as.fixed(df$Ammonium)
df$StirRate<-as.fixed(df$StirRate)
df$Temperature<-as.fixed(df$Temperature)

str(df)
## '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(Density~Ammonium*StirRate*Temperature,data=df)
gad(model)
## $anova
## 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 **
## 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   
## Residuals                      8 31.762   3.970                    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(model)
##                               Df Sum Sq Mean Sq F value  Pr(>F)   
## Ammonium                       1  44.39   44.39  11.180 0.01018 * 
## StirRate                       1  70.69   70.69  17.804 0.00292 **
## Temperature                    1   0.33    0.33   0.083 0.78117   
## Ammonium:StirRate              1  28.12   28.12   7.082 0.02875 * 
## Ammonium:Temperature           1   0.02    0.02   0.005 0.94281   
## StirRate:Temperature           1  10.13   10.13   2.551 0.14889   
## Ammonium:StirRate:Temperature  1   1.52    1.52   0.383 0.55341   
## Residuals                      8  31.76    3.97                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Here P value is higher than 0.05 within all three interractions. We we failed to reject the Null hypothesis. There is no significae in the interraction between three factors.

model1<-aov(Density~Ammonium*Temperature,data=df)
gad(model1)
## $anova
## Analysis of Variance Table
## 
## Response: Density
##                      Df  Sum Sq Mean Sq F value  Pr(>F)  
## Ammonium              1  44.389  44.389  3.7456 0.07686 .
## Temperature           1   0.328   0.328  0.0277 0.87069  
## Ammonium:Temperature  1   0.022   0.022  0.0018 0.96653  
## Residuals            12 142.212  11.851                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(model1)
##                      Df Sum Sq Mean Sq F value Pr(>F)  
## Ammonium              1  44.39   44.39   3.746 0.0769 .
## Temperature           1   0.33    0.33   0.028 0.8707  
## Ammonium:Temperature  1   0.02    0.02   0.002 0.9665  
## Residuals            12 142.21   11.85                 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Here P value is higher than 0.05 within all two interractions(Ammonium & Temperature). so we failed to reject the Null hypothesis. There is no significane in the interraction between these two factors

model2 <- aov(Density~StirRate*Temperature,data=df)
gad(model2)
## $anova
## Analysis of Variance Table
## 
## Response: Density
##                      Df  Sum Sq Mean Sq F value  Pr(>F)  
## StirRate              1  70.686  70.686  8.0167 0.01514 *
## Temperature           1   0.328   0.328  0.0372 0.85034  
## StirRate:Temperature  1  10.128  10.128  1.1487 0.30491  
## Residuals            12 105.809   8.817                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(model2)
##                      Df Sum Sq Mean Sq F value Pr(>F)  
## StirRate              1  70.69   70.69   8.017 0.0151 *
## Temperature           1   0.33    0.33   0.037 0.8503  
## StirRate:Temperature  1  10.13   10.13   1.149 0.3049  
## Residuals            12 105.81    8.82                 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Here P value is higher than 0.05 within all two interractions(StirRate & Temperature). so we failed to reject the Null hypothesis. There is no significane in the interraction between these two factors

model3 <- aov(Density~Ammonium*StirRate,data=df)
gad(model3)
## $anova
## 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 *  
## Residuals         12 43.759   3.647                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(model3)
##                   Df Sum Sq Mean Sq F value   Pr(>F)    
## Ammonium           1  44.39   44.39   12.17 0.004472 ** 
## StirRate           1  70.69   70.69   19.38 0.000861 ***
## Ammonium:StirRate  1  28.12   28.12    7.71 0.016751 *  
## Residuals         12  43.76    3.65                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Here P value is less than 0.05 within two interractions(Ammonium & StirRate). so we can reject the Null hypothesis. There is significant interraction between these two factors

interaction.plot(df$StirRate, df$Ammonium, df$Density, main = "Ammonium vs Stir Rate", ylab="Density")

From the interraction plot , since the lines are not parallel , so we can tell that the interaction between ammonium and StirRate is significant.

Problem 2:

library(agricolae)
## Warning: package 'agricolae' was built under R version 4.4.3
# Define factor levels
A <- c("A1 = Organic compost", "A2 = Chemical fertilizer")
B <- c("B1 = Once per day", "B2 = Twice per day")
C <- c("C1 = 22°C", "C2 = 28°C")

# Create factorial design (2^3) with 3 replications in RCBD
design <- design.ab(trt = c(2, 2, 2), r = 3, design = "rcbd", seed = 123)

# Assign descriptive labels to each factor
design$book$A <- factor(design$book$A, labels = A)
design$book$B <- factor(design$book$B, labels = B)
design$book$C <- factor(design$book$C, labels = C)

# Display output
design$book
##    plots block                        A                  B         C
## 1    101     1 A2 = Chemical fertilizer B2 = Twice per day C1 = 22°C
## 2    102     1     A1 = Organic compost  B1 = Once per day C1 = 22°C
## 3    103     1 A2 = Chemical fertilizer B2 = Twice per day C2 = 28°C
## 4    104     1     A1 = Organic compost B2 = Twice per day C2 = 28°C
## 5    105     1 A2 = Chemical fertilizer  B1 = Once per day C1 = 22°C
## 6    106     1     A1 = Organic compost  B1 = Once per day C2 = 28°C
## 7    107     1 A2 = Chemical fertilizer  B1 = Once per day C2 = 28°C
## 8    108     1     A1 = Organic compost B2 = Twice per day C1 = 22°C
## 9    109     2     A1 = Organic compost B2 = Twice per day C2 = 28°C
## 10   110     2     A1 = Organic compost  B1 = Once per day C2 = 28°C
## 11   111     2 A2 = Chemical fertilizer B2 = Twice per day C2 = 28°C
## 12   112     2 A2 = Chemical fertilizer  B1 = Once per day C1 = 22°C
## 13   113     2 A2 = Chemical fertilizer B2 = Twice per day C1 = 22°C
## 14   114     2     A1 = Organic compost  B1 = Once per day C1 = 22°C
## 15   115     2 A2 = Chemical fertilizer  B1 = Once per day C2 = 28°C
## 16   116     2     A1 = Organic compost B2 = Twice per day C1 = 22°C
## 17   117     3     A1 = Organic compost  B1 = Once per day C1 = 22°C
## 18   118     3 A2 = Chemical fertilizer  B1 = Once per day C1 = 22°C
## 19   119     3 A2 = Chemical fertilizer B2 = Twice per day C1 = 22°C
## 20   120     3     A1 = Organic compost  B1 = Once per day C2 = 28°C
## 21   121     3     A1 = Organic compost B2 = Twice per day C1 = 22°C
## 22   122     3 A2 = Chemical fertilizer B2 = Twice per day C2 = 28°C
## 23   123     3 A2 = Chemical fertilizer  B1 = Once per day C2 = 28°C
## 24   124     3     A1 = Organic compost B2 = Twice per day C2 = 28°C

Complete Code

# Problem 1
library(GAD)

df<-read.csv("https://raw.githubusercontent.com/tmatis12/datafiles/main/PowderProduction.csv")
print(df)
df$Ammonium<-as.fixed(df$Ammonium)
df$StirRate<-as.fixed(df$StirRate)
df$Temperature<-as.fixed(df$Temperature)

str(df)
model<-aov(Density~Ammonium*StirRate*Temperature,data=df)
gad(model)

summary(model)
# model 1
model1<-aov(Density~Ammonium*Temperature,data=df)
gad(model1)

summary(model1)
# model 2
model2 <- aov(Density~StirRate*Temperature,data=df)
gad(model2)

summary(model2)
# model 3
model3 <- aov(Density~Ammonium*StirRate,data=df)
gad(model3)

summary(model3)

# interaction plot
interaction.plot(df$StirRate, df$Ammonium, df$Density, main = "Ammonium vs Stir Rate", ylab="Density")

#Problem 2
library(agricolae)

# Define factor levels
A <- c("A1 = Organic compost", "A2 = Chemical fertilizer")
B <- c("B1 = Once per day", "B2 = Twice per day")
C <- c("C1 = 22°C", "C2 = 28°C")

# Create factorial design (2^3) with 3 replications in RCBD
design <- design.ab(trt = c(2, 2, 2), r = 3, design = "rcbd", seed = 123)

# Assign descriptive labels to each factor
design$book$A <- factor(design$book$A, labels = A)
design$book$B <- factor(design$book$B, labels = B)
design$book$C <- factor(design$book$C, labels = C)

# Display output
design$book