
Generic function for plotting predictions from various types of fitted
models. plotFit
currently supports objects of class
lm
, glm
, and
nls
. A default method also exists which may be used for
plotting the fitted mean response from other model fits (e.g.,
lqs
and rlm
from the MASS
package).
plotFit(object, ...)# S3 method for default
plotFit(
object,
type = c("response", "link"),
interval = c("none", "both", "confidence", "prediction"),
level = 0.95,
data,
adjust = c("none", "Bonferroni", "Scheffe"),
k,
...,
shade = FALSE,
extend.range = FALSE,
hide = TRUE,
col.conf = if (shade) grDevices::grey(0.7) else "black",
col.pred = if (shade) grDevices::grey(0.9) else "black",
border.conf = col.conf,
border.pred = col.pred,
col.fit = "black",
lty.conf = if (shade) 1 else 2,
lty.pred = if (shade) 1 else 3,
lty.fit = 1,
lwd.conf = 1,
lwd.pred = 1,
lwd.fit = 1,
n = 500,
xlab,
ylab,
xlim,
ylim
)
Additional optional arguments passed on to
plot
.
The type of prediction required. The default is on the scale of
the response variable; the alternative "link"
is on the scale of the
linear predictor. This option is only used when plotting
glm
objects.
A character string indicating if a prediction band, confidence band, both, or none should be plotted.
The desired confidence level.
An optional data frame containing the variables in the model.
A character string indicating the type of adjustment (if any) to make to the confidence/prediction bands.
An integer to be used in computing the critical value for the
confidence/prediction bands. Only needed when adjust = "Bonferroni"
,
or when adjust = "Scheffe"
and interval = "prediction"
.
A logical value indicating if the band should be shaded.
A logical value indicating if the fitted regression line
and bands (if any) should extend to the edges of the plot. Default is
FALSE
.
A logical value indicating if the fitted model should be plotted
on top of the points (FALSE
) or behind them (TRUE
). Default is
TRUE
.
Shade color for confidence band.
Shade color for prediction band.
The color to use for the confidence band border.
The color to use for the prediction band border.
The color to use for the fitted line.
Line type to use for confidence band border.
Line type to use for prediction band border.
Line type to use for the fitted regression line.
Line width to use for confidence band border.
Line width to use for prediction band border.
Line width to use for the fitted regression line.
The number of predictor values at which to evaluate the fitted model (larger gives a smoother plot).
A title for the x axis.
A title for the y axis.
The x limits (x1, x2) of the plot.
The y limits (y1, y2) of the plot.
No return value (called for side effects).
Bates, D. M., and Watts, D. G. (2007) Nonlinear Regression Analysis and its Applications. Wiley.
Florent Baty, Christian Ritz, Sandrine Charles, Martin Brutsche, Jean-Pierre Flandrois, Marie-Laure Delignette-Muller (2015). A Toolbox for Nonlinear Regression in R: The Package nlstools. Journal of Statistical Software, 66(5), 1-21.
# NOT RUN {
# A nonlinear least squares example (see ?datasets::Puromycin and
# ?investr::predFit)
data(Puromycin, package = "datasets")
Puromycin2 <- Puromycin[Puromycin$state == "treated", ][, 1:2]
Puro.nls <- nls(rate ~ Vm * conc/(K + conc), data = Puromycin2,
start = c(Vm = 200, K = 0.05))
plotFit(Puro.nls, interval = "both", pch = 19, shade = TRUE,
col.conf = "skyblue4", col.pred = "lightskyblue2")
# }
Run the code above in your browser using DataLab