randrot {randRotation} | R Documentation

## Random rotation of initialised object

### Description

Perform random data rotation of a previously initialised object (see `initRandrot`) associated with the null hypothesis H0: β_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`, (Langsrud 2005) and (Hettegger et al. 2021).

### Value

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

### Author(s)

Peter Hettegger

### References

Hettegger P, Vierlinger K, Weinhaeusel A (2021). “Random rotation for identifying differentially expressed genes with linear models following batch effect correction.” Bioinformatics. ISSN 1367-4803, doi: 10.1093/bioinformatics/btab063.
Langsrud O (2005). “Rotation tests.” Statistics and Computing, 15(1), 53–60. ISSN 09603174, doi: 10.1007/s11222-005-4789-5.

### 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)))

[Package randRotation version 1.6.0 Index]