# NOT RUN {
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 p-value
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))
# }
Run the code above in your browser using DataLab