| fit_custom | R Documentation |
Fits a user-defined nonlinear model to each bottle in a rumen_gp dataset.
fit_custom(
data,
formula,
start,
lower = NULL,
upper = NULL,
model_name = "Custom"
)
data |
A rumen_gp object. |
formula |
A nonlinear model formula. |
start |
Named list of starting values. |
lower |
Optional named numeric vector of lower parameter bounds. |
upper |
Optional named numeric vector of upper parameter bounds. |
model_name |
Character string used to label the fitted model. |
This function allows researchers to fit
custom nonlinear kinetic equations using
minpack.lm::nlsLM().
Custom models integrate directly with:
summary()
plot_fit()
plot_residuals()
compare_models()
making them fully compatible with the rumenGP modeling framework.
The model formula must:
Use Gas_mL as the response variable
Use Time_h as the time variable
Include all parameters listed in
start
Example:
Gas_mL ~
A *
(
Time_h /
(
Time_h + K
)
)
Starting values are supplied through
start.
Example:
start = list( A = 150, K = 10 )
Good starting values often improve convergence and reduce fitting failures.
Optional lower and upper bounds may be supplied.
Example:
lower = c( A = 0, K = 0 ) upper = c( A = 500, K = 100 )
Bounds can improve stability and prevent biologically unrealistic parameter estimates.
Start with biologically meaningful equations
Use reasonable starting values
Apply parameter bounds when appropriate
Compare custom models against built-in models
Evaluate both fit quality and parameter interpretability
A custom_fit object containing:
Model name
Formula
Starting values
Parameter bounds
Parameter estimates
Model diagnostics
Predicted values
Residuals
fit_groot,
fit_mm,
compare_models,
plot_fit,
plot_residuals
files <- example_data()
raw_data <- read_ankom(
files$ankom
)
metadata <- read_metadata(
files$metadata
)
gp <- process_ankom(
raw_data,
metadata,
headspace_ml = 210,
temperature_c = 39
)
# Hyperbolic model
custom_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"
)
summary(custom_fit)
plot_fit(
custom_fit,
head = 1
)
plot_residuals(
custom_fit,
head = 1
)
# Compare with built-in models
compare_models(
Groot = fit_groot(gp),
Hyperbolic = custom_fit
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.