library(GAD)
## Loading required package: matrixStats
## Loading required package: R.methodsS3
## R.methodsS3 v1.8.1 (2020-08-26 16:20:06 UTC) successfully loaded. See ?R.methodsS3 for help.
dat<-read.csv("https://raw.githubusercontent.com/tmatis12/datafiles/main/PowderProduction.csv")
dat$Ammonium<-as.fixed(dat$Ammonium)
dat$StirRate<-as.fixed(dat$StirRate)
dat$Temperature<-as.fixed(dat$Temperature)
str(dat)
## '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 ...
Ho: \(\alpha \beta_{ij} = 0\) - Null Hypothesis
Ha: \(\alpha \beta_{ij} \ne 0\) - Alternative Hypothesis
Ho: \(\alpha_{i} = 0\) - Null Hypothesis
Ha: \(\alpha_{i} \ne 0\) - Alternative Hypothesis
Ho: \(\gamma_{j} = 0\) - Null Hypothesis
Ha: \(\gamma_{j} \ne 0\) - Alternative Hypothesis
Ho: \(\alpha \beta_{ij} = 0\) - Null Hypothesis
Ha: \(\alpha \beta_{ij} \ne 0\) - Alternative Hypothesis
Ho: \(\alpha \gamma_{ik}} = 0\) - Null Hypothesis
Ha: \(\alpha \gamma_{ik} \ne 0\) - Alternative Hypothesis
Ho: \(\beta \gamma_{jk} = 0\) - Null Hypothesis
Ha: \(\beta \gamma_{jk}} \ne 0\) - Alternative Hypothesis
Ho: \(\alpha \beta \gamma_{ijk} = 0\) - Null Hypothesis
Ha: \(\alpha \beta \gamma_{ijk} \ne 0\) - Alternative Hypothesis
\(\alpha\) = 0.05
Model Equation
\(y_{ijkl} = \mu + \alpha_{i} + \beta_j + \gamma_k + \alpha \beta_{ij} +\alpha \gamma_{ik} +\beta \gamma_{jk} +\alpha \beta \gamma_{ijk} + \epsilon_{ijkl}\)
model<-aov(Density~Ammonium+StirRate+Temperature+Ammonium*StirRate+Ammonium*Temperature+StirRate*Temperature
+Ammonium*StirRate*Temperature, data = dat)
gad(model)
## 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
## Residual 8 31.762 3.970
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Testing 3 factor Interaction hypothesis
Ho: \(\alpha \beta \gamma_{ijk} = 0\) - Null Hypothesis
Ha: \(\alpha \beta \gamma_{ijk} \ne 0\) - Alternative Hypothesis
From the result /fo/ is 0.3826 with a correspondingp-value of 0.553412 > \(\alpha\) = 0.05. Hence we fail to reject Ho hypothesis
Model Equation
\(y_{ijkl} = \mu + \alpha_{i} + \beta_j + \gamma_k + \alpha \beta_{ij} +\alpha \gamma_{ik} +\beta \gamma_{jk} + \epsilon_{ijkl}\)
model2<-aov(Density~Ammonium+StirRate+Temperature+Ammonium*StirRate+Ammonium*Temperature+StirRate*Temperature, 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 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
## Residual 9 33.281 3.698
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
We dropped the non significant factors
Ammonium:Temperature StirRate:Temperature
\(y_{ijkl} = \mu + \alpha_{i} + \beta_j + \gamma_k + \alpha \beta_{ij} + \epsilon_{ijkl}\)
model3<-aov(Density~Ammonium+StirRate+Temperature+Ammonium*StirRate, data = dat)
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 **
## Temperature 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
From the result /fo/ is 7.1211 with a correspondingp-value of 0.021851 < \(\alpha\) = 0.05. Hence we reject Ho hypothesis
These factors are significant Ammonium - 0.006443 < 0.05 Stirrate - 0.001410 < 0.05 Ammonium:StirRate - 0.021851 < 0.05
interaction.plot(dat$Ammonium, dat$StirRate, dat$Density, type = "l",col = 1:4 ,main ="Interraction Plot")
library(GAD)
temp<-rep(seq(1,3),6)
pos<-c(rep(1,9),rep(2,9))
response<-c(570,1063,565,565,1080,510,583,1043,590,528,988,526,547,1026,538,521,1004,532)
data.frame(temp,pos,response)
## temp pos response
## 1 1 1 570
## 2 2 1 1063
## 3 3 1 565
## 4 1 1 565
## 5 2 1 1080
## 6 3 1 510
## 7 1 1 583
## 8 2 1 1043
## 9 3 1 590
## 10 1 2 528
## 11 2 2 988
## 12 3 2 526
## 13 1 2 547
## 14 2 2 1026
## 15 3 2 538
## 16 1 2 521
## 17 2 2 1004
## 18 3 2 532
temp<-as.fixed(temp)
pos<-as.fixed(pos)
model4<-aov(response~temp+pos+temp*pos)
#GAD::gad(model4)
gad(model4)
## Analysis of Variance Table
##
## Response: response
## Df Sum Sq Mean Sq F value Pr(>F)
## temp 2 945342 472671 1056.117 3.25e-14 ***
## pos 1 7160 7160 15.998 0.001762 **
## temp:pos 2 818 409 0.914 0.427110
## Residual 12 5371 448
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
temp p-value of 3.25e-14 pos p-value of 0.001762 temp:pos p-value of 0.427110
temp<-as.random(temp)
pos<-as.random(pos)
model5<-aov(response~temp+pos+temp:pos)
#GAD::gad(model5)
gad(model5)
## Analysis of Variance Table
##
## Response: response
## Df Sum Sq Mean Sq F value Pr(>F)
## temp 2 945342 472671 1155.518 0.0008647 ***
## pos 1 7160 7160 17.504 0.0526583 .
## temp:pos 2 818 409 0.914 0.4271101
## Residual 12 5371 448
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
temp p-value of 0.0008647 pos p-value of 0.0526583 temp:pos p-value of 0.4271101
temp<-as.random(temp)
pos<-as.fixed(pos)
model6<-aov(response~temp+pos+pos*temp)
#GAD::gad(model6)
gad(model6)
## Analysis of Variance Table
##
## Response: response
## Df Sum Sq Mean Sq F value Pr(>F)
## temp 2 945342 472671 1056.117 3.25e-14 ***
## pos 1 7160 7160 17.504 0.05266 .
## temp:pos 2 818 409 0.914 0.42711
## Residual 12 5371 448
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
temp p-value of 3.25e-14 pos p-value of 0.05266 temp:pos p-value of 0.42711
Question 2d
From the results of P-values the temp:pos interaction does not change with random or fixed effects. The P-value of temperature is lower if both the factors are fixed. The P-value of pos is lower if both the factors are fixed but its higher when the factors are random effects However when effects model is mixed pos is remains the same and interaction remains same in all situations
library(GAD)
dat<-read.csv("https://raw.githubusercontent.com/tmatis12/datafiles/main/PowderProduction.csv")
dat$Ammonium<-as.fixed(dat$Ammonium)
dat$StirRate<-as.fixed(dat$StirRate)
dat$Temperature<-as.fixed(dat$Temperature)
str(dat)
model<-aov(Density~Ammonium+StirRate+Temperature+Ammonium*StirRate+Ammonium*Temperature+StirRate*Temperature
+Ammonium*StirRate*Temperature, data = dat)
gad(model)
model2<-aov(Density~Ammonium+StirRate+Temperature+Ammonium*StirRate+Ammonium*Temperature+StirRate*Temperature, data = dat)
gad(model2)
model3<-aov(Density~Ammonium+StirRate+Temperature+Ammonium*StirRate, data = dat)
gad(model3)
interaction.plot(dat$Ammonium, dat$StirRate, dat$Temperature, dat$Density, type = "l",col = 1:4, trace.label = , ylab = ,xlab = ,main ="Interraction Plot")
library(GAD)
temp<-rep(seq(1,3),6)
pos<-c(rep(1,9),rep(2,9))
response<-c(570,1063,565,565,1080,510,583,1043,590,528,988,526,547,1026,538,521,1004,532)
data.frame(temp,pos,response)
temp<-as.fixed(temp)
pos<-as.fixed(pos)
model4<-aov(response~temp+pos+temp*pos)
#GAD::gad(model4)
gad(model4)
temp<-as.random(temp)
pos<-as.random(pos)
model5<-aov(response~temp+pos+temp:pos)
#GAD::gad(model5)
gad(model5)
temp<-as.random(temp)
pos<-as.fixed(pos)
model6<-aov(response~temp+pos+pos*temp)
#GAD::gad(model6)
gad(model6)