title: "Building Custom Kinetic Models" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Building Custom Kinetic Models} %\VignetteEngine{knitr::rmarkdown} \usepackage[utf8]{inputenc}
knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
Most rumen gas production studies rely on a predefined set of kinetic models.
However, researchers often wish to:
rumenGP provides fit_custom() for fitting
user-defined nonlinear kinetic models.
Custom models integrate directly with:
summary()plot_fit()plot_residuals()compare_models()This vignette demonstrates how to build, fit, and evaluate custom models.
library(rumenGP)
Create a simple gas-production dataset.
manual_volume <- data.frame( Bottle = c( rep(1, 10), rep(2, 10) ), Treatment = c( rep("Control", 10), rep("Corn", 10) ), Time = rep( c( 0, 2, 4, 6, 8, 12, 16, 24, 36, 48 ), 2 ), Gas = c( 0, 5, 12, 20, 28, 40, 55, 75, 90, 100, 0, 8, 18, 30, 42, 58, 72, 95, 110, 120 ) )
Convert to a rumen_gp object.
gp <- as_rumen_gp( data = manual_volume, head_col = "Bottle", treatment_col = "Treatment", time_col = "Time", gas_col = "Gas" )
Consider the equation:
[ Gas(t) = A \left( 1 - e^{-kt} \right) ]
where:
Fit the model:
exp_fit <- fit_custom( data = gp, formula = Gas_mL ~ A * ( 1 - exp( -k * Time_h ) ), start = list( A = 120, k = 0.05 ), lower = c( A = 0, k = 0 ), model_name = "Simple Exponential" )
Inspect results:
summary(exp_fit)
Estimated parameters:
exp_fit$parameters
Consider:
[ Gas(t) = A \left( \frac{t} { t + K } \right) ]
where:
Fit the model:
hyperbolic_fit <- fit_custom( data = gp, formula = Gas_mL ~ A * ( Time_h / ( Time_h + K ) ), start = list( A = 150, K = 10 ), lower = c( A = 0, K = 0 ), model_name = "Hyperbolic" )
Inspect results:
summary(hyperbolic_fit)
hyperbolic_fit$parameters
The Richards model is a flexible four-parameter sigmoidal equation.
[ Gas(t) = VF \left( 1 - b e^{-kt} \right)^m ]
where:
Fit the model:
richards_fit <- fit_custom( data = gp, formula = Gas_mL ~ VF * ( 1 - b * exp( -k * Time_h ) )^m, start = list( VF = max(gp$Gas_mL) * 1.1, b = 0.9, k = 0.05, m = 1 ), lower = c( VF = 0, b = 0, k = 0, m = 0 ), upper = c( VF = Inf, b = 1, k = Inf, m = 10 ), model_name = "Richards" )
Review diagnostics:
richards_fit$diagnostics
Review parameter estimates:
richards_fit$parameters
Custom models can be compared directly with built-in models.
Fit built-in models:
groot_fit <- fit_groot(gp) brody_fit <- fit_brody(gp)
Compare models:
compare_models( Groot = groot_fit, Brody = brody_fit, Hyperbolic = hyperbolic_fit )
Custom models support the standard visualization workflow.
Plot observed and predicted values:
plot_fit( hyperbolic_fit, head = 1 )
Plot residuals:
plot_residuals( hyperbolic_fit, head = 1 )
Good starting values improve convergence.
Recommendations:
Example:
start = list( A = 120, k = 0.05 )
Bounds can prevent unrealistic estimates.
Example:
lower = c( A = 0, k = 0 ) upper = c( A = Inf, k = Inf )
When proposing a new kinetic model:
The fit_custom() framework allows
researchers to evaluate new kinetic models
without modifying package source code.
Custom models can be:
using exactly the same workflow as built-in models.
This makes rumenGP a flexible platform for developing and evaluating novel rumen gas production equations.
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.