6.13 Summary of important R code

The main components of the R code used in this chapter follow with the components to modify in lighter and/or ALL CAPS text where y is a response variable, x is an explanatory variable, and the data are in DATASETNAME.

  • pairs.panels(DATASETNAME, ellipses=F, scale=T, smooth=F, col=0)

    • Requires the psych package.

    • Makes a scatterplot matrix that also displays the correlation coefficient.

  • cor(y~x, data=DATASETNAME)

    • Provides the estimated correlation coefficient between \(x\) and \(y\).
  • plot(y~x, data=DATASETNAME)

    • Provides a scatter plot.
  • scatterplot(y~x, data=DATASETNAME, smooth=F)

    • Requires the car package.

    • Provides a scatter plot with a regression line.

  • MODELNAME <- lm(y~x, data=DATASETNAME)

    • Estimates a regression model using least squares.
  • summary(MODELNAME)

    • Provides parameter estimates and R-squared (used heavily in Chapter ?? and ?? as well).
  • par(mfrow=c(2, 2)); plot(MODELNAME)

    • Provides four regression diagnostic plots in one plot.