| prediction.plot {NCStats} | R Documentation |
Shows the predicted value and interval on a fitted line plot. This function is used to illustrate predictions with SLR or IVR models and to show distinctions between confidence and prediction intervals.
prediction.plot(mdl,newdata,interval="prediction",conf.level=0.95,
lty=1,lwd=3,...)
mdl |
an lm or nls object (i.e., returned from fitting a model with either lm or nls). |
newdata |
A data frame in which to look for variables with which to predict. This cannot be omitted as it is with predict. |
interval |
a string indicating whether to plot confidence (="confidence") or prediction (="prediction") intervals. |
conf.level |
a decimal numeric indicating the level of confidence to use for confidence and prediction intervals. Default is 0.95. |
lty |
a numeric indicating the type of line used for representing the intervals. See par. |
lwd |
a numeric indicating the width of line used for representing the intervals. See par. |
... |
Other arguments to the fit.plot function. For example, include legend=TRUE to include a legend on the fitted line plot for an IVR. |
This function produces a fitted line plot with both confidence and prediction bands shown. It then constructs vertical bars representing the predicted values with the corresponding interval (chosen with interval) for all observations found in newdata.
This function is only appropriate for SLR and IVR with a single quantitative covariate and two or fewer factors.
A data frame is returned that contains the number of the new observation (for comparison to the graphic that is produced), the values of the variables in newdata, and the predicted values at those observed values.
Derek H. Ogle, dogle@northland.edu
predict specifically predict.lm and fit.plot.
data(Mirex)
Mirex$year <- factor(Mirex$year)
attach(Mirex)
lm2a <- lm(mirex~weight*species)
lm3a <- lm(mirex~weight+species)
lm4 <- lm(mirex~weight)
par(mfrow=c(2,2),mar=c(3,3,2,1),mgp=c(2,0.7,0))
newdf <- data.frame(weight=c(2,10),species=c("chinook","coho"),year=c("1977","1992"))
prediction.plot(lm2a,newdf,legend=c(0,0.47))
prediction.plot(lm3a,newdf,legend=c(0,0.47))
prediction.plot(lm4,newdf)
prediction.plot(lm4,newdf,interval="c")
detach(Mirex)