x<-runif(100,0,10) # generate 100 random uniforms between 0 and 10 y<-1 + 2*x + rnorm(100) # generate some y's based on a simple # linear regression model plot(x,y) # Scatter plot of the data fit<-lsfit(x,y) # Least Squares fit (regression) # Note: we are storing the results of the LS fit # in the variable fit ... it will be used in several # other steps. ls.print(fit) # Standard regression output abline(fit) # Add the regression line to the scatter plot plot(x,fit$residuals) # residual vs predictor plot abline(h=0,lty=2) # add a dashed horizontal line at y=0