This function performs differential expression testing between conditions using the provided contrast matrix, based on a fitted devil model.

test_de(
  devil.fit,
  contrast,
  pval_adjust_method = "BH",
  max_lfc = 10,
  clusters = NULL
)

Arguments

devil.fit

An object containing the fitted devil model, which is returned by the fit_devil function.

contrast

A numeric vector or matrix specifying the contrast of interest for differential expression testing. The contrast defines the comparison between conditions.

pval_adjust_method

A character string specifying the method to adjust p-values for multiple testing. (default is "BH" (Benjamini & Hochberg method))

max_lfc

A numeric value specifying the maximum absolute log fold change to consider when filtering results. (default is 10)

clusters

An optional numeric or factor vector containing cluster IDs for each sample. This is useful in experimental settings where samples belong to different groups, such as different patients.

Value

A tibble containing the results of the differential expression testing. The tibble includes:

name

The gene names corresponding to the rows of the devil.fit model.

pval

The p-values associated with the differential expression test for each gene.

adj_pval

The adjusted p-values after applying the specified p-value adjustment method.

lfc

The log fold changes for each gene, scaled by log base 2 and filtered by max_lfc.

Details

This function calculates log fold changes and p-values for each gene in parallel. It first computes log fold changes by multiplying the beta coefficients from the fitted model with the specified contrast. Then, it calculates p-values using either the sandwich variance estimator (if clusters is provided) or the Hessian matrix. The results are adjusted for multiple testing using the specified p-value adjustment method.

The results are filtered based on the specified maximum absolute log fold change (max_lfc), ensuring that extreme log fold changes are capped at this value.