plot x and y, with optional straight line fit and display of squared residuals
Description
Plot x
and y
,
with optional fitted line and display of squared residuals.
By default the least squares line is calculated and used.
Any other straight line
can be specified by placing its coefficients in coef.model
.
Any other fitted model can be calculated by specifying the model
argument.
Any other function of one variable can be specified in the
alt.function
argument. At most one of the arguments
model
, coef.model
, alt.function
can be specified.
Usage
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16  regr1.plot(x, y,
model=lm(y~x),
coef.model,
alt.function,
main="put a useful title here",
xlab=deparse(substitute(x)),
ylab=deparse(substitute(y)),
jitter.x=FALSE,
resid.plot=FALSE,
points.yhat=TRUE,
pch=16,
..., length.x.set=51,
x.name,
pch.yhat=16,
cex.yhat=par()$cex*.7,
err=1)

Arguments
x 
x variable 
y 
y variable 
model 
Defaults to the simple linear model 
coef.model 
Defaults to the coefficients of the 
alt.function 
Any function of a single argument can be placed
here. 
main, xlab, ylab 
arguments to 
jitter.x 
logical. If 
resid.plot 
If 
points.yhat 
logical. If 
... 
other arguments. 
length.x.set 
number of points used to plot the predicted values. 
x.name 
If the 
pch 
Plotting character for the observed points. 
pch.yhat 
Plotting character for the fitted points. 
cex.yhat 

err 
The default 
Note
This plot is designed as a pedagogical example for introductory courses.
When resid.plot=="square"
, then we actually see the set of squares
for which the sum of their areas is minimized by the method of "least squares".
Author(s)
Richard M. Heiberger <rmh@temple.edu>
References
Heiberger, Richard M. and Holland, Burt (2004b). Statistical Analysis and Data Display: An Intermediate Course with Examples in SPlus, R, and SAS. Springer Texts in Statistics. Springer. ISBN 0387402705.
Smith, W. and Gonick, L. (1993). The Cartoon Guide to Statistics. HarperCollins.
See Also
resid.squares
Examples
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26  data(hardness)
## linear and quadratic regressions
hardness.lin.lm < lm(hardness ~ density, data=hardness)
hardness.quad.lm < lm(hardness ~ density + I(density^2), data=hardness)
anova(hardness.quad.lm) ## quadratic term has very low pvalue
par(mfrow=c(1,2))
regr1.plot(hardness$density, hardness$hardness,
resid.plot="square",
main="squared residuals for linear fit",
xlab="density", ylab="hardness",
points.yhat=FALSE,
xlim=c(20,95), ylim=c(0,3400))
regr1.plot(hardness$density, hardness$hardness,
model=hardness.quad.lm,
resid.plot="square",
main="squared residuals for quadratic fit",
xlab="density", ylab="hardness",
points.yhat=FALSE,
xlim=c(20,95), ylim=c(0,3400))
par(mfrow=c(1,1))
