Learn R Programming

investr (version 1.4.0)

plotFit: Plotting Confidence/Prediction Bands

Description

Plots fitted model for an object of class "lm" or "nls" with the option of adding a confidence and/or prediction band.

Usage

plotFit(object, ...)
"plotFit"(object, 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) grey(0.7) else "black", col.pred = if (shade) 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)
"plotFit"(object, 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) grey(0.7) else "black", col.pred = if (shade) 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)
"plotFit"(object, type = c("response", "link"), interval = c("none", "confidence"), level = 0.95, data, ..., shade = FALSE, extend.range = FALSE, hide = TRUE, col.conf = if (shade) grey(0.9) else "black", border.conf = col.conf, col.fit = "black", lty.conf = if (shade) 1 else 2, lty.fit = 1, lwd.conf = 1, lwd.fit = 1, n = 500, xlab, ylab, xlim, ylim)
"plotFit"(object, data, ..., extend.range = FALSE, hide = TRUE, col.fit = "black", lty.fit = 1, lwd.fit = 1, n = 500, xlab, ylab, xlim, ylim)
"plotFit"(object, data, ..., extend.range = FALSE, hide = TRUE, col.fit = "black", lty.fit = 1, lwd.fit = 1, n = 500, xlab, ylab, xlim, ylim)

Arguments

object
An object that inherits from class "lm", "glm", or "nls".
...
Additional optional arguments passed on to plot.
interval
A character string indicating if a prediction band, confidence band, both, or none should be plotted.
level
The desired confidence level.
data
An optional data frame containing the variables in the model.
adjust
A character string indicating the type of adjustment (if any) to make to the confidence/prediction bands.
k
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".
shade
A logical value indicating if the band should be shaded.
extend.range
A logical value indicating if the fitted regression line and bands (if any) should extend to the edges of the plot. Default is FALSE.
hide
A logical value indicating if the fitted model should be plotted on top of the points (FALSE) or behind them (TRUE). Default is TRUE.
col.conf
Shade color for confidence band.
col.pred
Shade color for prediction band.
border.conf
The color to use for the confidence band border.
border.pred
The color to use for the prediction band border.
col.fit
The color to use for the fitted line.
lty.conf
Line type to use for confidence band border.
lty.pred
Line type to use for prediction band border.
lty.fit
Line type to use for the fitted regression line.
lwd.conf
Line width to use for confidence band border.
lwd.pred
Line width to use for prediction band border.
lwd.fit
Line width to use for the fitted regression line.
n
The number of predictor values at which to evaluate the fitted model (larger implies a smoother plot).
xlab
A title for the x axis.
ylab
A title for the y axis.
xlim
The x limits (x1, x2) of the plot.
ylim
The y limits (y1, y2) of the plot.
type
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.

References

Bates, D. M., and Watts, D. G. (2007) Nonlinear Regression Analysis and its Applications. Wiley.

F. Baty and M. L. Delignette-Muller (2012), A Toolbox for Nonlinear Regression in R: The Package nlstools. Journal of Statistical Software (under revision).

Examples

Run this code
#
# A nonlinear regression example
#
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