cmat {hypr} | R Documentation |
Retrieve or set contrast matrix
Description
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.
Usage
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 replacement method for signature 'factor,ANY,hypr'
contrasts(x, how.many = NULL) <- value
## S4 replacement method for signature 'factor,ANY,hypr_cmat'
contrasts(x, how.many = NULL) <- value
contr.hypothesis(
x,
add_intercept = NULL,
remove_intercept = FALSE,
as_fractions = FALSE
) <- value
Arguments
x |
A hypr object |
add_intercept |
Add additional intercept column to contrast matrix |
remove_intercept |
If |
as_fractions |
Should the returned matrix be formatted as fractions (using |
value |
contrast matrix |
... |
A list of hypothesis equations for which to retrieve a contrast matrix |
how.many |
Details
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).
Value
A matrix
of contrast codes with contrasts as columns and levels as rows.
Functions
-
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
References
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
See Also
Examples
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)