Tutorial Lectures on R

John Fox

(Department of Sociology, McMaster University)


Tokyo, November 2012

Short URL: tinyurl.com/R-Japan

The R statistical computing environment has become the de-facto standard among statisticians for writing statistical software, and has made substantial inroads in the social sciences. R is a free, open-source implementation of the S programming language, and is available for Windows, Mac OS X, and Unix/Linux systems.  There is also a commercial implementation of S called S-PLUS, but it has been eclipsed by R.

The basic R system is developed and maintained by the R Core group, comprising 20 members, many of them eminent in the field of statistical computing.  The R Project for Statistical Computing is a project of the R Foundation, whose membership includes the R Core group and several other individuals.

I recommend using R through R Studio, a free, open-source interactive development environment (IDE) specifically designed for R. I have prepared some notes on installing R and R Studio.


These tutorial lectures deal with three essentially unrelated topics:

Structural Equation Modeling in R with the sem Package

path diagram

Structural equation models (SEMs) are multi-equation regression models. Unlike the more traditional multivariate linear model, however, the response variable in one regression equation in a SEM may appear as a predictor in another equation, and variables in a SEM may influence one-another reciprocally, either directly or through other variables as intermediaries. This tutorial will describe how to use the sem package for R to fit a variety of linear structural equation models to data, including general structural equation models with latent variables.

The sem package was written by John Fox, Zhenghua Nie, and Jarrett Byrnes.

Visualizing Regression Models in R with the effects Package

effect plot

Complex regression models (such as linear models with regression splines or interactions, and generalized linear models for categorical responses) can be difficult to comprehend simply from an examination of the estimated regression coecients. Effect displays are graphs or tables of fitted values under a model, selected judiciously to explicate how the explanatory variables in the model combine to influence the response variable. This tutorial will introduce effect displays for linear and generalized linear models, including models for polytomous (multi-category) categorical responses and mixed-effects models. I will show how a variety of effect displays can be constructed automatically using the effects package for R.

The effects package was written by John Fox, Sanford Weisberg, and Jangman Hong.

Writing R Commander Plug-in Packages

R Commander

The R Commander is a graphical user interface (GUI) to R, written as a standard R package: the Rcmdr package. The Rcmdr uses the facilities of the tcltk package, which provides a bridge from R to the Tcl/Tk GUI toolkit, and which is a standard part of the R distribution. The Rcmdr therefore runs on all of the platforms (Windows, Mac OS X, Linux/Unix) on which R is available.

The Rcmdr package is limited in scope, providing a point-and-click interface to basic and intermediate-level statistical methods, including linear and generalized linear models. One of the features of the Rcmdr, however, is extensibility via "plug-in" packages. Rcmdr plug-ins are standard R packages that extend the Rcmdr interface to incorporate additional menus, menu items, dialogs, and possibly classes of statistical models; Rcmdr plug-ins even can modify the standard Rcmdr menus. A number of Rcmdr plug-in packages are currently available on CRAN (the R package archive).

This tutorial will firrst introduce and demonstrate the R Commander, and then, using the RcmdrPlugin.survival package (an Rcmdr plug-in for survival analysis) as an example, will explain how to write Rcmdr plug-ins.

Tutorial Materials

Topic Materials
The sem package for Structural Equation Modeling
Structural Equation Modeling in R with the sem Package, script, slides
The effects package for effect displays "Effect Displays in R for Generalised Linear Models", "Effect Displays in R for Multinomial and Proportional-Odds Logit Models: Extensions to the effects Package", script, slides
The R Commander and Plug-Ins

Getting Started With the R Commander, R Commander website, "Extending the R Commander by 'Plug-In' packages", "The RcmdrPlugin.survival Package: Extending the R Commander Interface to Survival Analysis", RcmdrPlugin.survival source package