knitr::opts_chunk$set(echo = TRUE) library(hypr)
hypr
is a package for easy translation between experimental (null) hypotheses, hypothesis matrices and contrast matrices, as used for coding factor contrasts in linear regression models. The package can be used to derive contrasts from hypotheses and vice versa. This vignette provides an example for understanding contrasts by deriving hypotheses from contrast matrices.
For a general introduction to hypr
, see the hypr-intro
vignette:
vignette("hypr-intro", package = "hypr")
For an introduction to using hypr
for contrast coding in regression models, see the hypr-regression
vignette:
vignette("hypr-regression", package = "hypr")
Treatment contrasts are relatively easy to understand. The intercept tests the statistical significance of the baseline against zero while the contrasts test the significance of the treatments against the baseline.
Even though this is a simple coding scheme, it might not be immediately clear to everyone examining the contrast matrix:
contr.treatment(4) # a contrast matrix for one baseline and 3 treatments
To understand what this contrast is testing, we can create an empty hypr
object and set its contrast matrix to the one above:
h <- hypr() cmat(h) <- contr.treatment(4) h
When looking at the inferred equations, we can see that this contrast tests the significance of the treatments against zero. This is only appropriate if there is no baseline. However, we may want to consider a non-zero baseline. This is usually included in regression models. To let hypr
know that we are including an intercept for the baseline, we can set the contrast matrix like this:
cmat(h, add_intercept = TRUE) <- contr.treatment(4) h
Finally, the derived hypotheses can be formulated as:
\begin{align} H_{0_1}:& \; \mu_1 = 0 \ H_{0_2}:& \; \mu_2 = \mu_1 \ H_{0_3}:& \; \mu_3 = \mu_1 \ H_{0_4}:& \; \mu_4 = \mu_1 \end{align}
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.