Hypothesis Matrix Translation

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) and Rabe et al. (2020) .


hypr

CRAN downloads JOSS publicationstatus DOI Packagestatus

hypr is an R package for easy translation between experimental (null) hypotheses and contrast matrices as used for linear regression. For an extensive overview of the package functions, see the hypr-intro vignette, e.g. by running vignette("hypr-intro") after installing the package.

Installation

Install from CRAN within R using:

install.packages("hypr")

Install the development version in R using devtools:

devtools::install_github("mmrabe/hypr", build_vignettes = TRUE)

Deriving contrast matrices

For a treatment contrast with a baseline and three treatment conditions:

trtC <- hypr(mu1~0, mu2~mu1, mu3~mu1, mu4~mu1)
trtC
## hypr object containing 4 null hypotheses:
## H0.1: 0 = mu1        (Intercept)
## H0.2: 0 = mu2 - mu1
## H0.3: 0 = mu3 - mu1
## H0.4: 0 = mu4 - mu1
## 
## Call:
## hypr(~mu1, ~mu2 - mu1, ~mu3 - mu1, ~mu4 - mu1, levels = c("mu1", 
## "mu2", "mu3", "mu4"))
## 
## Hypothesis matrix (transposed):
##     [,1] [,2] [,3] [,4]
## mu1  1   -1   -1   -1  
## mu2  0    1    0    0  
## mu3  0    0    1    0  
## mu4  0    0    0    1  
## 
## Contrast matrix:
##     [,1] [,2] [,3] [,4]
## mu1 1    0    0    0   
## mu2 1    1    0    0   
## mu3 1    0    1    0   
## mu4 1    0    0    1

To assign the contrast matrix to a factor fac with an intermediate hypr object:

contrasts(fac) <- contr.hypothesis(trtC)

… or without an intermediate object:

contrasts(fac) <- contr.hypothesis(mu1~0, mu2~mu1, mu3~mu1, mu4~mu1) 

For more information, see vignette("hypr-regression").

Deriving research hypotheses

To check which reserach (null) hypotheses a given contrast matrix is testing, we can create an empty hypr object.

testC <- hypr() # create an empty hypr object

A treatment contrast with 4 levels (incl. the baseline) can look as follows:

contr.treatment(4)
##   2 3 4
## 1 0 0 0
## 2 1 0 0
## 3 0 1 0
## 4 0 0 1

We can now populate the hypr object by setting its contrast matrix. Note that the treatment contrast does not have an intercept. We thus have to add it when populating the hypr object:

cmat(testC, add_intercept = TRUE) <- contr.treatment(4) # populate object via contrast matrix

Now, the hypr object contains 4 hypotheses, a hypothesis matrix and the contrast matrix identical to the treatment contrast with an intercept added:

testC
## hypr object containing 4 null hypotheses:
## H0.Intercept: 0 = X1        (Intercept)
##         H0.2: 0 = -X1 + X2
##         H0.3: 0 = -X1 + X3
##         H0.4: 0 = -X1 + X4
## 
## Call:
## hypr(Intercept = ~X1, `2` = ~-X1 + X2, `3` = ~-X1 + X3, `4` = ~-X1 + 
##     X4, levels = c("X1", "X2", "X3", "X4"))
## 
## Hypothesis matrix (transposed):
##    Intercept 2  3  4 
## X1  1        -1 -1 -1
## X2  0         1  0  0
## X3  0         0  1  0
## X4  0         0  0  1
## 
## Contrast matrix:
##    Intercept 2 3 4
## X1 1         0 0 0
## X2 1         1 0 0
## X3 1         0 1 0
## X4 1         0 0 1

The derived hypotheses can be rewritten as:

For more information, see vignette("hypr-contrasts").

Community guidelines

If you want to report a bug, are having technical difficulties or want to recommend features, it’s best to open a Github Issue. If you want to suggest a specific implementation of a feature or bug fix, you’re welcome to fork the repository and submit a pull request! Alternatively, if you are having problems or questions, you can also send an e-mail ([email protected]).

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("hypr")

0.2.8 by Maximilian M. Rabe, 3 years ago


https://maxrabe.com/hypr


Report a bug at https://github.com/mmrabe/hypr/issues


Browse source code at https://github.com/cran/hypr


Authors: Maximilian M. Rabe [aut, cre] , Shravan Vasishth [aut] , Sven Hohenstein [aut] , Reinhold Kliegl [aut] , Daniel J. Schad [aut]


Documentation:   PDF Manual  


GPL-3 license


Imports MASS, pracma, methods, cli, magrittr, Matrix

Suggests knitr, rmarkdown


Imported by appRiori.

Suggested by contrastable.


See at CRAN