run_limma_and_lfc: Run limma and calculate LFC

View source: R/run_limma_and_lfc.R

run_limma_and_lfcR Documentation

Run limma and calculate LFC

Description

Function to calculate LFC, run limma using lmFit, contrasts.fit, and eBayes with the flag robust = TRUE. If neither weights or gamma_reg_model is provided, then lmFit will be run without precision weights. If both are provided, then it will default to using the gamma_reg_model model to produce the weights.

Usage

run_limma_and_lfc(
  data,
  design,
  contrast_matrix,
  gamma_reg_model = NULL,
  id_col = "id",
  weights = NULL,
  .robust = T
)

Arguments

data

a data.frame with the samples and feature ids.

design

a design or model matrix produced by model.matrix.

contrast_matrix

a contrast matrix produced by makeContrasts.

gamma_reg_model

the regression model produced by fit_gamma_weights (see Mean-Variance_Gamma_Regressions) or any glm with formula sd ~ mean.

id_col

a character for the name of the column containing the name of the features in data (e.g., peptides, proteins, etc.).

weights

a matrix of precision weights.

Value

a tibble with the id_col, then one p_val_* and lfc_* for each comparison (*) in the contrast matrix

Examples

# Generate a design matrix for the data
design <- model.matrix(~ 0 + factor(rep(1:2, each = 3)))

# Set correct colnames, this is important for fit_gamma_*
colnames(design) <- paste0("ng", c(50, 100))

# Generate the contrast matrix
contrast <- limma::makeContrasts(
  contrasts = "ng100-ng50",
  levels = design
)

# Normalize and log-transform the data
yeast <- psrn(yeast, "identifier")

# Fit the gamma regressions
gamma_reg_model <- fit_gamma_weights(yeast, design, "identifier")

# Exemplify on the non-missing data
yeast <- tidyr::drop_na(yeast)

results <- run_limma_and_lfc(
  yeast,
  design,
  contrast,
  gamma_reg_model,
  "identifier"
)

PhilipBerg/PaiR documentation built on March 18, 2022, noon