\(y_{ijkl} = \mu + \tau_i + \beta_j + \gamma_k + (\tau\beta)_{ij} + (\tau\gamma)_{ik} + (\beta\gamma)_{jk} + (\tau\beta\gamma)_{ijk} + \varepsilon_{ijkl}\)
μ (mu): The overall mean response — represents the grand average of all observations in the experiment.
τᵢ (tau): The main effect of Factor A (e.g., Ammonium %). It shows how the mean response changes when Factor A changes from its low to high level, averaged across all other factors.
βⱼ (beta): The main effect of Factor B (e.g., Stir Rate). It measures how the mean response changes with the different levels of Stir Rate, averaged across all other factors.
γₖ (gamma): The main effect of Factor C (e.g., Temperature). It indicates how changes in Temperature affect the mean response, averaged across all other factors.
(τβ)ᵢⱼ: The two-factor interaction between Factors A and B. It shows whether the effect of Ammonium % depends on the level of Stir Rate (and vice versa).
(τγ)ᵢₖ: The two-factor interaction between Factors A and C. It shows whether the effect of Ammonium % depends on Temperature.
(βγ)ⱼₖ: The two-factor interaction between Factors B and C. It captures whether the effect of Stir Rate depends on Temperature.
(τβγ)ᵢⱼₖ: The three-factor interaction among Factors A, B, and C. It indicates whether the combined effect of any two factors changes depending on the level of the third factor. εᵢⱼₖₗ (epsilon): The random error term — accounts for variability not explained by the factors or their interactions. It represents random experimental noise.
library(GAD)
read.csv("https://raw.githubusercontent.com/tmatis12/datafiles/main/PowderProduction.csv")
## 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<-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
Given alpha=0.05,
The P-Value of Ammonium is 0.01018
The P-Value of StirRate is 0.00292
The P-Value of Ammonoium * StirRate is 0.02875
These values are significant because they are quite similar to alpha, 0.05.
The temperature is not significant because the P-Value is greater than the given alpha, so we need to drop the temperature.
interaction.plot(df$StirRate, df$Ammonium, df$Density, main = "Ammonium vs Stir Rate", ylab="Density")
interaction.plot(df$Temperature, df$Ammonium, df$Density, main = "Ammonium vs Temperature", ylab="Density")
interaction.plot(df$Temperature, df$StirRate, df$Density, main = "Stir Rate vs Temperature", ylab="Density")
From these 3 plots, we can see that the ammonium and StirRate are significant because they are close to alpha, 0.05.
library(agricolae)
set.seed(12345)
trt <- c(2, 2, 2)
r <- 3
outdesign <- design.ab(trt, r = r, design = "rcbd", serie = 2)
book <- outdesign$book
print(names(book))
## [1] "plots" "block" "A" "B" "C"
if ("X1" %in% names(book)) {
names(book)[names(book) == "X1"] <- "Fertilizer_Type"
names(book)[names(book) == "X2"] <- "Irrigation_Frequency"
names(book)[names(book) == "X3"] <- "Temperature_Setting"
} else if ("A" %in% names(book)) {
names(book)[names(book) == "A"] <- "Fertilizer_Type"
names(book)[names(book) == "B"] <- "Irrigation_Frequency"
names(book)[names(book) == "C"] <- "Temperature_Setting"
}
names(book)[names(book) == "block"] <- "Block"
names(book)[names(book) == "plots"] <- "Plot"
book$Fertilizer_Type <- factor(book$Fertilizer_Type,
labels = c("Organic compost", "Chemical fertilizer"))
book$Irrigation_Frequency <- factor(book$Irrigation_Frequency,
labels = c("Once per day", "Twice per day"))
book$Temperature_Setting <- factor(book$Temperature_Setting,
labels = c("22°C", "28°C"))
print(book)
## Plot Block Fertilizer_Type Irrigation_Frequency Temperature_Setting
## 1 101 1 Chemical fertilizer Once per day 22°C
## 2 102 1 Chemical fertilizer Once per day 28°C
## 3 103 1 Organic compost Once per day 22°C
## 4 104 1 Organic compost Once per day 28°C
## 5 105 1 Chemical fertilizer Twice per day 22°C
## 6 106 1 Chemical fertilizer Twice per day 28°C
## 7 107 1 Organic compost Twice per day 28°C
## 8 108 1 Organic compost Twice per day 22°C
## 9 109 2 Chemical fertilizer Once per day 22°C
## 10 110 2 Organic compost Once per day 28°C
## 11 111 2 Organic compost Twice per day 28°C
## 12 112 2 Organic compost Once per day 22°C
## 13 113 2 Chemical fertilizer Twice per day 22°C
## 14 114 2 Chemical fertilizer Once per day 28°C
## 15 115 2 Organic compost Twice per day 22°C
## 16 116 2 Chemical fertilizer Twice per day 28°C
## 17 117 3 Chemical fertilizer Twice per day 28°C
## 18 118 3 Organic compost Once per day 22°C
## 19 119 3 Organic compost Once per day 28°C
## 20 120 3 Chemical fertilizer Twice per day 22°C
## 21 121 3 Organic compost Twice per day 28°C
## 22 122 3 Chemical fertilizer Once per day 22°C
## 23 123 3 Organic compost Twice per day 22°C
## 24 124 3 Chemical fertilizer Once per day 28°C
``
Question 1:
library(GAD)
read.csv("https://raw.githubusercontent.com/tmatis12/datafiles/main/PowderProduction.csv")
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)
interaction.plot(df$StirRate, df$Ammonium, df$Density, main = "Ammonium vs Stir Rate", ylab="Density")
interaction.plot(df$Temperature, df$Ammonium, df$Density, main = "Ammonium vs Temperature", ylab="Density")
interaction.plot(df$Temperature, df$StirRate, df$Density, main = "Stir Rate vs Temperature", ylab="Density")
Question 2:
library(agricolae)
set.seed(12345)
trt <- c(2, 2, 2)
r <- 3
outdesign <- design.ab(trt, r = r, design = "rcbd", serie = 2)
book <- outdesign$book
print(names(book))
if ("X1" %in% names(book)) {
names(book)[names(book) == "X1"] <- "Fertilizer_Type"
names(book)[names(book) == "X2"] <- "Irrigation_Frequency"
names(book)[names(book) == "X3"] <- "Temperature_Setting"
} else if ("A" %in% names(book)) {
names(book)[names(book) == "A"] <- "Fertilizer_Type"
names(book)[names(book) == "B"] <- "Irrigation_Frequency"
names(book)[names(book) == "C"] <- "Temperature_Setting"
}
names(book)[names(book) == "block"] <- "Block"
names(book)[names(book) == "plots"] <- "Plot"
book$Fertilizer_Type <- factor(book$Fertilizer_Type,
labels = c("Organic compost", "Chemical fertilizer"))
book$Irrigation_Frequency <- factor(book$Irrigation_Frequency,
labels = c("Once per day", "Twice per day"))
book$Temperature_Setting <- factor(book$Temperature_Setting,
labels = c("22°C", "28°C"))
print(book)
```