fit_b_spline: B-spline fit

View source: R/detection.R

fit_b_splineR Documentation

B-spline fit

Description

Wraps bSpline function for use in bias detection and correction algorithm.

Usage

fit_b_spline(x, concentration, ...)

Arguments

concentration

Metabolite concentration.

...

Arguments to be passed into the bSpline() function, such as knots – "The internal breakpoints that define the spline" and degree – "Non-negative integer degree of the piecewise polynomial". If no additional arguments are provided, a reasonable default for is assumed.

time

Time or sample number for metabolite time-course.

Value

A vector of fit concentrations.

Examples

# 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 sample time
time <- seq(0, 9, length.out=10) * 24


# Fitting
fit <- fit_b_spline(time, concentration,
                              knots = c(0.5), degree = 2)

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

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