Plots the residuals of data from a model with given parameter values (the observed minus the predicted dependent variable) against the primary independent variable. Residuals from a good fit scatter evenly around zero. A pattern suggests that the model doesn't describe the data.
Usage
make_residual_plot(
model,
params,
data.df,
x.max = NULL,
x.label = NULL,
y.label = NULL,
x.units = NULL,
y.units = NULL,
title = NULL,
zero.line = TRUE,
legend.label = NULL,
palette = "Set1",
hide.legend = FALSE,
y.range = NULL,
show.grid = FALSE
)Arguments
- model
The model's code, one of VALID_MODELS, e.g.
"MM".- params
A named list of the model's parameter values, each greater than 0, usually
fit_model()$fitted.params. Other elements, such as confidence bounds, are ignored.- data.df
The data, a data frame with the model's variables as columns.
- x.max
Extends the x-axis to at least this value (more than 0). The axis always starts at 0 and covers all the data. Default
NULL.- x.label, y.label
Axis labels to use instead of the defaults. Units are still added.
- x.units, y.units
The units of the x variable and of the residuals, e.g.
"mM", added to the axis labels.- title
A plot title to use instead of the default (the model's name followed by "Residuals").
- zero.line
If
TRUE(default), draw a dotted line at zero.- legend.label
A legend title to use instead of the default (the extra variable's name).
- palette
A ColorBrewer palette from PLOT_COLOUR_PALETTES (default
"Set1").- hide.legend
If
TRUE, hide the legend. DefaultFALSE.- y.range
The y-axis limits, a numeric vector of two values. By default the axis is centred on zero and just covers the largest residual.
- show.grid
If
TRUE, draw grid lines. DefaultFALSE.
See also
fit_model() for parameter estimates, make_plot() for the data
and curve.
Examples
set.seed(1)
mm <- simulate_data("MM", list(Km = 0.5, Vmax = 2), x.min = 0.1, x.max = 5,
n.samples = 8, n.replicates = 3)
fit <- fit_model("MM", mm, start.params = list(Km = 1, Vmax = 1))
make_residual_plot("MM", fit$fitted.params, mm)
# Parameter values that don't fit leave a pattern
make_residual_plot("MM", list(Km = 1.5, Vmax = 2.4), mm)
