met_smooth_gam: GAM smoothing

Description Usage Arguments Value Examples

View source: R/correction.R

Description

Wraps GAM smoothing function for use in bias correction algorithm.

Usage

1
met_smooth_gam(time, concentration, new.time = NULL, warn = FALSE, ...)

Arguments

time

Time or sample number for metabolite time-course.

concentration

Metabolite concentration.

new.time

Optional vector for new independent variables.

warn

The gam function uses internal warning suppression that doesn't appear to work when used in conjunction with dplyr. All warning messages are suppressed by default here. Set to TRUE to unsuppress.

...

Arguments to be passed into the s() smoothing function, such as k – the dimension of the basis used to represent the smooth term. If no additional arguments are provided, a reasonable default for k (5) is assumed.

Value

A vector of smoothed concentrations.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Simulating concave curve with 10 points
par <- c(3.5, 4.5, 2.5, 3.5, 0.0, 0.2, 0.8, 0.9)
concentration <- as.numeric(simulate_concave(1, 10, par))

# Adding noise and changing scale
concentration <- concentration * 18 + 2
abs.sd <- mean(concentration) * 0.1
concentration <- concentration + rnorm(10, 0, abs.sd)
concentration[concentration < 0] <- 0

# Original sampling time
time <- seq(0, 9, length.out=10) * 24

# New time for smoothing
new.time <- seq(0, 9, length.out=100) * 24

# Smoothing
corrected <- met_smooth_gam(time, concentration, new.time = new.time, k = 5)

# Plotting
plot(time, concentration, type='p',
     xlab='Time post inoculation (hours)', ylab='Concentration (mM)')
lines(new.time, corrected, type='l')

ssokolen/metcourse documentation built on May 30, 2019, 8:43 a.m.