Building Custom Kinetic Models


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 = "#>"
)

Introduction

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:

This vignette demonstrates how to build, fit, and evaluate custom models.

library(rumenGP)

Example Dataset

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"
)

Example 1: Simple Exponential Model

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

Example 2: Hyperbolic Model

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

Example 3: Richards Model

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

Comparing Custom and Built-in Models

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

)

Visualizing Custom Models

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
)

Choosing Starting Values

Good starting values improve convergence.

Recommendations:

Example:

start = list(
  A = 120,
  k = 0.05
)

Using Bounds

Bounds can prevent unrealistic estimates.

Example:

lower = c(
  A = 0,
  k = 0
)

upper = c(
  A = Inf,
  k = Inf
)

Best Practices

When proposing a new kinetic model:

  1. Use biologically meaningful parameters.
  2. Choose reasonable starting values.
  3. Apply parameter bounds when appropriate.
  4. Compare against established models.
  5. Evaluate both fit quality and parameter interpretability.

Summary

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.



Try the rumenGP package in your browser

Any scripts or data that you put into this service are public.

rumenGP documentation built on Oct. 2, 2026, 5:09 p.m.