1 Problem 1

1.1 Data Import

The data will be imported using the read.csv() function in the code chunk below. Additionally, the factors will be converted to fixed effects.

dat1<-read.csv("https://raw.githubusercontent.com/tmatis12/datafiles/main/PowderProduction.csv")
#install.packages("GAD")
library(GAD)
dat1$Ammonium<-as.fixed(dat1$Ammonium)
dat1$StirRate<-as.fixed(dat1$StirRate)
dat1$Temperature<-as.fixed(dat1$Temperature)

1.2 Model Equation

The model equation for this 2^3 factorial design can be seen in the equation below.

\[ X_{ijkl}=\mu + \alpha_i + \beta_j + \gamma_k + (\alpha\beta)_{ij} + (\alpha\gamma)_{ik} + (\beta\gamma)_{jk} + (\alpha\beta\gamma)_{ijk} + \epsilon_{ijkl} \]

Where \(X_{ijkl}\) is the response variable density, \(\mu\) is the grand mean, \(\alpha_i\) is the effect of Ammonium content, \(\beta_j\) is the effect of the Stir Rate, \(\gamma_k\) is the effect of the Temperature, the different combinations of the main effects are the two and three factor interaction effects, and \(\epsilon_{ijkl}\) is the random error associated with the measurement.

1.3 Factorial Design Analysis

The analysis will be performed using the “GAD” package and can be seen in the code chunk below.

model1<-lm(Density~Ammonium + StirRate + Temperature + Ammonium:StirRate + Ammonium:Temperature + StirRate:Temperature + Ammonium:StirRate:Temperature, data = dat1)
gad(model1)
## $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

Since the three factor interaction has a p-value of 0.553412 and is not significant, it will be removed from the model and analyzed again.

model2<-lm(Density~Ammonium + StirRate + Temperature + Ammonium:StirRate + Ammonium:Temperature + StirRate:Temperature, data = dat1)
gad(model2)
## $anova
## 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 **
## 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   
## Residuals             9 33.281   3.698                    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Since the Ammonium & Temperature two factor interaction has a p-value of 0.940538 and is the least significant, it will be removed from the model and analyzed again.

model3<-lm(Density~Ammonium + StirRate + Temperature + Ammonium:StirRate + StirRate:Temperature, data = dat1)
gad(model3)
## $anova
## 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 ***
## Temperature           1  0.328   0.328  0.0984 0.7601850    
## Ammonium:StirRate     1 28.117  28.117  8.4426 0.0156821 *  
## StirRate:Temperature  1 10.128  10.128  3.0412 0.1117751    
## Residuals            10 33.303   3.330                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Since the Stir Rate & Temperature two factor interaction has a p-value of 0.1117751 and is the least significant, it will be removed from the model and analyzed again.

model4<-lm(Density~Ammonium + StirRate + Temperature + Ammonium:StirRate, data = dat1)
gad(model4)
## $anova
## 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 **
## Temperature        1  0.328   0.328  0.0830 0.778613   
## Ammonium:StirRate  1 28.117  28.117  7.1211 0.021851 * 
## Residuals         11 43.431   3.948                    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Since Temperature is the only remaining factor that is not significant with a p-value of 0.778613, it will be removed from the model and analyzed again.

model5<-lm(Density~Ammonium + StirRate + Ammonium:StirRate, data = dat1)
gad(model5)
## $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

The gad(model5) function returned a p-value of 0.0167511 for the interaction effect between the Ammonium content and the Stir Rate. Since we are using a significance level of 0.05, this interaction between the two factors is deemed significant. An interaction plot will now be generated between the two interacting factors in the code chunk below.

interaction.plot(dat1$StirRate, dat1$Ammonium, dat1$Density, main = "Interaction Plot Between Ammonium Content and Stir Rate", xlab = "Stir Rate", ylab = "Density", trace.label = "Ammonium Content")

As seen in the plot, the slopes of the two Ammonium levels differ significantly. For 2% Ammonium, the Stir Rate significantly effects the measured density of the powder, whereas the Stir Rate for 30% Ammonium has a minimal effect comparatively. It appears a crossover point might occur around a Stir Rate of 90 RPM where the 2% Ammonium would actually have a higher density than the 30% Ammonium.

2 Problem 2

2.1 Experimental Design Layout

A 2^3 factorial design will be set up to see how three factors affect tomato yield in a greenhouse environment. These three factors are Fertilizer Type, Irrigation Frequency, and Temperature Setting. Eight observations of this design will capture a full replication and three replications are desired for a total of 24 observations. This design will also feature a randomized complete block design where the blocks represent differences among greenhouse benches. The layout of this design can be generated using the design.ab() function. This can be seen in the code chunk below.

#install.packages("agricolae")
library(agricolae)
design1<-design.ab(trt = c(2, 2, 2), r = 3, serie = 1, design = c("rcbd"), seed = 825)
design1$book
##    plots block A B C
## 1     11     1 1 1 2
## 2     12     1 1 1 1
## 3     13     1 2 2 2
## 4     14     1 2 2 1
## 5     15     1 2 1 2
## 6     16     1 1 2 2
## 7     17     1 1 2 1
## 8     18     1 2 1 1
## 9     19     2 2 1 2
## 10    20     2 2 2 2
## 11    21     2 2 2 1
## 12    22     2 2 1 1
## 13    23     2 1 2 2
## 14    24     2 1 1 2
## 15    25     2 1 2 1
## 16    26     2 1 1 1
## 17    27     3 1 1 1
## 18    28     3 2 2 1
## 19    29     3 1 2 1
## 20    30     3 2 1 2
## 21    31     3 2 2 2
## 22    32     3 1 2 2
## 23    33     3 2 1 1
## 24    34     3 1 1 2

3 Complete R Code

# Problem 1

## Data Import
dat1<-read.csv("https://raw.githubusercontent.com/tmatis12/datafiles/main/PowderProduction.csv")
#install.packages("GAD")
library(GAD)
dat1$Ammonium<-as.fixed(dat1$Ammonium)
dat1$StirRate<-as.fixed(dat1$StirRate)
dat1$Temperature<-as.fixed(dat1$Temperature)

## Factorial Design Analysis
model1<-lm(Density~Ammonium + StirRate + Temperature + Ammonium:StirRate + Ammonium:Temperature + StirRate:Temperature + Ammonium:StirRate:Temperature, data = dat1)
gad(model1)

model2<-lm(Density~Ammonium + StirRate + Temperature + Ammonium:StirRate + Ammonium:Temperature + StirRate:Temperature, data = dat1)
gad(model2)

model3<-lm(Density~Ammonium + StirRate + Temperature + Ammonium:StirRate + StirRate:Temperature, data = dat1)
gad(model3)

model4<-lm(Density~Ammonium + StirRate + Temperature + Ammonium:StirRate, data = dat1)
gad(model4)

model5<-lm(Density~Ammonium + StirRate + Ammonium:StirRate, data = dat1)
gad(model5)

interaction.plot(dat1$StirRate, dat1$Ammonium, dat1$Density, main = "Interaction Plot Between Ammonium Content and Stir Rate", xlab = "Stir Rate", ylab = "Density", trace.label = "Ammonium Content")

# Problem 2

## Experimental Design Layout
#install.packages("agricolae")
library(agricolae)
design1<-design.ab(trt = c(2, 2, 2), r = 3, serie = 1, design = c("rcbd"), seed = 825)
design1$book