enzKinet2 simulates, fits and plots models of enzyme and binding kinetics. This page walks through a whole analysis with the Michaelis-Menten model: draw the model’s curve, simulate an experiment, fit the model, and check the fit. The other models work the same way.
Install
enzKinet2 isn’t on CRAN. Install it from GitHub, then load it:
# install.packages("remotes")
remotes::install_github("damacer/enzKinet2")Models are named by short codes
Every function takes a model code as its first argument, such as
"MM" for Michaelis-Menten or "CI" for
competitive inhibition. The model registry lists each
model’s parameters and variables:
VALID_MODELS
#> [1] "MM" "MMSI" "OGMM" "ALTMM" "CI" "UCI" "NCI" "MI" "TC"
#> [10] "HILL" "PP" "BK" "BKH" "QBK"
MODEL_PARAMETERS[["MM"]]
#> [1] "Km" "Vmax"
MODEL_VARIABLES[["MM"]]
#> [1] "A" "V"Michaelis-Menten has two parameters, Km and
Vmax, and two variables: the substrate concentration
A and the rate V. Data for this model is a
data frame with columns A and V. The model gallery has every model’s
equation.
Draw a curve
make_curve() computes a model’s curve from parameter
values, and make_plot() draws it. Here Km is 0.8 mM and
Vmax is 12 µM/min:
params <- list(Km = 0.8, Vmax = 12)
curve <- make_curve("MM", params, x.min = 0, x.max = 6)
make_plot("MM", curve.df = curve, x.units = "mM", y.units = "µM/min")
Simulate an experiment
simulate_data() picks substrate concentrations, computes
the rate at each, and adds random noise. This simulates 8 concentrations
from 0.1 to 6 mM in duplicate, with noise of 5% of each rate:
set.seed(42)
data <- simulate_data("MM", params, x.min = 0.1, x.max = 6,
n.samples = 8, n.replicates = 2, noise.level = 0.05)
head(data)
#> A V
#> 1 0.1000000 1.424731
#> 2 0.9428571 6.308508
#> 3 1.7857143 8.437760
#> 4 2.6285714 9.491117
#> 5 3.4714286 9.949640
#> 6 4.3142857 10.069191set.seed() makes the noise reproducible. Your own data
works the same way, as long as it has the model’s columns: see Using your own data.
Fit the model
fit_model() estimates the parameters by nonlinear least
squares. It needs starting values, which don’t have to be accurate, just
in the right region:
fit <- fit_model("MM", data, start.params = list(Km = 1, Vmax = 10),
get.conf.int = TRUE, get.stats = TRUE)
fit$fitted.params
#> $Km
#> [1] 0.7812223
#>
#> $Vmax
#> [1] 12.14617
#>
#> $Km.lb
#> [1] 0.6021664
#>
#> $Km.ub
#> [1] 1.002085
#>
#> $Vmax.lb
#> [1] 11.50512
#>
#> $Vmax.ub
#> [1] 12.87767The estimates are close to the true values (Km = 0.8, Vmax = 12).
Km.lb and Km.ub are the lower and upper bounds
of the 95% confidence interval for Km, and likewise for Vmax.
fit$statistics holds the standard errors and fit
statistics:
str(fit$statistics)
#> List of 10
#> $ Km.se : num 0.0932
#> $ Vmax.se : num 0.32
#> $ R2 : num 0.982
#> $ RMSE : num 0.392
#> $ MAE : num 0.292
#> $ AIC : num 21.5
#> $ BIC : num 23.8
#> $ Log.likelihood : num -7.73
#> $ Confidence.level: num 0.95
#> $ CI.method : chr "profile"If a fit fails, fit$fitted.params is NULL
and fit$error says why. Fitting models covers this, and the
other options.
Plot the fit
Pass the fitted parameters to make_curve(). With
conf.int = TRUE it also computes a parameter uncertainty
envelope from the confidence intervals, which make_plot()
shades:
fitted_curve <- make_curve("MM", fit$fitted.params, x.min = 0, x.max = 6, conf.int = TRUE)
make_plot("MM", data.df = data, curve.df = fitted_curve, conf.int = TRUE,
x.units = "mM", y.units = "µM/min")
Check the residuals
The residuals are the data minus the fitted curve. Residuals from a good fit scatter around zero with no pattern:
make_residual_plot("MM", fit$fitted.params, data, x.units = "mM", y.units = "µM/min")
Try other plots
Linearised plots, such as the Lineweaver-Burk plot, are one
plot.transformation away. The curve is transformed with the
data, so you still see the fitted model:
make_plot("MM", data.df = data, curve.df = make_curve("MM", fit$fitted.params, x.min = 0.1, x.max = 6),
plot.transformation = "lineweaver", x.units = "mM", y.units = "µM/min")
Every plot is a ggplot object, so you can change it further with ggplot2.
Next steps
- Simulating data, Fitting models and Plotting cover each step in depth.
- Using your own data shows how to read and prepare your measurements.
- The worked examples go further, from telling inhibition types apart to designing an experiment.
- The function reference documents every argument.
- EKA2 does all of this in your browser, without code.
