Fit a negative-binomial GLM using qsea::fitNBglm() on counts from a qsea::qseaSet, and add one or more contrasts. This is the low-level worker used by calculateDMRs().

fitQseaGLM(
  qseaSet,
  variable = NULL,
  covariates = NULL,
  contrasts = NULL,
  keepIndex = NULL,
  minReadCount = 0,
  minNRPM = 1,
  checkPVals = TRUE,
  formula = NULL,
  calcDispersionAll = FALSE
)

Arguments

qseaSet

qseaSet. Input object containing counts and sample metadata.

variable

character(1) Column name in the sample table used as the primary explanatory variable. Default: NULL (must be provided unless formula is supplied).

covariates

character() Additional column names (e.g., batch, patient ID) to include as covariates. Default: NULL.

contrasts

data.frame or NULL A data frame with columns group1 and group2 specifying contrasts to compute. If NULL, a fitted GLM with no contrasts added is returned. Default: NULL.

keepIndex

integer() or NULL Row indices (windows) to retain before fitting; when supplied, this overrides filtering by minReadCount / minNRPM. Default: NULL.

minReadCount

numeric(1) Minimum raw count required in at least one sample to retain a window. Default: 0.

minNRPM

numeric(1) Minimum NRPM required in at least one sample to retain a window. Default: 1.

checkPVals

logical(1) If TRUE, stop or warn if an excessive proportion of p-values are exactly zero (possible instability). Default: TRUE.

formula

formula or NULL Optional model formula overriding variable/covariates. Default: NULL.

calcDispersionAll

logical(1) If TRUE, samples not present in any specified contrast are still used to fit the initial GLM and dispersion estimates. Note this means adding samples to qseaSet can change DMRs even when they are not directly contrasted. Default: FALSE.

Value

A qseaGLM object containing:

  • the fitted negative-binomial GLM;

  • (optionally) one or more added contrasts (group1 vs group2);

  • filtering metadata (based on keepIndex, minReadCount, minNRPM);

  • model specification (variable, covariates, or formula).

Details

  • Dispersion is estimated across the windows retained after filtering.

  • When calcDispersionAll = TRUE, all samples contribute to dispersion estimation even if not part of any contrast.

  • Contrasts are added sequentially with qsea::addContrast().

  • By default, beta-normalised counts are used as the outcome (as in qsea).

See also

Examples

data(exampleTumourNormal, package = "mesa")
qs <- exampleTumourNormal
contr <- tibble::tibble(group1 = "LUAD", group2 = "NormalLung")
fitQseaGLM(qs, variable = "type", contrasts = contr)
#> Generating table of nrpm values for 819 regions across 5 samples.
#> Fitting initial GLM on 255 windows, without using parallelisation.
#> Performing contrast LUAD_vs_NormalLung
#> Contrasts Complete
#> qsea GLM object
#> =======================================
#> full model: log(y/norm) ~ typeLUAD + typeNormalLung
#> contrasts: LUAD_vs_NormalLung