This function performs linear modeling using the Limma package, incorporating covariates in the model fitting process. It is designed to handle both two-group comparisons and multi-group settings with covariates.

Limma_fit(
  x,
  group,
  meta.info,
  formula.str,
  trend,
  robust,
  correlation_block = NULL
)

Arguments

x

A list containing two or more data matrices where rows represent features (e.g., genes, proteins) and columns represent samples. The list should contain at least two matrices for pairwise group comparison.

group

A character string indicating the name of the group variable inmeta.info to be used in the analysis.

meta.info

A data frame containing the metadata for the samples. This includes sample grouping and any covariates to be included in the model.

formula.str

A string specifying the formula to be used in model fitting. It should follow the standard R formula syntax (e.g., ~ covariate1 + covariate2). If the formula contains a random effects term (i.e., includes |, e.g., ~ 0 + group + (1|subject)), the function automatically routes to DREAM analysis via dream. The DREAM path is restricted to two-group comparisons; passing more than two groups with a random term raises an error.

trend

A logical value indicating whether to allow for an intensity-dependent trend in the prior variance.

robust

A logical value indicating whether to use a robust fitting procedure to protect against outliers.

correlation_block

Character or NULL. The name of a column in meta.info that defines correlation blocks. When not NULL, within-block correlation is estimated via duplicateCorrelation and accounted for in lmFit. If NULL, standard independent fitting is used.

Value

A list containing the following elements:

d

A vector of the test statistics (log-fold changes or F-statistics) for each feature.

s

A vector of the standard deviations for each feature, adjusted by t he empirical Bayes procedure.

corrected.logfc

The log-fold changes for each feature after fitting the model.

Details

This function combines the data matrices from different groups and fits a linear model using covariates provided in the meta.info. For two-group comparisons, the function computes contrasts between the two groups and applies empirical Bayes moderation. For multi-group analysis with a single covariate, pairwise contrasts are computed, and the moderated F-statistic is calculated for each feature.

When formula.str contains a | character (random effects term), the function bypasses the standard limma workflow and instead uses dream to fit a linear mixed model. This path is only supported for two-group comparisons. Passing more than two groups with a random-effects formula raises an informative error directing the user to use the correlation_block argument with a fixed-effects formula instead.