add_contrast | R Documentation |
Add a contrast to a data frame
add_contrast(
data,
col,
contrast = c("anova", "sum", "treatment", "helmert", "poly", "difference"),
levels = NULL,
...,
add_cols = TRUE,
colnames = NULL
)
data |
the data frame |
col |
the column to recode |
contrast |
the contrast to recode to |
levels |
the levels of the factor in order |
... |
arguments to pass to the contrast function (base or omit) |
add_cols |
whether to just add the contrast to the existing column or also to create new explicit columns in the dataset (default) |
colnames |
optional list of column names for the added contrasts |
the data frame with the recoded column and added columns (if add_cols == TRUE)
df <- sim_design(between = list(time = 1:6), plot = FALSE) %>%
add_contrast("time", "poly")
# test all polynomial contrasts
lm(y ~ time, df) %>% broom::tidy()
# test only the linear and quadratic contrasts
lm(y ~ `time^1` + `time^2`, df) %>% broom::tidy()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.