correct_rel_bias: Correct systematic bias in metabolomic time-course data

View source: R/correction.R

correct_rel_biasR Documentation

Correct systematic bias in metabolomic time-course data

Description

Identifies systematic deviations in metabolic data using a spline fit. Timepoints that have a median relative deviation above a min.deviation value are assumed to be influenced by a measurement or methodological bias as compared to the overall trends metabolite concentrations.

Usage

correct_rel_bias(
  time,
  concentration,
  compound,
  min.deviation = NULL,
  degree = 3,
  knots = c(0.5)
)

Arguments

time

A vector of times or sample numbers for metabolite time-courses. Note, there should be a time value for every concentration for every compound e.g. time = c(1, 2, 3, 1, 2, 3), concentration = c(20, 15, 10, 3, 6, 9), compound = c('glc', 'glc', 'glc', 'lac', 'lac', 'lac').

concentration

A vector of metabolite concentrations.

compound

A vector of metabolite names that correspond to time and concentration.

min.deviation

Smallest median relative deviation to identify as a bias.

degree

degree of the B-spline

knots

position of the knots of the B-spline as a fraction. e.g. knots <- c(0.25, 0.5, 0.75)

Value

A dataframe with the fit.

Examples


# Using previously simulated data 40 metabolic trends with 10 time points
data(timecourse)

# Adding an error of 5% at sample 4
logic <- timecourse$sample == 4
timecourse$concentration[logic] <- timecourse$concentration[logic] * 1.05

# Correcting
output <- correct_rel_bias(timecourse$time,
                                         timecourse$concentration,
                                         timecourse$metabolite,
                                         degree = 2)
timecourse$corrected <- output$fit

# Plotting -- the original value of the corrected point is marked in red
par(mfrow = c(8, 5), oma = c(5, 4, 1, 1) + 0.1, mar = c(1, 1, 1, 1) + 0.1)

for (metabolite in unique(timecourse$metabolite)) {

  logic <- timecourse$metabolite == metabolite
  d <- timecourse[logic, ]

  logic2 <- d$concentration != d$corrected

  plot(d$time, d$corrected, pch = 16, xlab = '', ylab = '',
       ylim = c(min(d$concentration), max(d$concentration)))


  points(d$time[logic2], d$concentration[logic2], pch = 16, col = 'red')

}

title(xlab = 'Time post inoculation (hours)',
      ylab = 'Concentration (mM)', outer = TRUE, line = 3)

ssokolen/metcourse documentation built on Nov. 3, 2024, 11:22 p.m.