fitLinearModel: Fit a linear model

Description Usage Arguments Details Value Author(s) Examples

View source: R/fitLinearModel.R

Description

No-frills fitting of a linear model to the rows of any matrix-like object with numeric values.

Usage

1
2
3
4
5
6
7
8
fitLinearModel(
  x,
  design,
  get.coefs = TRUE,
  subset.row = NULL,
  BPPARAM = SerialParam(),
  rank.error = TRUE
)

Arguments

x

A numeric matrix-like object where columns are samples (e.g., cells) and rows are usually features (e.g., genes).

design

A numeric design matrix with number of rows equal to ncol(x). This should be of full column rank.

get.coefs

A logical scalar indicating whether the coefficients should be returned.

subset.row

An integer, character or logical vector indicating the rows of x to use for model fitting.

BPPARAM

A BiocParallelParam object specifying the parallelization backend to use.

rank.error

Logical scalar indicating whether to throw an error when design is not of full rank.

Details

This function is basically a stripped-down version of lm.fit, made to operate on any matrix representation (ordinary, sparse, whatever). It is generally intended for use inside other functions that require robust and efficient linear model fitting.

If design is not of full rank and rank.error=TRUE, an error is raised. If rank.error=FALSE, NA values are returned for all entries of the output list.

Value

If get.coefs=TRUE, a list is returned containing:

Otherwise, if get.coefs=FALSE, the same list is returned without coefficients.

Author(s)

Aaron Lun

Examples

1
2
3
4
5
6
y <- Matrix::rsparsematrix(1000, 1000, 0.1)
design <- model.matrix(~runif(1000))

output <- fitLinearModel(y, design)
head(output$coefficients)
head(output$variance)

scuttle documentation built on Dec. 19, 2020, 2 a.m.