View source: R/contrast_weights.R
contrast_weights | R Documentation |
To be used ideally with emmeans::contrast. Each contrasts is tested (sum to 0?) and scaled so that all positive weights sum to 1 (and all negative weights to -1).
contrast_weights(..., .name = "custom", .adjust = NULL)
cw(..., .name = "custom", .adjust = NULL)
... |
Can be:
|
.name |
The label as it will appear in the results in |
.adjust |
Gives the default adjustment method for multiplicity (used in
|
Depending on input, either a vector or a data frame of scaled weights.
data(mtcars)
mod <- lm(mpg ~ factor(cyl) * am, mtcars)
my_contrasts <- data.frame(
"squares" = c(-1, 2, -1),
"4 vs 6" = c(-30, 30, 0),
check.names = FALSE
)
(my_contrasts2 <- cw(my_contrasts))
my_contrasts3 <- cw(my_contrasts, .adjust = "fdr")
library(emmeans)
(emms <- emmeans(mod, ~ cyl + am))
contrast(emms, method = my_contrasts, by = "am")
contrast(emms, method = my_contrasts2, by = "am") # estimate is affected!
contrast(emms, method = my_contrasts3, by = "am") # p value is affected
# Also in interaction contrasts
contrast(emms, interaction = list(cyl = my_contrasts2, am = "pairwise"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.