lm_test: Mass-univariate inference for contrasts in a linear model

View source: R/bootstrapCalibration.R

lm_testR Documentation

Mass-univariate inference for contrasts in a linear model

Description

Compute the marginal t-statistics for a set of contrasts and their (two-sided) p-value.

Usage

lm_test(Y, X, C, alternative = c("two.sided", "less", "greater"))

Arguments

Y

A data matrix of size $n$ observations (in row) and $D$ features in columns

X

A design matrix of size $n$ observations (in row) and $p$ variables (in columns)

C

A contrast matrix of size $L$ tested contrasts (in row) and $p$ columns corresponding to the parameters to be tested

alternative

A character string specifying the alternative hypothesis. Must be one of "two.sided" (default), "greater" or "less".

Details

Based on a python implementation available in the pyperm package: https://github.com/sjdavenport/pyperm/

Value

A list with elements:

epsilon_est

A n \times D matrix of residuals

stat_test

A L \times D matrix of test statistics

p.value

A L \times D matrix of p-values

beta_est

A n \times D matrix of parameter estimates

References

Davenport, S., Thirion, B., & Neuvial, P. (2025). FDP control in mass-univariate linear models using the residual bootstrap. Electronic Journal of Statistics, 19(1), 1313-1336.

Examples

N <- 100
p <- 2
D <- 2
X <- matrix(0, nrow = N, ncol = p)
X[, 1] <- 1
X[, -1] <- runif(N*(p-1), min = 0, max = 3)
beta <- matrix(0, nrow = p, ncol = D)
epsilons <- matrix(rnorm(N*D), nrow = N, ncol = D)
Y <- X %*% beta + epsilons
C <- diag(p)
resLM <- lm_test(Y = Y, X = X, C = C)

pneuvial/sanssouci documentation built on July 4, 2025, 3:16 p.m.