Use these functions to retrieve or set a hypr object’s contrast matrix. If used for updating, the hypothesis matrix and equations are derived automatically.
cmat(x, add_intercept = FALSE, remove_intercept = FALSE, as_fractions = TRUE)cmat(x, add_intercept = FALSE, remove_intercept = FALSE) <- value
contr.hypothesis(
...,
add_intercept = FALSE,
remove_intercept = NULL,
as_fractions = FALSE
)
# S4 method for factor,ANY,hypr
contrasts(x, how.many = NULL) <- value
# S4 method for factor,ANY,hypr_cmat
contrasts(x, how.many = NULL) <- value
contr.hypothesis(
x,
add_intercept = NULL,
remove_intercept = FALSE,
as_fractions = FALSE
) <- value
A matrix of contrast codes with contrasts as columns and levels as rows.
A hypr object
Add additional intercept column to contrast matrix
If TRUE, tries to find an intercept column (all codes equal) and removes it from the matrix. If NULL, does the same but does not throw an exception if no intercept is found. FALSE explicitly disables this functionality. A numeric argument explicitly identifies the index of the column to be removed.
Should the returned matrix be formatted as fractions (using MASS::as.fractions())?
contrast matrix
A list of hypothesis equations for which to retrieve a contrast matrix
cmat(x, add_intercept = FALSE, remove_intercept = FALSE) <- value: Set contrast matrix
contr.hypothesis(): Retrieve contrast matrix with sensible intercept default to override factor contrasts
contrasts(x = factor, how.many = ANY) <- value: Update factor contrasts
contrasts(x = factor, how.many = ANY) <- value: Update factor contrasts
contr.hypothesis(
x,
add_intercept = NULL,
remove_intercept = FALSE,
as_fractions = FALSE
) <- value: Update contrast matrix with sensible intercept default
Basic specification of contrasts in R is accomplished with basic R functions stats::contrasts() and stats::C() (Chambers & Hastie, 1992). Other relevant packages for this topic are multcomp (Bretz et al., 2010), contrast (Kuhn et al., 2016), and, including also various vignettes, emmeans (Lenth, 2019).
Chambers, J. M. and Hastie, T. J. (1992) Statistical models. Chapter 2 of Statistical Models in S eds J. M. Chambers and T. J. Hastie, Wadsworth & Brooks/Cole.
Frank Bretz, Torsten Hothorn and Peter Westfall (2010), Multiple Comparisons Using R, CRC Press, Boca Raton.
Max Kuhn, contributions from Steve Weston, Jed Wing, James Forester and Thorn Thaler (2016). contrast: A Collection of Contrast Methods. R package version 0.21. https://CRAN.R-project.org/package=contrast
Lenth, R. (2019). emmeans: Estimated Marginal Means, aka Least-Squares Means. R package version 1.4.1. https://CRAN.R-project.org/package=emmeans
hypr
h <- hypr(mu1~0, mu2~mu1)
cmat(h) # retrieve the contrast matrix
contr.hypothesis(h) # by default without intercept (removes first column)
contr.hypothesis(mu1~0, mu2~mu1)
Run the code above in your browser using DataLab