testLinearModel {scran} | R Documentation

## Hypothesis tests with linear models

### Description

Perform basic hypothesis tests with linear models in an efficient manner.

### Usage

    testLinearModel(x, ...)

    ## S4 method for signature 'ANY'
    testLinearModel(
      x,
      design,
      coefs = ncol(design),
      contrasts = NULL,
      block = NULL,
      equiweight = FALSE,
      method = "z",
      subset.row = NULL,
      BPPARAM = SerialParam()
    )

    ## S4 method for signature 'SummarizedExperiment'
    testLinearModel(x, ..., assay.type = "logcounts")

### Arguments

`x` | A numeric matrix-like object containing log-expression values for cells (columns) and genes (rows). Alternatively, a SummarizedExperiment containing such a matrix.
`...` | For the generic, further arguments to pass to specific methods. For the SummarizedExperiment method, further arguments to pass to the ANY method.
`design` | A numeric design matrix with number of rows equal to `ncol(x)`.
`coefs` | An integer vector specifying the coefficients to drop to form the null model. Only used if `contrasts` is not specified.
`contrasts` | A numeric vector or matrix specifying the contrast of interest. This should have length (if vector) or number of rows (if matrix) equal to `ncol(x)`.
`block` | A factor specifying the blocking levels for each cell in `x`. If specified, variance modelling is performed separately within each block and statistics are combined across blocks.
`equiweight` | A logical scalar indicating whether statistics from each block should be given equal weight. Otherwise, each block is weighted according to its number of cells. Only used if `block` is specified.
`method` | String specifying how p-values should be combined when `block` is specified, see `combinePValues`.
`subset.row` | See `?"scran-gene-selection"`, specifying the rows for which to model the variance. Defaults to all genes in `x`.
`BPPARAM` | A BiocParallelParam object indicating whether parallelization should be performed across genes.
`assay.type` | String or integer scalar specifying the assay containing the log-expression values.

### Details

This function can be considered a more efficient version of `lmFit` that works on a variety of matrix representations (see `fitLinearModel`). It also omits the empirical Bayes shrinkage step, which is acceptable given the large number of residual d.f. in typical single-cell studies.

If `contrasts` is specified, the null hypothesis is defined by the contrast matrix or vector in the same manner that is used in the limma and edgeR packages. Briefly, the contrast vector specifies a linear combination of coefficients that sums to zero under the null. For contrast matrices, the joint null consists of the intersection of the nulls defined by each column vector.

Otherwise, if only `coefs` is specified, the null model is formed by simply dropping all of the specified coefficients from `design`.

If `block` is specified, a linear model is fitted separately to the cells in each level. The results are combined across levels by averaging coefficients and combining p-values with `combinePValues`. By default, the contribution from each level is weighted by its number of cells; if `equiweight=TRUE`, each level is given equal weight instead.

### Value

A DataFrame containing test results with one row per row of `x`. It contains the estimated values of the contrasted coefficients as well as the p-value and FDR for each gene.

### Author(s)

Aaron Lun

### See Also

`fitLinearModel`, which performs the hard work of fitting the linear models.

### Examples

    y <- matrix(rnorm(10000), ncol=100)

    # Example with categorical factors:
    A <- gl(2, 50)
    design <- model.matrix(~A)
    testLinearModel(y, design, contrasts=c(0, 1))

    # Example with continuous variables:
    u <- runif(100)
    design <- model.matrix(~u)
    testLinearModel(y, design, contrasts=c(0, 1))

    # Example with multiple variables:
    B <- gl(4, 25)
    design <- model.matrix(~B)
    testLinearModel(y, design, contrasts=cbind(c(0,1,0,0), c(0,0,1,-1)))

[Package scran version 1.18.7 Index]