# 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)
if (FALSE) {
mod2 <- fitFOM(s9, n.pool = 2, time.name = 'time.d', resp.name = 'cvCH4', method = 'LM')
mod2$summ
}
# 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')
Run the code above in your browser using DataLab