# Diseño factorial 4 x 3 con 3 réplicas (totales de celda excluidos)
datos <- data.frame(
profundidad = rep(c(0.15, 0.18, 0.21, 0.24), each = 9),
velocidad = rep(rep(c(0.20, 0.25, 0.30), each = 3), times = 4),
replica = rep(1:3, times = 12),
y = c( 74, 64, 60, 92, 86, 88, 99, 98,102, # A = 0.15
79, 68, 73, 98,104, 88, 104, 99, 95, # A = 0.18
82, 88, 92, 99,108, 95, 108,110, 99, # A = 0.21
99,104, 96, 104,110, 99, 114,111,107) # A = 0.24
)
datos$A <- factor(datos$profundidad)
datos$B <- factor(datos$velocidad)
str(datos) # 36 obs.
## 'data.frame': 36 obs. of 6 variables:
## $ profundidad: num 0.15 0.15 0.15 0.15 0.15 0.15 0.15 0.15 0.15 0.18 ...
## $ velocidad : num 0.2 0.2 0.2 0.25 0.25 0.25 0.3 0.3 0.3 0.2 ...
## $ replica : int 1 2 3 1 2 3 1 2 3 1 ...
## $ y : num 74 64 60 92 86 88 99 98 102 79 ...
## $ A : Factor w/ 4 levels "0.15","0.18",..: 1 1 1 1 1 1 1 1 1 2 ...
## $ B : Factor w/ 3 levels "0.2","0.25","0.3": 1 1 1 2 2 2 3 3 3 1 ...
with(datos, tapply(y, list(A, B), sum)) # comprobación vs. totales del cuadro
## 0.2 0.25 0.3
## 0.15 198 266 299
## 0.18 220 290 298
## 0.21 262 302 317
## 0.24 299 313 332
modelo <- aov(y ~ A * B, data = datos)
summary(modelo)
## Df Sum Sq Mean Sq F value Pr(>F)
## A 3 2125.1 708.4 24.663 1.65e-07 ***
## B 2 3160.5 1580.2 55.018 1.09e-09 ***
## A:B 6 557.1 92.8 3.232 0.018 *
## Residuals 24 689.3 28.7
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Supuestos
par(mfrow = c(2, 2)); plot(modelo)

shapiro.test(residuals(modelo))
##
## Shapiro-Wilk normality test
##
## data: residuals(modelo)
## W = 0.97051, p-value = 0.4397
bartlett.test(y ~ interaction(A, B), data = datos)
##
## Bartlett test of homogeneity of variances
##
## data: y by interaction(A, B)
## Bartlett's K-squared = 4.6743, df = 11, p-value = 0.9459
# Gráfico de interacción
with(datos, interaction.plot(B, A, y, type = "b", pch = 19,
xlab = "Velocidad", ylab = "Respuesta media", trace.label = "Profundidad"))
