randrot: Random rotation of initialised object

randrotR Documentation

Random rotation of initialised object

Description

Perform random data rotation of a previously initialised object (see initRandrot) associated with the null hypothesis H_{0}: \beta_{coef.h} = 0.

Usage

randrot(object, ...)

## S4 method for signature 'initRandrot'
randrot(object, ...)

## S4 method for signature 'initRandrotW'
randrot(object, ...)

## S4 method for signature 'initBatchRandrot'
randrot(object, ...)

Arguments

object

An initialised object of class initRandrot-class or initBatchRandrot-class.

...

further arguments passed to randorth

Details

This function generates a randomly rotated dataset from an initialised randrot object (see initRandrot). See also package vignette for application examples. Only the numerical matrix of rotated data is returned, no design matrix, weights or other info is return for efficiency purposes. Please consider that, if you e.g. use weights or if you use rotateStat, you may need to forward the design matrix X, weights etc. to subsequent analyses. See the example in rotateStat.

Details on the calculation of a rotated dataset are given in initRandrot, \insertCiteLangsrud2005randRotation and \insertCiteHettegger2021randRotation.

Value

numeric matrix of rotated data under the specified combined null hypothesis.

Author(s)

Peter Hettegger

References

\insertAllCited

Examples

# For further examples see '?rotateStat' and package vignette.

#set.seed(0)

# Dataframe of phenotype data (sample information)
# We simulate 2 sample classes processed in 3 batches
pdata <- data.frame(batch = rep(1:3, c(10,10,10)),
                   phenotype = rep(c("Control", "Cancer"), c(5,5)))
features <- 100

# Matrix with random gene expression data
edata <- matrix(rnorm(features * nrow(pdata)), features)
rownames(edata) <- paste("feature", 1:nrow(edata))

mod1 <- model.matrix(~phenotype, pdata)

# Initialisation of the random rotation class
init1 <- initBatchRandrot(Y = edata, X = mod1, coef.h = 2,
                            batch = pdata$batch)
init1

### Fit model to original data

fit.orig <- lm.fit(mod1, t(edata))
head(t(coef(fit.orig)))

### Fit model to rotated data

edata.rot <- randrot(init1)
fit.rot <- lm.fit(mod1, t(edata.rot))
head(t(coef(fit.rot)))


# Note that the coefficients stay equal if we regress only on the
# non-hypothesis coefficients

mod0 <- model.matrix(~1, pdata)
fit.orig0 <- lm.fit(mod0, t(edata))
fit.rot0  <- lm.fit(mod0, t(edata.rot))
head(t(coef(fit.orig0)))
head(t(coef(fit.rot0)))


phettegger/randRotation documentation built on April 10, 2023, 7:25 p.m.