generate_interaction_contrast | R Documentation |
Returns a matrix N_cells × N_contrasts – each row is a design cell,
columns are independent contrasts (difference‑coded for the factors you ask
for, grand‑mean for the rest). Suitable for tcrossprod(dm, C)
or
lm.fit(design, y)
followed by %*% coef
in the usual way.
generate_interaction_contrast(des, factors)
generate_main_effect_contrast(des, factor)
des |
data.frame with one column per factor (must be |
factors |
character vector: which factor(s) get difference coding.
• |
factor |
Single factor name for the main effect. |
numeric matrix nrow = ∏ levels(f) , ncol = ∏ (Lᵢ − 1) for the chosen factors.
des <- expand.grid(Time = factor(1:4),
Cond = factor(c("face","scene")))
# Main effect of Time (4‑1 = 3 contrasts)
M <- generate_main_effect_contrast(des, "Time")
# Full Time×Cond interaction ( (4‑1)*(2‑1) = 3 contrasts )
I <- generate_interaction_contrast(des, c("Time","Cond"))
dim(I) # 8 rows (cells) × 3 columns (contrasts)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.