Skip to contents

Function to correct for run-order drifts within or across batches using loess smoothing

Usage

corr_drift_loess(
  data,
  qc_types,
  within_batch,
  apply_conditionally,
  apply_conditionally_per_batch = TRUE,
  log2_transform = TRUE,
  span = 0.75,
  feature_list = NULL,
  max_cv_ratio_before_after = 1,
  use_uncorrected_if_fit_fails = TRUE,
  extrapolate = FALSE
)

Arguments

data

MidarExperiment object

qc_types

QC types used for drift correction

within_batch

Apply to each batch separately if TRUE (the default)

apply_conditionally

Apply drift correction to all species if FALSE, or only when sample CV after smoothing changes below a threshold defined via max_cv_ratio_before_after

apply_conditionally_per_batch

When apply_conditionally = TRUE, correction is conditionally applied per batch when TRUE and across all batches when FALSE

log2_transform

Log transform the data for correction when TRUE (the default). Note: log transformation is solely applied internally for smoothing, results will not be be log-transformed. Log transformation may result in more robust smoothing that is less sensitive to outlier.

span

Loess span width (default is 0.75)

feature_list

Subset the features for correction whose names matches the specified text using regular expression. Default is NULL which means all features are selected.

max_cv_ratio_before_after

Only used when apply_conditionally = TRUE. Maximum allowed ratio of sample CV change before and after smoothing for the correction to be applied. A value of 1 (the default) indicates the CV needs to improve or remain unchanged after smoothing so that the conditional smoothing is applied. A value of < 1 means that CV needs to improve, a value of e.g. 1.20 that the CV need to improve or get worse by max 1.20-fold after smoothing.

use_uncorrected_if_fit_fails

In case the smoothing function fails for a species, then use original (uncorrected) data when TRUE (the default) or return NA for all analyses of the feature where the fit failed.

extrapolate

Extrapolate loess smoothing. WARNING: It is generally not recommended to extrapolate outside of the range spanned by the QCs used for smoothing. See details below.

Value

MidarExperiment object

Details

Note that using extrapolation for loess smoothing is generally not recommended. Use this only if you must include samples or QCs that are outside of the range spanned by the QCs used for smoothing. Cases where this may be necessary are when specific drifts occur in analysis sequence segments that are not spanned by QC, e.g. when the instrument broke down or suddenly changed its sensitivity. Only use for samples adjacent to the first or last QC and consult runscatter plots.