Skip to contents

This function normalizes a data vector by subtracting a linear interpolation between the means of pre and post measurements. This is useful for correcting measurement drift in experimental data.

Usage

normalise_drift_means(data, pre, post)

Arguments

data

Numeric vector containing the measurements to be normalized

pre

Numeric vector or single value representing pre-measurement(s)

post

Numeric vector or single value representing post-measurement(s)

Value

A numeric vector of the same length as data containing the normalized values

Details

The function performs the following steps:

  1. Calculates mean of pre-measurements if multiple values provided

  2. Calculates mean of post-measurements if multiple values provided

  3. Creates a linear interpolation between pre and post means

  4. Subtracts interpolated values from the data to correct for drift

Examples

# Single pre/post values
data <- c(15, 16, 17, 18, 19)
normalise_drift_means(data, pre = 10, post = 20)
#> Corrected for linear drift between 10 and 20
#> [1]  5.0  3.5  2.0  0.5 -1.0

# Multiple pre/post values
normalise_drift_means(
  data = c(15, 16, 17, 18, 19),
  pre = c(10, 11, 12),
  post = c(19, 20, 21)
)
#> Using mean of 3 pre-measurements: 11
#> Using mean of 3 post-measurements: 20
#> Corrected for linear drift between 11 and 20
#> [1]  4.00  2.75  1.50  0.25 -1.00