Add a linear regression line to an existing plot. The function first
calculates predictions from an lm object and then adds the fitted
line together with optional confidence and prediction bands.
Usage
# S3 method for class 'lm'
lines(
x,
col = pal()[1],
lwd = 2,
lty = "solid",
type = "l",
n = 100,
cbandArgs = list(conf.level = 0.95),
pbandArgs = NA,
xpred = NULL,
...
)
# S3 method for class 'lmlog'
lines(
x,
col = pal()[1],
lwd = 2,
lty = "solid",
type = "l",
n = 100,
cbandArgs = list(conf.level = 0.95),
pbandArgs = NA,
xpred = NULL,
...
)Arguments
- x
linear model object as returned by
lm().- col
line color. Defaults to
pal()[1].- lwd
line width.
- lty
line type.
- type
plotting type passed to
lines().- n
number of points used for plotting the fit.
- cbandArgs
controls the confidence band. May be
TRUE,FALSE,NULL,NA, or a named list. The confidence level is specified viaconf.level. Default islist(conf.level=0.95).- pbandArgs
controls the prediction band. May be
TRUE,FALSE,NULL,NA, or a named list. The confidence level is specified viaconf.level. Default isNA.- xpred
optional numeric vector defining the range over which predictions should be calculated.
- ...
currently ignored.
Details
In contrast to abline(), polynomial models and transformed
predictors are supported as long as the model contains exactly one predictor.
Confidence and prediction bands are controlled via cbandArgs and
pbandArgs. These arguments can be:
FALSE,NULLorNA: suppress the bandTRUE: draw the band with default settingsa named list: customize the band appearance and confidence level
See also
Other graphics.trendlines:
lines.loess(),
splineCI
