The full factorial linear effects model is:
\[ y_{ijkl}=\mu+\alpha_i+\beta_j+\gamma_k+(\alpha\beta)_{ij}+(\alpha\gamma)_{ik}+(\beta\gamma)_{jk}+(\alpha\beta\gamma)_{ijk}+\epsilon_{ijkl} \] where:
\(i,j,k = 1,2\) and \(l = 1,2\)
library(GAD)
dat1<-read.csv("https://raw.githubusercontent.com/tmatis12/datafiles/main/PowderProduction.csv")
names(dat1)
## [1] "Ammonium" "StirRate" "Temperature" "Density"
head(dat1)
## 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
ammonium<-c(rep(c(2,2,30,30),4))
stir<-rep(c(100,100,100,100,150,150,150,150),2)
temp<-c(rep(8,8),rep(40,8))
density<-c(
14.68,15.18,15.12,17.48,
7.54,6.66,12.46,12.62,
10.95,17.68,12.65,15.96,
8.03,8.84,14.96,14.96
)
ammonium<-as.fixed(ammonium)
stir<-as.fixed(stir)
temp<-as.fixed(temp)
model1<-lm(density~ammonium*stir*temp)
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 *
## stir 1 70.686 70.686 17.8037 0.002918 **
## temp 1 0.328 0.328 0.0826 0.781170
## ammonium:stir 1 28.117 28.117 7.0817 0.028754 *
## ammonium:temp 1 0.022 0.022 0.0055 0.942808
## stir:temp 1 10.128 10.128 2.5510 0.148890
## ammonium:stir:temp 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
At \(\alpha=0.05\), Ammonium, stir rate, and the Ammonium:stir rate interaction are significant.
Significant p-values are:
Temperature and the remaining interactions are not significant.
interaction.plot(ammonium,stir,density,
xlab="Ammonium (%)",
ylab="Mean Density",
trace.label="Stir Rate (RPM)")
The interaction plot shows that the effect of stir rate depends on the
Ammonium level. Since the interaction is significant, the two factors
should be interpreted together.
library(GAD)
density2<-c(
570,565,583,
1063,1080,1043,
565,510,590,
528,547,521,
988,1026,1004,
526,538,532
)
position<-rep(c(1,2),each=9)
temperature<-rep(rep(c(800,825,850),each=3),2)
position.f<-as.fixed(position)
temperature.f<-as.fixed(temperature)
model2a<-lm(density2~position.f*temperature.f)
gad(model2a)
## $anova
## Analysis of Variance Table
##
## Response: density2
## Df Sum Sq Mean Sq F value Pr(>F)
## position.f 1 7160 7160 15.998 0.001762 **
## temperature.f 2 945342 472671 1056.117 3.25e-14 ***
## position.f:temperature.f 2 818 409 0.914 0.427110
## Residuals 12 5371 448
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
P-values:
At \(\alpha=0.05\), Position and Temperature are significant, but their interaction is not significant.
position.r<-as.random(position)
temperature.r<-as.random(temperature)
model2b<-lm(density2~position.r*temperature.r)
gad(model2b)
## $anova
## Analysis of Variance Table
##
## Response: density2
## Df Sum Sq Mean Sq F value Pr(>F)
## position.r 1 7160 7160 17.504 0.0526583 .
## temperature.r 2 945342 472671 1155.518 0.0008647 ***
## position.r:temperature.r 2 818 409 0.914 0.4271101
## Residuals 12 5371 448
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
P-values:
-Position: \(p=0.0526583\) -Temperature: \(0.0008647\) -Position:Temperature: \(p=0.427110\)
At \(\alpha=0.05\), Temperature is significant, while Position and the interaction are not significant.
model2c<-lm(density2~position.f*temperature.r)
gad(model2c)
## $anova
## Analysis of Variance Table
##
## Response: density2
## Df Sum Sq Mean Sq F value Pr(>F)
## position.f 1 7160 7160 17.504 0.05266 .
## temperature.r 2 945342 472671 1056.117 3.25e-14 ***
## position.f:temperature.r 2 818 409 0.914 0.42711
## Residuals 12 5371 448
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
P-values:
-Position: \(p=0.05266\) -Temperature: \(p=3.25e-14\) -Position:Temperature: \(p=0.42711\)
At \(\alpha=0.05\), Temperature is significant, while Position and interaction are not significant.
Temperature is significant in all three models, and interaction is not significant in any model.
Position is significant when both factors are fixed, but it is not significant otherwise.
These differences occur because fixed and random effects use different error terms when calculating the F-statistics and p-values.
library(GAD)
dat1<-read.csv("https://raw.githubusercontent.com/tmatis12/datafiles/main/PowderProduction.csv")
names(dat1)
head(dat1)
ammonium<-c(rep(c(2,2,30,30),4))
stir<-rep(c(100,100,100,100,150,150,150,150),2)
temp<-c(rep(8,8),rep(40,8))
density<-c(
14.68,15.18,15.12,17.48,
7.54,6.66,12.46,12.62,
10.95,17.68,12.65,15.96,
8.03,8.84,14.96,14.96
)
ammonium<-as.fixed(ammonium)
stir<-as.fixed(stir)
temp<-as.fixed(temp)
model1<-lm(density~ammonium*stir*temp)
gad(model1)
interaction.plot(ammonium,stir,density,
xlab="Ammonium (%)",
ylab="Mean Density",
trace.label="Stir Rate (RPM)")
library(GAD)
density2<-c(
570,565,583,
1063,1080,1043,
565,510,590,
528,547,521,
988,1026,1004,
526,538,532
)
position<-rep(c(1,2),each=9)
temperature<-rep(rep(c(800,825,850),each=3),2)
position.f<-as.fixed(position)
temperature.f<-as.fixed(temperature)
model2a<-lm(density2~position.f*temperature.f)
gad(model2a)
position.r<-as.random(position)
temperature.r<-as.random(temperature)
model2b<-lm(density2~position.r*temperature.r)
gad(model2b)
model2c<-lm(density2~position.f*temperature.r)
gad(model2c)