
a. Full factorial model equation.\[\begin{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}\end{equation}\]
b. Ammonium and Stir Rate are significant using p < α=0.05 with p-values of 0.01018 and 0.00292 respectively. The interaction between the Ammonium and Stir Rate has a significant p-value of 0.02875 but the interaction plot does not cross. The only plot that has an interaction plot that crosses is the interaction between Temperature and Stir Rate but it does not have a p-value that is significant.
dat <- data.frame(
Ammonium = c(2, 2, 30, 30, 2, 2, 30, 30, 2, 2, 30, 30, 2, 2, 30, 30),
StirRate = c(100, 100, 100, 100, 150, 150, 150, 150, 100, 100, 100, 100, 150, 150, 150, 150),
Temperature = c(8, 8, 8, 8, 8, 8, 8, 8, 40, 40, 40, 40, 40, 40, 40, 40),
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))
dat$Ammonium <- as.factor(dat$Ammonium)
dat$StirRate <- as.factor(dat$StirRate)
dat$Temperature <- as.factor(dat$Temperature)
aovmodel <- aov(Density ~ Ammonium * StirRate * Temperature, data = dat)
summary(aovmodel)
## 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
# Interaction plot: Ammonium and Stir Rate
interaction.plot(dat$Ammonium, dat$StirRate, dat$Density,
col = c("red", "blue"), lty = 1:2,
main = "Interaction: Ammonium and Stir Rate")
# Interaction plot: Temperature and Ammonium
interaction.plot(dat$Temperature, dat$Ammonium, dat$Density,
col = c("green", "purple"), lty = 1:2,
main = "Interaction: Temperature and Ammonium")
# Interaction plot: Stir Rate and Temperature
interaction.plot(dat$StirRate, dat$Temperature, dat$Density,
col = c("orange", "cyan"), lty = 1:2,
main = "Interaction: Stir Rate and Temperature")
a. Both Fixed: Temperature and Position have significant p-values. Temperature: p=3.25e-14, Position: p=0.00176, Interaction: p=0.42711
b. Both Random: Temperature and Position have significant p-values. Temperature: p=5.269e-16, Position: p=0.00549, Interaction: p=0.0466.
c. Position Fixed and Temperature Random: Temperature and Position have significant p-values. Temperature: p=9.755e-16, Position: p=0.00125, Interaction: p=0.04580.
d. Honestly, the significance of the effects didn’t change whether the effects were random or not except for the interaction. I can’t tell if this is because of an error of mine or if there is only a minor change in the p-values when the type of effect is changed. All of the effects remained significant using a significance factor of p < α=0.05. However the interaction between temperature and position was insignificant when both effects were fixed but was significant when both were random and temperature was random.
# Create the data
dat <- data.frame(
Position = as.factor(c(1, 1, 1, 2, 2, 2, 1, 1, 1, 2, 2, 2, 1, 1, 1, 2, 2, 2)),
Temperature = as.factor(c(800, 800, 800, 800, 800, 800,
825, 825, 825, 825, 825, 825,
850, 850, 850, 850, 850, 850)),
Density = c(570, 565, 583, 528, 547, 521,
1063, 1080, 1043, 988, 1026, 1004,
565, 510, 590, 526, 538, 532)
)
#a. Both Fixed:
faovmodel <- aov(Density ~ Temperature * Position, data = dat)
summary(aovmodel)
## 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
#b. Both Random: - Note: I could not get as.random to work
library(lme4)
## Loading required package: Matrix
library(lmerTest)
##
## Attaching package: 'lmerTest'
## The following object is masked from 'package:lme4':
##
## lmer
## The following object is masked from 'package:stats':
##
## step
raovmodel <- lmer(Density ~ 1 + (1 | Temperature) + (1 | Position), data = dat)
summary(raovmodel)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: Density ~ 1 + (1 | Temperature) + (1 | Position)
## Data: dat
##
## REML criterion at convergence: 171.4
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -2.49077 -0.40932 0.08772 0.55213 1.31420
##
## Random effects:
## Groups Name Variance Std.Dev.
## Temperature (Intercept) 78704.9 280.54
## Position (Intercept) 746.4 27.32
## Residual 442.1 21.03
## Number of obs: 18, groups: Temperature, 3; Position, 2
##
## Fixed effects:
## Estimate Std. Error df t value Pr(>|t|)
## (Intercept) 709.944 163.195 2.056 4.35 0.0466 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
ranova(raovmodel)
## boundary (singular) fit: see help('isSingular')
## ANOVA-like table for random-effects: Single term deletions
##
## Model:
## Density ~ (1 | Temperature) + (1 | Position)
## npar logLik AIC LRT Df Pr(>Chisq)
## <none> 4 -85.711 179.42
## (1 | Temperature) 3 -118.558 243.12 65.693 1 5.269e-16 ***
## (1 | Position) 3 -89.567 185.13 7.711 1 0.00549 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#c. Mixed Effects: Position fixed and Temperature random
maovmodel <- lmer(Density ~ Position + (1 | Temperature), data = dat)
summary(maovmodel)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: Density ~ Position + (1 | Temperature)
## Data: dat
##
## REML criterion at convergence: 161.2
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -2.54934 -0.43618 0.08772 0.56263 1.25564
##
## Random effects:
## Groups Name Variance Std.Dev.
## Temperature (Intercept) 78704.8 280.54
## Residual 442.1 21.03
## Number of obs: 18, groups: Temperature, 3
##
## Fixed effects:
## Estimate Std. Error df t value Pr(>|t|)
## (Intercept) 729.889 162.124 2.004 4.502 0.04580 *
## Position2 -39.889 9.911 14.000 -4.025 0.00125 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr)
## Position2 -0.031
ranova(maovmodel)
## ANOVA-like table for random-effects: Single term deletions
##
## Model:
## Density ~ Position + (1 | Temperature)
## npar logLik AIC LRT Df Pr(>Chisq)
## <none> 4 -80.606 169.21
## (1 | Temperature) 3 -112.846 231.69 64.479 1 9.755e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1