fitFOM | R Documentation |
fitFOM
(FOM is for first order model) is a flexible function for fitting first-order models to batch biogas production data, typically from a biochemical methane potential (BMP) test.
fitFOM(dat, n.pool = 1, time.name = 'time.d', resp.name = 'cvCH4',
fit.to = 'yield', method = 'Nelder-Mead', abs.err = FALSE, trans = TRUE,
init = if (n.pool == 1) c(B = 'yield', k = 0.5)
else c(B = 'yield', f = 0.5, k1 = 0.01, k2 = 0.5),
fixed = NULL, fit.last = FALSE, lower = NULL, upper = NULL, lag.phase = FALSE)
dat |
a data frame with columns for elapsed time and cumulative methane yield ("specific methane production" SMP) or another response variable. |
n.pool |
Number of substrate pools to include in the model. 1 or 2. Length-one numeric vector. |
time.name |
Name of the column in |
resp.name |
Name of the column in |
fit.to |
Should fitting be to cumulative yield ( |
method |
Method used to fit the model, i.e., to estimate best-fit parameter values.
Default of |
abs.err |
Should fitting be based on mean absolute error ( |
trans |
Should parameter values be transformed for fitting?
If |
init |
Vector of initial parameter estimates.
See defaults for elements.
For |
fixed |
Fixed parameters that should be excluded from optimization. Named numeric vector. |
fit.last |
Set to |
lower |
Optional lower parameter value limits.
Only available with some |
upper |
Optional upper parameter value limits.
Only available with some |
lag.phase |
Should the "lag phase" be excluded from fitting?
This period is defined as all observations prior to maximum average production rate.
Default of |
Use for fitting a first-order model (estimation of best-fit parameter values). Intended for extracting kinetic constants and maximum methane potential from biochemical methane potential (BMP) test measurements.
A list with parameter estimates and additional information.
Most useful elements are coefs
and coef.tab
(best-fit parameter values), summ
(a summary that includes model efficiency, error, and convergence information), and pred
(model predicted or fitted values).
Sasha D. Hafner
Hafner, S.D., Koch, K., Carrere, H., Astals, S., Weinrich, S., Rennuit, C. 2018. Software for biogas research: Tools for measurement and prediction of methane production. SoftwareX 7 205-210. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1016/j.softx.2018.06.005")}
# First use example data to generate a specific methane potential (SMP) curve
library(biogas)
data('feedVol')
data('feedSetup')
# Cumulative biogas and CH4 production
cbg <- calcBgVol(feedVol, comp = 1, temp = 0, pres = 1,
interval = FALSE, data.struct = 'wide',
id.name = 'id', time.name = 'time.d', vol.name = '1',
dry = TRUE)
# Get SMP
SMP <- summBg(vol = cbg, setup = feedSetup, time.name = 'time.d',
inoc.name = 'BK', inoc.m.name = 'm.inoc', when = 'meas',
norm.name = 'm.sub.vs', show.obs = TRUE)
# Select bottle 9
s9 <- subset(SMP, id == 9)
# Fit model
mod1 <- fitFOM(s9, n.pool = 1, time.name = 'time.d', resp.name = 'cvCH4')
# View summary
mod1$summ
# Add model predictions
s9$cvCH4.pred <- mod1$pred
# And plot
plot(cvCH4 ~ time.d, data = s9, type = 'o')
lines(cvCH4.pred ~ time.d, data = s9, col = 'red')
# Fit to rates instead
mod1b <- fitFOM(s9, n.pool = 1, time.name = 'time.d', resp.name = 'cvCH4', fit.to = 'rate')
mod1b$summ
# Try 2 pools
mod2 <- fitFOM(s9, n.pool = 2, time.name = 'time.d', resp.name = 'cvCH4')
mod2$summ
# First pool effectively ignored in the fit
# Try different method (this one required minpack.lm package)
## Not run:
mod2 <- fitFOM(s9, n.pool = 2, time.name = 'time.d', resp.name = 'cvCH4', method = 'LM')
mod2$summ
## End(Not run)
# Unfortunately, here is a big effect of method on the result!
s9$cvCH4.pred2 <- mod2$pred
plot(cvCH4 ~ time.d, data = s9, type = 'o')
lines(cvCH4.pred ~ time.d, data = s9, col = 'red')
lines(cvCH4.pred2 ~ time.d, data = s9, col = 'blue')
# Drop (exclude) lag phase
mod3 <- fitFOM(s9, n.pool = 2, time.name = 'time.d', resp.name = 'cvCH4', lag.phase = TRUE)
mod3$summ
s9$cvCH4.pred3 <- mod3$pred
lines(cvCH4.pred3 ~ time.d, data = s9, col = 'darkgreen')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.