Assignment 14 Group4

Problem 1

dat1 <- read.csv("https://raw.githubusercontent.com/tmatis12/datafiles/main/PowderProduction.csv")
colnames(dat1) <- c("Ammonium", "StirRate", "Temperature", "Density")
str(dat1)
## 'data.frame':    16 obs. of  4 variables:
##  $ Ammonium   : int  2 2 30 30 2 2 30 30 2 2 ...
##  $ StirRate   : int  100 100 100 100 150 150 150 150 100 100 ...
##  $ Temperature: int  8 8 8 8 8 8 8 8 40 40 ...
##  $ Density    : num  14.68 15.18 15.12 17.48 7.54 ...

\(\overline{y_{ijk}}=\mu+\alpha_{i}+\beta_{j}+\gamma_{k}+\alpha\beta_{ij}+\alpha\gamma_{ik}+\beta\gamma_{jk}+\alpha\beta\gamma_{ijk}+\epsilon_{ijkl}\)

dat1$Ammonium<-as.factor(dat1$Ammonium)
dat1$StirRate<-as.factor(dat1$StirRate)
model<-aov(Density~Ammonium+StirRate+Temperature+Ammonium*StirRate*Temperature,data=dat1)

summary(model) #note, the summary of the aov gives the same as gad since fixed effects
##                               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

P-value for Ammonium:StirRate:Temperature=0.55341, P-value for StirRate:Temperature=0.14889, P-value for Ammonium:Temperature=0.94281, p-value for Ammonium:StirRate= 0.02875. Compared to critical value=0.05, we Know that Ammonium:StirRate interaction is significant, the rest interactions are not.

we plot the Ammonium:StirRate interaction

Density1 <- c(14.68, 15.18,10.95,17.68)
Density2 <- c(7.54,6.66,8.03,8.84)
Density12 <- c(Density1,Density2)
StirRate1 <- c(rep(100,4),rep(150,4))
plot(StirRate1, Density12,main="Scatterplot with average", xlab="Stir Rate ",ylab="Density", pch=19, col="red")

avg1 <- c(ave(Density1), ave(Density2))

points(StirRate1,avg1,pch = 15,col="red")
abline(lm(avg1 ~ StirRate1), col = "red")

Density3 <- c(15.12,17.48,12.65,15.96)
Density4 <- c(12.46,12.62,14.96,14.96)
Density34 <- c(Density3,Density4)
StirRate1 <- c(rep(100,4),rep(150,4))
points(StirRate1,Density34,pch = 15,col="blue")

avg2 <- c(ave(Density3), ave(Density4))

points(StirRate1,avg2,pch = 15,col="blue")
abline(lm(avg2 ~ StirRate1), col = "blue")

# arrows(StirRate1, avg1, StirRate1, avg1, length=0.05, angle=90, code=3, col="blue")

We can see from the plot that they do have interaction, they are not in parallel.

————————————————————————————————

Problem 2

\(H_{0}\): All row treatments are equal, \(\tau_{i}\) = 0

\(H_{1}\): At least one \(\tau_{i}\) \(\neq\) 0

\(H_{0}\): All column treatments are equal, \(\beta_{j}\) = 0

\(H_{1}\): At least one \(\beta_{j}\) \(\neq\) 0

\(H_{0}\): (\(\tau \beta_{ij}\)) = 0 for all i,j

\(H_{1}\): At least one (\(\tau \beta_{ij}\)) \(\neq\) 0

library(GAD)
## 载入需要的程辑包:matrixStats
## 载入需要的程辑包:R.methodsS3
## R.methodsS3 v1.8.1 (2020-08-26 16:20:06 UTC) successfully loaded. See ?R.methodsS3 for help.
density <- c(570,565,583,528,547,521,1063,1080,1043,988,1026,1004,565,510,590,526,538,532)
temp <- c(rep(800,6),rep(825,6),rep(850,6))
temp <- as.fixed(temp)
position <- c(rep(1,3),rep(2,3),rep(1,3),rep(2,3),rep(1,3),rep(2,3))
position <- as.fixed(position)
data2 <- as.data.frame(cbind(density,temp,position))
data2
##    density temp position
## 1      570    1        1
## 2      565    1        1
## 3      583    1        1
## 4      528    1        2
## 5      547    1        2
## 6      521    1        2
## 7     1063    2        1
## 8     1080    2        1
## 9     1043    2        1
## 10     988    2        2
## 11    1026    2        2
## 12    1004    2        2
## 13     565    3        1
## 14     510    3        1
## 15     590    3        1
## 16     526    3        2
## 17     538    3        2
## 18     532    3        2
model<-aov(density~temp+position+temp*position)
GAD::gad(model)
## Analysis of Variance Table
## 
## Response: density
##               Df Sum Sq Mean Sq  F value   Pr(>F)    
## temp           2 945342  472671 1056.117 3.25e-14 ***
## position       1   7160    7160   15.998 0.001762 ** 
## temp:position  2    818     409    0.914 0.427110    
## Residual      12   5371     448                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
temp <- as.random(temp)
position <- as.random(position)
model<-aov(density~temp+position+temp*position)
GAD::gad(model)
## Analysis of Variance Table
## 
## Response: density
##               Df Sum Sq Mean Sq  F value    Pr(>F)    
## temp           2 945342  472671 1155.518 0.0008647 ***
## position       1   7160    7160   17.504 0.0526583 .  
## temp:position  2    818     409    0.914 0.4271101    
## Residual      12   5371     448                       
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
position <- as.fixed(position)
model<-aov(density~temp+position+temp*position)
GAD::gad(model)
## Analysis of Variance Table
## 
## Response: density
##               Df Sum Sq Mean Sq  F value   Pr(>F)    
## temp           2 945342  472671 1056.117 3.25e-14 ***
## position       1   7160    7160   17.504  0.05266 .  
## temp:position  2    818     409    0.914  0.42711    
## Residual      12   5371     448                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

(a) p-value of temperature is 3.25e-14, p-value of position is 0.001762, p-value of interaction is 0.427110.

(b) p-value of temperature is 0.0008647, p-value of position is 0.0526583, p-value of interaction is 0.4271101.

(c) p-value of temperature is 3.25e-14, p-value of position is 0.05266, p-value of interaction is 0.42711.

(d)

1.The interaction’s p-value remained unchanged, regardless of whether or not the factors were considered fixed, random, or mixed.This strongly implies that the interaction between the two factors is not significant(p-value>0.05). The way we calculate the f-statistics is the same (MSAB/MSE) regardless of whether the factors were considered fixed, random, or mixed.

2. The temperature/position’s p-value was the same when the factors were considered fixed and when the factors were considered mixed. When the factors were considered random, the temperature/position’s p-value increased significantly.