Skip to contents

Latin-square three-way ANOVA (row, col, treatment)

Usage

mrm_latin_square(data, response_col, row_col, col_col, treatment_col)

Arguments

data

data.frame.

response_col, row_col, col_col, treatment_col

Column names.

Value

Named list with anova, n, k, interpretation.

Examples

# 4 x 4 Latin square: each treatment appears once per row and column.
# `mrm_random_latin()` returns integer codes 0..k-1; convert to
# letters for a more readable example.
sq <- mrm_random_latin(k = 4, seed = 2026)
df <- expand.grid(row = paste0("R", 1:4), col = paste0("C", 1:4))
df$treatment <- LETTERS[as.integer(as.vector(sq)) + 1L]
set.seed(2026)
df$y <- match(df$treatment, LETTERS) * 1.5 + rnorm(16, 0, 0.4)
res <- mrm_latin_square(df,
  response_col = "y",
  row_col = "row", col_col = "col",
  treatment_col = "treatment"
)
res$anova
#>   Df     Sum Sq    Mean Sq    F value       Pr(>F)    source
#> 1  3  0.5168711  0.1722904   1.287169 3.612711e-01       row
#> 2  3  0.4462810  0.1487603   1.111377 4.152822e-01       col
#> 3  3 52.1961828 17.3987276 129.984601 7.568081e-06 treatment
#> 4  6  0.8031133  0.1338522         NA           NA Residuals