diagnose_models: Model diagnostics after batch adjustment

View source: R/diagnose_models.R

diagnose_modelsR Documentation

Model diagnostics after batch adjustment

Description

After adjust_batch has performed adjustment for batch effects, diagnose_models provides an overview of parameters and adjustment models. Information is only available about the most recent run of adjust_batch on a dataset.

Usage

diagnose_models(data)

Arguments

data

Batch-adjusted dataset (in which adjust_batch has stored information on batch adjustment in the attribute .batchtma)

Value

List:

  • adjust_method Method used for batch adjustment (see adjust_batch).

  • markers Variables of biomarkers for adjustment

  • suffix Suffix appended to variable names

  • batchvar Variable indicating batch

  • confounders Confounders, i.e. determinants of biomarker levels that differ between batches. Returned only if used by the model.

  • adjust_parameters Tibble of parameters used to obtain adjust biomarker levels. Parameters differ between methods:

    • simple, standardize, and ipw: Estimated adjustment parameters are a tibble with one batchmean per marker and .batchvar.

    • quantreg returns a tibble with numerous values per marker and .batchvar: unadjusted (un_...) and adjusted (ad_...) estimates of the lower (..._lo) and upper quantile (..._hi) and interquantile range (..._iq), plus the lower (all_lo) and upper quantiles (all_hi) across all batches.

    • quantnorm does not explicitly estimate parameters.

  • model_fits List of model fit objects, one per biomarker. Models differ between methods:

    • standardize: Linear regression model for the biomarker with .batchvar and confounders as predictors, from which marginal predictions of batch means for each batch are obtained.

    • ipw: Logistic (2 batches) or multinomial models for assignment to a specific batch with .batchvar as the response and confounders as the predictors, used to generate stabilized inverse-probability weights that are then used in a linear regression model to estimate marginally standardized batch means.

    • quantreg: Quantile regression with the marker as the response variable and .batchvar and confounders as predictors.

    • simple and quantnorm do not fit any regression models.

Examples

# Data frame with two batches
# Batch 2 has higher values of biomarker and confounder
df <- data.frame(
  tma = rep(1:2, times = 10),
  biomarker = rep(1:2, times = 10) +
    runif(max = 5, n = 20),
  confounder = rep(0:1, times = 10) +
    runif(max = 10, n = 20)
)

# Adjust for batch effects
df2 <- adjust_batch(
  data = df,
  markers = biomarker,
  batch = tma,
  method = quantreg,
  confounders = confounder
)

# Show overview of model diagnostics:
diagnose_models(data = df2)

# Obtain first fitted regression model:
fit <- diagnose_models(data = df2)$model_fits[[1]][[1]]

# Obtain residuals for this model:
residuals(fit)

stopsack/batchtma documentation built on June 10, 2024, 1:33 a.m.