View source: R/fitLinearModel.R
fitLinearModel | R Documentation |
No-frills fitting of a linear model to the rows of any matrix-like object with numeric values.
fitLinearModel(
x,
design,
get.coefs = TRUE,
subset.row = NULL,
BPPARAM = SerialParam(),
rank.error = TRUE
)
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 |
get.coefs |
A logical scalar indicating whether the coefficients should be returned. |
subset.row |
An integer, character or logical vector indicating the rows of |
BPPARAM |
A BiocParallelParam object specifying the parallelization backend to use. |
rank.error |
Logical scalar indicating whether to throw an error when |
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.
If get.coefs=TRUE
, a list is returned containing:
coefficents
, a numeric matrix of coefficient estimates,
with one row per row of x
(or a subset thereof specified by subset.row
)
and one column per column of design
.
mean
, a numeric vector of row means of x
.
Computed as a courtesy to avoid iterating over the matrix twice.
variance
, a numeric vector of residual variances per row of x
.
Computed by summing the residual effects from the fitted model.
residual.df
, an integer scalar containing the residual degrees of freedom for design
.
Otherwise, if get.coefs=FALSE
, the same list is returned without coefficients
.
Aaron Lun
y <- Matrix::rsparsematrix(1000, 1000, 0.1)
design <- model.matrix(~runif(1000))
output <- fitLinearModel(y, design)
head(output$coefficients)
head(output$variance)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.