########## R script: mitsub ########## # For doing a regression analysis of the # Mitsubishi price/age data. # Last changed: 24 SEP 2001 # Define function wait() for sending prompts # to the screen. (Very useful for scripts such # as this). wait <- function() { cat("Hit return to continue\n") ans <- readline() invisible() } # Read in data into data frame named 'mitsub' mitsub <- read.table("mitsub.dat",header=T,sep=",") price <- mitsub$price age <- mitsub$age # Obtain and print some summary statistics print(summary(mitsub)) wait() # Draw graphics hist(price) wait() boxplot(age) wait() boxplot(split(price,age)) wait() plot(age,price,pch=1) wait() # Obtain a regression fit fit <- lm(price~age,data=mitsub) # Add fitted line to plot abline(fit$coef) # Print summary of regression fit wait() print(summary(fit)) wait() # Do some diagnostic plots par(mfrow=c(2,3)) plot(fit) ########## End of mitsub ##########