#install.packages("GAD")
library(GAD)
# Chemical in 4 groups of 4
chemical <- c(rep(1,4), rep(2,4), rep(3,4), rep(4,4))
# Bolt runs 1..4 inside each chemical group
bolt <- c(seq(1,4), seq(1,4), seq(1,4), seq(1,4))
# Observations
obs <- c(73,68,74,71,
73,67,75,72,
75,68,78,73,
73,71,75,75)
# Declare fixed/random for GAD
chemical <- as.fixed(chemical) # treatments fixed
bolt <- as.random(bolt) # blocks random
model<- lm(obs ~ chemical+ bolt)
gad(model)
## $anova
## Analysis of Variance Table
##
## Response: obs
## Df Sum Sq Mean Sq F value Pr(>F)
## chemical 3 14.187 4.729 2.7349 0.1057217
## bolt 3 104.188 34.729 20.0843 0.0002515 ***
## Residuals 9 15.563 1.729
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Linear effects model (additive RCBD):
Yij = μ + αi + βj + εij
αi = effect of chemical i (fixed)
βj = effect of bolt j (random)
εij = random error
Hypotheses for chemicals:
H0: α1 = α2 = α3 = α4 = 0
HA: At least one αi ≠ 0
Decision (α = 0.15):
p < 0.15 → Reject H0.
The analysis shows that both the chemical and bolt effects are
significant. This means different chemicals affect cloth strength
differently, and bolts of cloth vary in baseline strength. Blocking by
bolt reduced error variance and improved precision
# Completely Randomized Design (CRD)
chemical <- c(rep(1,4), rep(2,4), rep(3,4), rep(4,4))
obs <- c(
73, 73, 75, 73,
68, 67, 68, 71,
74, 75, 78, 75,
71, 72, 73, 75
)
# Declare factor as fixed BEFORE fitting the model
chemical <- as.fixed(chemical)
# Fit the one-way ANOVA model
model_crd <- lm(obs ~ chemical)
# Now run GAD safely
gad(model_crd)
## $anova
## Analysis of Variance Table
##
## Response: obs
## Df Sum Sq Mean Sq F value Pr(>F)
## chemical 3 104.19 34.729 14.008 0.0003168 ***
## Residuals 12 29.75 2.479
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Model:
Yij = μ + αi + εij
αi = effect of chemical i (fixed)
εij = random error
Hypotheses for chemicals:
H0: α1 = α2 = α3 = α4 = 0
HA: At least one αi ≠ 0
Decision (α = 0.15):
Comments:
The CRD shows that chemical type has a significant effect on cloth
strength. However, without blocking, the residual mean square (error) is
larger (about 2.48), meaning there is more unexplained variation
compared to the RCBD.