howtoplotresiduals-rcode

howtoplotresiduals-rcode - #Illustrating various residual...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 #Illustrating various residual plots # Model Y_i = 2 + 5*X_i + epsilon_i # Where N(0,4^2) # Fix X's from 11 to 18 set.seed(1) #This gives me the same randomly generated data every time x = runif(25,11,18) err.a = rnorm(25,0,4) y = 2 + 5*x + err.a #_____________________________________________________________________________ # Plot (a) par(mfrow=c(3,2)) #put 9 graphs on 1 page plot(x,y,main="(a) Scatter plot and regression line", cex.main=.8,pch=20,xlab="x",ylab="y") fit.a = lm(y ~ x) abline(fit.a) #_____________________________________________________________________________ # Plot (b) X vs. non-standardized residuals plot(x,fit.a$res,pch=20, main="(b) X vs. non-standardized residuals",cex.main=.8, xlab="x",ylab="Residuals") abline(h=0) # Notice that there is no discernible pattern in the residuals. # They seem to be randomly scattered about the line y=0. #______________________________________________________________________________ # Plot (c) # Change the model so that the variance increases as x increases. err.b=err.a/2
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 06/16/2009 for the course STAT 540 taught by Professor Staff during the Spring '08 term at Colorado State.

Page1 / 4

howtoplotresiduals-rcode - #Illustrating various residual...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online