# Olympic Example # Use a quadratic regression model to # fit the olympic.txt dataset; # Load data frame from disk olympic <- read.table("c:/datasets/olympic.txt", header=TRUE) # Show output and plots for simple linear model. model1 <- lm(chol ~ fat, data=olympic) cat("Summary for Simple Linear Model (model1)\n") print(summary(model1)) # Send graphs to output file. pdf("c:/datasets/olympic-graphs.pdf") p = predict(model1) r = resid(model1) plot(p, r, main="Olympic Example -- Residual Plot", sub="Simple Regression Model (model1)", xlab="Predicted Value", ylab="Residual") abline(h=0, lty="dashed", col="red") qqnorm(r, main="Olympic Example -- Normal Plot", sub="Simple Regression Model (model1)") qqline(r) # Show output and plots for quadratic linear model. fatsq <- olympic$fat ^ 2 model2 <- lm(chol ~ fat + fatsq, data=olympic) cat("Summary for Quadratic Model (model2)\n") print(summary(model2)) p = predict(model2) r = resid(model2) plot(p, r, main="Olympic Example -- Residual Plot", sub="Quadratic Model (model2)", xlab="Predicted Value", ylab="Residual") abline(h=0, lty="dashed", col="red") qqnorm(r, main="Olympic Example -- Normal Plot", sub="Quadratic Regression Model (model2)") qqline(r) dev.off( )