Skip to contents

Function to correct for run-order drifts within or across batches via a provided custom function #' @details The drift correction function needs to be provided by the user. See smooth_fun for details.

Usage

corr_drift_fun(
  data,
  smooth_fun,
  qc_types,
  log2_transform = TRUE,
  span_width,
  within_batch,
  apply_conditionally,
  apply_conditionally_per_batch = TRUE,
  max_cv_ratio_before_after = 1,
  use_uncorrected_if_fit_fails = TRUE,
  feature_list = NULL,
  ...
)

Arguments

data

MidarExperiment object

smooth_fun

Function that performs drift correction. Function need to have following parameter data (MidarExperiment), QC_TYPES (one or more strings), and span_width (numerical). Function needs to return a numerical vector with the length of number of rows in data. In case functions fails a vector with NA_real_ needs be returned

qc_types

QC types used for drift correction

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_width

Width used by smoothing function

within_batch

Apply to each batch separately if TRUE (the default)

apply_conditionally

Apply drift correction to all species if TRUE, 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

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.

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.

...

Parameters specific for the smoothing function

Value

MidarExperiment object