### Code that allows you to visually examine the assumptions of regression ### Run regression - most plots require regression analysis in order to plot results=lm(Y~X,data=datum) #run a regression between Y and X # replace 'Y' with y-variable name # repace 'X' with x-variable name ### scatterplot of x-y data plot(Y~X,data=datum) #plots data # replace 'X' with X-variable name # replace 'Y' with Y-variable name abline(results) # add regression line to plot # won't work unless you've already plotted data # also won't work if you haven't run the regression ### plot of residuals plot(datum$X,residuals(results)) #or plot(residuals(results)~datum$X) # replace 'X' with X-variable name ### plot histogram of residuals hist(residuals(results)) ### plot autocorrelation function acf(residuals(results)[order(datum$X)]) # test of autocorrelation in order of X ### note that autocorrelation may exist in terms of the order the data was collected. If so: acf(residuals(results)) # replace 'X' with x-variable name