Normalize Data for Linear Drift Between Pre and Post Measurements
Source:R/normalise_drift_means.R
normalise_drift_means.Rd
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.
Details
The function performs the following steps:
Calculates mean of pre-measurements if multiple values provided
Calculates mean of post-measurements if multiple values provided
Creates a linear interpolation between pre and post means
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