get_residuals: Get residuals from regression model

Description Usage Arguments Details Value Examples

View source: R/get_residuals.R

Description

Compute studentized residuals from fitting linear regression models to expression values in a data matrix

Usage

1
get_residuals(data, metadata.samples = NULL, metadata.genes = NULL, cores = 1)

Arguments

data

A matrix or SummarizedExperiment object with samples as columns and features (gene, probes) as rows. Note that expression values should typically be log2(expx + 1) transformed before fitting linear regression models.

metadata.samples

A data frame with samples as rows and columns the covariates. No NA values are allowed, otherwise residual of the corresponding sample will be NA.

metadata.genes

A data frame with genes (covariates) as rows and samples as columns. For each evaluated gene, each column (e.g. CNA) that corresponds to the same gene will be set as a single covariate variable. This can be used to correct copy number alterations for each gene.

cores

Number of CPU cores to be used. Defaults to 1.

Details

When only metadata.samples are provided, this function computes residuals for expression values in a data matrix by fitting model

features ~ Sample_covariate1 + Sample_covariate2 ... + Sample_covariateN where N is the index of the columns in the metadata provided, features are (typically log transformed) expression values.

When the user additionally provide metadata.genes, that is, gene metadata (e.g. gene_covariate = copy number variations/alterations) residuals are computed by fitting the following model:

features ~ Sample_covariate1 + Sample_covariate2 ... + Sample_covariateN + gene_covariate

Value

A residuals matrix with samples as columns and features (gene, probes) as rows

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
data("gene.exp.chr21.log2")

data("clinical")
metadata <- clinical[,c( "gender", "sample_type")]

cnv <- matrix(
   sample(x = c(-2,-1,0,1,2),
   size = ncol(gene.exp.chr21.log2) * nrow(gene.exp.chr21.log2),replace = TRUE),
   nrow = nrow(gene.exp.chr21.log2),
   ncol = ncol(gene.exp.chr21.log2)
)
rownames(cnv) <- rownames(gene.exp.chr21.log2)
colnames(cnv) <- colnames(gene.exp.chr21.log2)

gene.exp.residuals <- get_residuals(
   data = gene.exp.chr21.log2[1:3,],
   metadata.samples = metadata,
   metadata.genes = cnv
)
gene.exp.residuals <- get_residuals(
   data = gene.exp.chr21.log2[1:3,],
   metadata.samples = metadata,
   metadata.genes = cnv[1:2,]
)
gene.exp.residuals <- get_residuals(
   data = gene.exp.chr21.log2[1:3,],
   metadata.samples = metadata
)

MethReg documentation built on Nov. 8, 2020, 8:01 p.m.