# Hamster Example # Predict the lifetime of a hamster from its # percent of life hibernating. Create the scatterplot, # the residual plot, and normal plot of residuals. hamster = read.table("c:/datasets/hamster.txt", header=TRUE) cat("Hamster Dataset:\n") print(hamster) cat("Simple Regression Model:\n") model = lm(hamster$Lifetime ~ hamster$Hiber) summary(model) # Send graphics output to PDF file. pdf("c:/datasets/hamster.pdf") # Create scatter plot with regression line. plot(hamster$Hiber, hamster$Lifetime, main="Hamster Example Scatterplot", xlab="Percent of Life Hibernated", ylab="Lifetime in Days") abline(model, col="red", lty="dashed") # Create residual plot. resid = resid(model) predict = predict(model) plot(predict, resid, main="Hamster Example Residual Plot", xlab="Predicted Values", ylab="Residuals") abline(h = 0, col="red", lty="dashed") # Create normal plot of residuals. qqnorm(resid, main="Hamster Example Normal Plot") qqline(resid) # Send graphics output back to screen. dev.off( )