Title: | Hypothesis Matrix Translation |
---|---|
Description: | Translation between experimental null hypotheses, hypothesis matrices, and contrast matrices as used in linear regression models. The package is based on the method described in Schad et al. (2019) <doi:10.1016/j.jml.2019.104038> and Rabe et al. (2020) <doi:10.21105/joss.02134>. |
Authors: | Maximilian M. Rabe [aut, cre] |
Maintainer: | Maximilian M. Rabe <[email protected]> |
License: | GPL-3 |
Version: | 0.2.8 |
Built: | 2025-03-03 03:32:43 UTC |
Source: | https://github.com/mmrabe/hypr |
You can combine one or more hypr
objects, i.e. combine their hypothesis to a single hypr
object, by adding them with the +
or \*
operators.
## S4 method for signature 'hypr,hypr' e1 + e2 ## S4 method for signature 'hypr,hypr' e1 * e2 ## S4 method for signature 'hypr,hypr' e1 & e2 ## S4 method for signature 'hypr,hypr' e1 / e2
## S4 method for signature 'hypr,hypr' e1 + e2 ## S4 method for signature 'hypr,hypr' e1 * e2 ## S4 method for signature 'hypr,hypr' e1 & e2 ## S4 method for signature 'hypr,hypr' e1 / e2
e1 , e2
|
|
The combined hypr
object
e1 * e2
: Interaction of e1
and e2
e1 & e2
: Interaction and main contrasts of e1
and e2
e1 / e2
: Nesting levels of e2
within e1
(h1 <- hypr(a~i, b~i)) # a hypr object of two treatments (h2 <- hypr(i~0)) # an intercept-only hypr object hc <- h1 + h2 hc interaction <- h1 & h2 interaction_and_main <- h1 * h2
(h1 <- hypr(a~i, b~i)) # a hypr object of two treatments (h2 <- hypr(i~0)) # an intercept-only hypr object hc <- h1 + h2 hc interaction <- h1 & h2 interaction_and_main <- h1 * h2
Non-centered contrasts require an intercept for correct specification of experimental hypotheses. These functions enable the user to check for existance of intercepts and to add or remove intercept columns as needed.
add_intercept(x) remove_intercept(x) is_intercept(x) which_intercept(x) has_intercept(x)
add_intercept(x) remove_intercept(x) is_intercept(x) which_intercept(x) has_intercept(x)
x |
A hypr object |
There are functions available to check whether a hypr
object contains an intercept (has_intercept
) or which contrast is the intercept (is_intercept
, which_intercept
). Moreover, if needed, the user can add (add_intercept
) or remove (remove_intercept
) an intercept column to/from a hypr object. add_intercept
and remove_intercept
do not throw an error if the user attempts to remove a non-existing intercept or add an intercept if there already is one.
A single logical value (has_intercept
), a logical vector (is_intercept
), an integer index vector (which_intercept
), or a modified hypr object (add_intercept
, remove_intercept
)
add_intercept()
: Add an intercept column if there is none
remove_intercept()
: Remove the intercept column if there is one
which_intercept()
: Return indices, not a logical vector of intercept columns
has_intercept()
: Check whether any of the contrasts is an intercept
h1 <- hypr(mu1~0, mu2~mu1) h2 <- hypr(mu2~mu1, mu3~mu1) stopifnot(has_intercept(h1)) stopifnot(!has_intercept(h2)) stopifnot(which_intercept(h1) == 1) stopifnot(is_intercept(h1) == c(TRUE,FALSE))
h1 <- hypr(mu1~0, mu2~mu1) h2 <- hypr(mu2~mu1, mu3~mu1) stopifnot(has_intercept(h1)) stopifnot(!has_intercept(h2)) stopifnot(which_intercept(h1) == 1) stopifnot(is_intercept(h1) == c(TRUE,FALSE))
Centeredness of contrasts is critical for the interpretation of interactions and intercepts. There are functions available to check for centered contrasts and to realign contrasts so that they are centered.
centered_contrasts(x) is_centered(x) all_centered(x, ignore_intercept = TRUE) which_centered(x)
centered_contrasts(x) is_centered(x) all_centered(x, ignore_intercept = TRUE) which_centered(x)
x |
A hypr object |
ignore_intercept |
If |
The function centered_contrasts(x)
will return a copy of x
where all contrasts were centered to a zero mean.
The functions is_centered(x)
and which_centered()
indicate which contrasts of x
, are centered. all_centered(x)
will return TRUE
if all contrasts in x
are centered or FALSE
if at least one contrast is not.
A centered set of hypr contrasts (centered_contrasts
), a single logical value (all_centered
), a logical vector (is_centered
), or an integer index vector (which_centered
)
is_centered()
: Check which contrasts of x
are centered
all_centered()
: Check whether all contrasts of x
are centered
which_centered()
: Check which contrasts of x
are centered
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 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
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
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 |
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).
A matrix
of contrast codes with contrasts as columns and levels as rows.
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
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
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)
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)
These functions can be used to translate between null hypothesis equations, hypothesis matrices, and contrast matrices without defining a hypr
object. Note that some of these functions do generate a hypr
object internally but they never return one.
eqs2hmat( eqs, levels = NULL, order_levels = missing(levels), as_fractions = TRUE ) eqs2cmat(eqs, as_fractions = TRUE) hmat2cmat(hmat, as_fractions = TRUE) cmat2hmat(cmat, as_fractions = TRUE) hmat2eqs(hmat, as_fractions = TRUE) cmat2eqs(cmat, as_fractions = TRUE)
eqs2hmat( eqs, levels = NULL, order_levels = missing(levels), as_fractions = TRUE ) eqs2cmat(eqs, as_fractions = TRUE) hmat2cmat(hmat, as_fractions = TRUE) cmat2hmat(cmat, as_fractions = TRUE) hmat2eqs(hmat, as_fractions = TRUE) cmat2eqs(cmat, as_fractions = TRUE)
eqs |
A |
levels |
(optional) A |
order_levels |
(optional) Whether to alphabetically order appearance of levels (rows in transposed hypothesis matrix or contrast matrix). Default is |
as_fractions |
(optional) Whether to output matrix using fractions formatting (via |
hmat |
Hypothesis matrix |
cmat |
Contrast matrix |
A list
of equations (hmat2eqs
and cmat2eqs
), a contrast matrix (hmat2cmat
, eqs2cmat
), or a hypothesis matrix (cmat2hmat
, eqs2hmat
).
eqs2hmat()
: Convert null hypothesis equations to hypothesis matrix
eqs2cmat()
: Convert null hypothesis equations to contrast matrix
hmat2cmat()
: Convert hypothesis matrix to contrast matrix
cmat2hmat()
: Convert contrast matrix to hypothesis matrix
hmat2eqs()
: Convert hypothesis matrix to null hypothesis equations
cmat2eqs()
: Convert contrast matrix to null hypothesis equations
# The following examples are based on a 2-level treatment contrast (i.e., baseline and treatment). hypotheses <- list(baseline = mu1~0, treatment = mu2~mu1) hypothesis_matrix <- matrix( c(c(1, -1), c(0, 1)), ncol = 2, dimnames = list(c("baseline","treatment"), c("mu1", "mu2"))) contrast_matrix <- matrix( c(c(1, 1), c(0, 1)), ncol = 2, dimnames = list(c("mu1","mu2"), c("baseline", "treatment"))) # Convert a list of null hypothesis equations to ... # ... a hypothesis matrix: eqs2hmat(hypotheses) # ... a contrast matrix: eqs2cmat(hypotheses) # Convert a hypothesis matrix to... # ... a list of null hypothesis equations: hmat2eqs(hypothesis_matrix) # ... a contrast matrix: hmat2cmat(hypothesis_matrix) # Convert a contrast matrix to... # ... a list of null hypothesis equations: cmat2eqs(contrast_matrix) # ... a hypothesis matrix: cmat2hmat(contrast_matrix) # Are all functions returning the expected results? stopifnot(all.equal(eqs2hmat(hypotheses, as_fractions = FALSE), hypothesis_matrix)) stopifnot(all.equal(eqs2cmat(hypotheses, as_fractions = FALSE), contrast_matrix)) stopifnot(all.equal(hmat2cmat(hypothesis_matrix, as_fractions = FALSE), contrast_matrix)) stopifnot(all.equal(cmat2hmat(contrast_matrix, as_fractions = FALSE), hypothesis_matrix))
# The following examples are based on a 2-level treatment contrast (i.e., baseline and treatment). hypotheses <- list(baseline = mu1~0, treatment = mu2~mu1) hypothesis_matrix <- matrix( c(c(1, -1), c(0, 1)), ncol = 2, dimnames = list(c("baseline","treatment"), c("mu1", "mu2"))) contrast_matrix <- matrix( c(c(1, 1), c(0, 1)), ncol = 2, dimnames = list(c("mu1","mu2"), c("baseline", "treatment"))) # Convert a list of null hypothesis equations to ... # ... a hypothesis matrix: eqs2hmat(hypotheses) # ... a contrast matrix: eqs2cmat(hypotheses) # Convert a hypothesis matrix to... # ... a list of null hypothesis equations: hmat2eqs(hypothesis_matrix) # ... a contrast matrix: hmat2cmat(hypothesis_matrix) # Convert a contrast matrix to... # ... a list of null hypothesis equations: cmat2eqs(contrast_matrix) # ... a hypothesis matrix: cmat2hmat(contrast_matrix) # Are all functions returning the expected results? stopifnot(all.equal(eqs2hmat(hypotheses, as_fractions = FALSE), hypothesis_matrix)) stopifnot(all.equal(eqs2cmat(hypotheses, as_fractions = FALSE), contrast_matrix)) stopifnot(all.equal(hmat2cmat(hypothesis_matrix, as_fractions = FALSE), contrast_matrix)) stopifnot(all.equal(cmat2hmat(contrast_matrix, as_fractions = FALSE), hypothesis_matrix))
Fill free degrees of freedom with orthogonal filler contrasts.
filler_contrasts(x, how.many = nlevels(x), rescale = FALSE) which_filler(x) which_target(x) filler_names(x) target_names(x)
filler_contrasts(x, how.many = nlevels(x), rescale = FALSE) which_filler(x) which_target(x) filler_names(x) target_names(x)
x |
A hypr object |
how.many |
The total number of contrasts for the new hypr object |
rescale |
If |
which_filler()
: Return indices of filler contrasts
which_target()
: Return indices of filler contrasts
filler_names()
: Return names of filler contrasts
target_names()
: Return names of target contrasts
# A complete Helmert contrast matrix for 4 levels: h1 <- hypr(~ (mu2-mu1)/2, ~ (mu3-(mu1+mu2)/2)/3, ~ (mu4-(mu1+mu2+mu3)/3)/4, levels = c("mu1", "mu2", "mu3", "mu4") ) cmat(h1) # An incomplete Helmer contrast matrix (2nd contrast dropped) h2 <- hypr(~ (mu2-mu1)/2, ~ (mu4-(mu1+mu2+mu3)/3)/4, levels = c("mu1", "mu2", "mu3", "mu4") ) cmat(h2) # Filling the remaining degree of freedom retrieves the contrast h3 <- filler_contrasts(h2, rescale = TRUE) cmat(h3) stopifnot(all.equal(cmat(h3)[,3], cmat(h1)[,2], check.attributes = FALSE))
# A complete Helmert contrast matrix for 4 levels: h1 <- hypr(~ (mu2-mu1)/2, ~ (mu3-(mu1+mu2)/2)/3, ~ (mu4-(mu1+mu2+mu3)/3)/4, levels = c("mu1", "mu2", "mu3", "mu4") ) cmat(h1) # An incomplete Helmer contrast matrix (2nd contrast dropped) h2 <- hypr(~ (mu2-mu1)/2, ~ (mu4-(mu1+mu2+mu3)/3)/4, levels = c("mu1", "mu2", "mu3", "mu4") ) cmat(h2) # Filling the remaining degree of freedom retrieves the contrast h3 <- filler_contrasts(h2, rescale = TRUE) cmat(h3) stopifnot(all.equal(cmat(h3)[,3], cmat(h1)[,2], check.attributes = FALSE))
This is a generic function for setting an S4 object’s formulas.
formula(x, ...) <- value
formula(x, ...) <- value
x |
The object to manipulate |
... |
Additional arguments passed on to the method |
value |
The new formula |
This function is a wrapper for MASS::ginv
and calculates the generalized inverse of x
.
ginv2(x, as_fractions = TRUE)
ginv2(x, as_fractions = TRUE)
x |
The original matrix |
as_fractions |
Whether to format the matrix as fractions (MASS package) |
In addition to MASS::ginv
, this function rounds values, formats the matrix as fractions and copies dimension names from the original matrix.
Generalized inverse of x
h <- hypr(mu1~0, mu2~mu1) hmat(h) ginv2(hmat(h)) cmat(h) # cmat is effectively the generalized inverse of hmat stopifnot(all.equal( `class<-`(ginv2(hmat(h)), "matrix"), `class<-`(cmat(h), "matrix"), check.attributes = FALSE))
h <- hypr(mu1~0, mu2~mu1) hmat(h) ginv2(hmat(h)) cmat(h) # cmat is effectively the generalized inverse of hmat stopifnot(all.equal( `class<-`(ginv2(hmat(h)), "matrix"), `class<-`(cmat(h), "matrix"), check.attributes = FALSE))
Use these functions to retrieve or set a hypr object's hypothesis matrix. If used for updating, the contrast matrix and equations are derived automatically.
hmat(x, as_fractions = TRUE) thmat(x, as_fractions = TRUE) hmat(x) <- value thmat(x) <- value
hmat(x, as_fractions = TRUE) thmat(x, as_fractions = TRUE) hmat(x) <- value thmat(x) <- value
x |
A hypr object |
as_fractions |
Whether to format matrix as fractions (via |
value |
Hypothesis matrix |
Hypothesis matrix of x
thmat()
: Retrieve transposed hypothesis matrix
hmat(x) <- value
: Set hypothesis matrix
thmat(x) <- value
: Set transposed hypothesis matrix
h <- hypr(mu1~0, mu2~mu1) # To retrieve the hypothesis matrix of `h`: hmat(h) # To retrieve the transposed hypothesis matrix of `h`: thmat(h) # Setting the hypothesis matrix of `h`: hmat(h) <- matrix(c(1,-1,0,1), ncol=2, dimnames=list(NULL, c("mu1","mu2"))) h h2 <- hypr() # an empty hypr object thmat(h2) <- matrix(c(1,0,-1,1), ncol=2, dimnames=list(c("mu1","mu2"), NULL)) h2 # `h` and `h2` should be identical: stopifnot(all.equal(hmat(h), hmat(h2))) stopifnot(all.equal(cmat(h), cmat(h2)))
h <- hypr(mu1~0, mu2~mu1) # To retrieve the hypothesis matrix of `h`: hmat(h) # To retrieve the transposed hypothesis matrix of `h`: thmat(h) # Setting the hypothesis matrix of `h`: hmat(h) <- matrix(c(1,-1,0,1), ncol=2, dimnames=list(NULL, c("mu1","mu2"))) h h2 <- hypr() # an empty hypr object thmat(h2) <- matrix(c(1,0,-1,1), ncol=2, dimnames=list(c("mu1","mu2"), NULL)) h2 # `h` and `h2` should be identical: stopifnot(all.equal(hmat(h), hmat(h2))) stopifnot(all.equal(cmat(h), cmat(h2)))
Use this function to create hypr objects from null hypothesis equations. Each argument should be one equation. For example, a null hypothesis for the grand mean (GM), often used as the intercept, is usually coded as mu~0
.
hypr( ..., levels = NULL, add_intercept = FALSE, remove_intercept = FALSE, order_levels = missing(levels) )
hypr( ..., levels = NULL, add_intercept = FALSE, remove_intercept = FALSE, order_levels = missing(levels) )
... |
A list of null hypothesis equations |
levels |
(Optional) A list of terms/levels to use. If supplied, matrix rows/columns will be in this order. An error will be thrown if an equation contains a level that is not in this vector. |
add_intercept |
If |
remove_intercept |
If |
order_levels |
(Optional) Whether to order the rows/columns of the hypothesis/contrast matrices alphabetically. Default is |
You may call the function without any arguments. In that case, an empty hypr object is returned. This is useful if you want to derive equations from a known hypothesis matrix or contrast matrix.
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).
A hypr
object
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
contrasts
and C
for basic specification of contrasts in R, S4 class hypr
, cmat
, contr.hypothesis
for retrieval of contrast matrices from hypr
objects
# Create an empty hypr object (no hypotheses): h <- hypr() # Treatment contrast: h <- hypr(mu1~0, mu2~mu1, mu3~mu1, mu4~mu1) # Identical version: h <- hypr(~mu1, ~mu2-mu1, ~mu3-mu1, ~mu4-mu1) contr.hypothesis(h) # Generate a dataset set.seed(123) M <- c(mu1 = 10, mu2 = 20, mu3 = 10, mu4 = 40) # condition means N <- 5 # number of observations per condition SD <- 10 # residual SD simdat <- do.call(rbind, lapply(names(M), function(x) { data.frame(X = x, DV = as.numeric(MASS::mvrnorm(N, unname(M[x]), SD^2, empirical = TRUE))) })) simdat$X <- factor(simdat$X, levels=levels(h)) simdat # Check agreement of hypothesis levels and factor levels stopifnot(levels(h) == levels(simdat$X)) # Linear regression contrasts(simdat$X) <- contr.hypothesis(h) round(coef(summary(lm(DV ~ X, data=simdat))),3)
# Create an empty hypr object (no hypotheses): h <- hypr() # Treatment contrast: h <- hypr(mu1~0, mu2~mu1, mu3~mu1, mu4~mu1) # Identical version: h <- hypr(~mu1, ~mu2-mu1, ~mu3-mu1, ~mu4-mu1) contr.hypothesis(h) # Generate a dataset set.seed(123) M <- c(mu1 = 10, mu2 = 20, mu3 = 10, mu4 = 40) # condition means N <- 5 # number of observations per condition SD <- 10 # residual SD simdat <- do.call(rbind, lapply(names(M), function(x) { data.frame(X = x, DV = as.numeric(MASS::mvrnorm(N, unname(M[x]), SD^2, empirical = TRUE))) })) simdat$X <- factor(simdat$X, levels=levels(h)) simdat # Check agreement of hypothesis levels and factor levels stopifnot(levels(h) == levels(simdat$X)) # Linear regression contrasts(simdat$X) <- contr.hypothesis(h) round(coef(summary(lm(DV ~ X, data=simdat))),3)
A hypr
object contains equations, a hypothesis matrix and a contrast matrix, all of which are related to each other. See below for methods.
## S4 method for signature 'hypr' show(object) ## S4 method for signature 'hypr' levels(x) ## S4 method for signature 'hypr' nlevels(x) ## S4 method for signature 'hypr' names(x) ## S4 method for signature 'hypr' as.call(x) ## S4 replacement method for signature 'hypr' names(x) <- value ## S4 replacement method for signature 'hypr' levels(x) <- value ## S4 method for signature 'hypr' formula(x, ...) ## S4 replacement method for signature 'hypr' formula(x, ...) <- value
## S4 method for signature 'hypr' show(object) ## S4 method for signature 'hypr' levels(x) ## S4 method for signature 'hypr' nlevels(x) ## S4 method for signature 'hypr' names(x) ## S4 method for signature 'hypr' as.call(x) ## S4 replacement method for signature 'hypr' names(x) <- value ## S4 replacement method for signature 'hypr' levels(x) <- value ## S4 method for signature 'hypr' formula(x, ...) ## S4 replacement method for signature 'hypr' formula(x, ...) <- value
object , x
|
a hypr object |
value |
New value ( |
... |
(ignored) |
To generate a hypr object, use the hypr
function.
A character vector of level names
An integer denoting the number of levels
A character vector of contrast names
A call
object that reproduces the hypr
object
A list
of null hypothesis equations
show(hypr)
: Show summary of hypr object, including contrast equations, the (transposed) hypothesis matrix and the derived contrast matrix.
levels(hypr)
: Retrieve the levels (variable names) used in a hypr
object
nlevels(hypr)
: Retrieve the number of levels (variable names) used in a hypr
object
names(hypr)
: Retrieve the contrast names used in a hypr
object
as.call(hypr)
: Transform hypr
object to a reproducible function call
names(hypr) <- value
: Set the contrast names used in a hypr
object
levels(hypr) <- value
: Set the levels used in a hypr
object
formula(hypr)
: Retrieve a hypr
object’s null hypothesis equations.
formula(hypr) <- value
: Modify a hypr
object’s null hypothesis equations
eqs
List of null hypotheses
hmat
Hypothesis matrix
cmat
Contrast matrix
# Equations and matrices in a hypr object are always congruent # Therefore creating a hypr object h and then copying ... h <- hypr(mu1~0, mu2~mu1) # ... its equations, ... h2 <- hypr() formula(h2) <- formula(h) # ... its hypothesis matrix, ... h3 <- hypr() hmat(h3) <- hmat(h) # ... or its contast matrix ... h4 <- hypr() cmat(h4) <- cmat(h) # ... over to another hypr object is the same as copying the object: h5 <- h # check that hypr objects are equal by comparing hmat() and cmat() stopifnot(all.equal(hmat(h), hmat(h2))) stopifnot(all.equal(cmat(h), cmat(h2))) stopifnot(all.equal(hmat(h), hmat(h3))) stopifnot(all.equal(cmat(h), cmat(h3))) stopifnot(all.equal(hmat(h), hmat(h4))) stopifnot(all.equal(cmat(h), cmat(h4))) stopifnot(all.equal(hmat(h), hmat(h5))) stopifnot(all.equal(cmat(h), cmat(h5))) h <- hypr(mu1~0, mu2~mu1) formula(h) h2 <- hypr() formula(h2) <- formula(h) h2 formula(h2) # After updating, matrices should be equal stopifnot(all.equal(hmat(h), hmat(h2))) stopifnot(all.equal(cmat(h), cmat(h2)))
# Equations and matrices in a hypr object are always congruent # Therefore creating a hypr object h and then copying ... h <- hypr(mu1~0, mu2~mu1) # ... its equations, ... h2 <- hypr() formula(h2) <- formula(h) # ... its hypothesis matrix, ... h3 <- hypr() hmat(h3) <- hmat(h) # ... or its contast matrix ... h4 <- hypr() cmat(h4) <- cmat(h) # ... over to another hypr object is the same as copying the object: h5 <- h # check that hypr objects are equal by comparing hmat() and cmat() stopifnot(all.equal(hmat(h), hmat(h2))) stopifnot(all.equal(cmat(h), cmat(h2))) stopifnot(all.equal(hmat(h), hmat(h3))) stopifnot(all.equal(cmat(h), cmat(h3))) stopifnot(all.equal(hmat(h), hmat(h4))) stopifnot(all.equal(cmat(h), cmat(h4))) stopifnot(all.equal(hmat(h), hmat(h5))) stopifnot(all.equal(cmat(h), cmat(h5))) h <- hypr(mu1~0, mu2~mu1) formula(h) h2 <- hypr() formula(h2) <- formula(h) h2 formula(h2) # After updating, matrices should be equal stopifnot(all.equal(hmat(h), hmat(h2))) stopifnot(all.equal(cmat(h), cmat(h2)))