Book: Gelman & Hill (2007)

From MathWiki

This is a collection of links related to Gelman & Hill (2007) "Data Analysis Using Regression and Multilevel/Hierarchical Models"

Table of contents

General links

Installing R and packages for Gelman & Hill

  • To install and get started with R see R: Getting started
  • Install the 'arm' package for the text, use the following command in R:
    > install.packages("arm")
    This also installs a number of other packages including John Fox's 'car' package.
  • To load the package when using R, use the command:
    > library(arm)

Chapter 1

The high school example given by G&H in Chapter 1 is similar to the classic example used in many introductions to multilevel modeling since Bryk and Raudenbush (1992). A version of this data set is available at

A subset of 40 schools is

To read these files into R, save them in a suitable directory on your PC as a '.csv' file, start R and give the command:

 > dd <- read.csv( file.choose() )

Section 1.2

Data sets

These are direct links to data set directories. As we go along we can organize them by chapter to make them easier to find. Note that the data sets are in a variety of formats and will require different strategies for downloading to R. There is only one data frame preloaded in 'library(arm)'. Perhaps, the reason Gelman & Hill haven't provided convenient .csv files for all their data is to help readers learn how to convert everyday data into a form that can be analyzed in R.

  • academy.awards (http://www.stat.columbia.edu/~gelman/arm/examples/academy.awards)
  • age.guessing (http://www.stat.columbia.edu/~gelman/arm/examples/age.guessing)
  • arsenic (http://www.stat.columbia.edu/~gelman/arm/examples/arsenic)
  • beauty (http://www.stat.columbia.edu/~gelman/arm/examples/beauty)
    • Note that most of these files are directly accessible in R from Gelman's web site. For example, to read this in, simply run:
 > file <- "http://www.stat.columbia.edu/~gelman/arm/examples/beauty/ProfEvaltnsBeautyPublic.csv"
 > beauty.data <- read.table (file, header=TRUE, sep=",")


  • beta.blockers (http://www.stat.columbia.edu/~gelman/arm/examples/beta.blockers)
  • bypass (http://www.stat.columbia.edu/~gelman/arm/examples/bypass)
  • cd4 (http://www.stat.columbia.edu/~gelman/arm/examples/cd4)
  • censoring (http://www.stat.columbia.edu/~gelman/arm/examples/censoring)
  • chicks (http://www.stat.columbia.edu/~gelman/arm/examples/chicks)
  • child.iq (http://www.stat.columbia.edu/~gelman/arm/examples/child.iq)
    • The data on children's IQ and mother's characteristics is given in the form of Stata ('.dta.) files.
    • These must be downloaded, and read using 'read.dta()' in the foreign package. (It doesn't allow reading directly from a URL.)
    • Note that variable names in Stata can have embedded underscores, so you should use 'convert.underscore=TRUE'.
 > library(foreign)
 > setwd("c:/R/SCS/seminar")
 > download.file("http://www.stat.columbia.edu/~gelman/arm/examples/child.iq/kidiq.dta", "kidiq.dta")
 > kidiq <- read.dta(file="kidiq.dta", convert.underscore=TRUE)
  • congress (http://www.stat.columbia.edu/~gelman/arm/examples/congress)
  • coop (http://www.stat.columbia.edu/~gelman/arm/examples/coop)
  • correlation (http://www.stat.columbia.edu/~gelman/arm/examples/correlation)
  • cows (http://www.stat.columbia.edu/~gelman/arm/examples/cows)
  • death.polls (http://www.stat.columbia.edu/~gelman/arm/examples/death.polls)
  • death.sentences (http://www.stat.columbia.edu/~gelman/arm/examples/death.sentences)
  • dogs (http://www.stat.columbia.edu/~gelman/arm/examples/dogs)
  • earnings (http://www.stat.columbia.edu/~gelman/arm/examples/earnings)
  • election88 (http://www.stat.columbia.edu/~gelman/arm/examples/election88)
  • electric.company (http://www.stat.columbia.edu/~gelman/arm/examples/electric.company)
  • exam (http://www.stat.columbia.edu/~gelman/arm/examples/exam)
  • girls (http://www.stat.columbia.edu/~gelman/arm/examples/girls)
  • lalonde (http://www.stat.columbia.edu/~gelman/arm/examples/lalonde)
  • lightspeed (http://www.stat.columbia.edu/~gelman/arm/examples/lightspeed)
  • mesquite (http://www.stat.columbia.edu/~gelman/arm/examples/mesquite)
  • moderation (http://www.stat.columbia.edu/~gelman/arm/examples/moderation)
  • nes (http://www.stat.columbia.edu/~gelman/arm/examples/nes)
  • olympics (http://www.stat.columbia.edu/~gelman/arm/examples/olympics)
  • pictures (http://www.stat.columbia.edu/~gelman/arm/examples/pictures)
  • pilots (http://www.stat.columbia.edu/~gelman/arm/examples/pilots)
  • police (http://www.stat.columbia.edu/~gelman/arm/examples/police)
  • pollution (http://www.stat.columbia.edu/~gelman/arm/examples/pollution)
  • pyth (http://www.stat.columbia.edu/~gelman/arm/examples/pyth)
  • radon (http://www.stat.columbia.edu/~gelman/arm/examples/radon)
    • To install this data, start R in a project (aka 'working') directory, copy the files
      • cty.dat (http://www.stat.columbia.edu/~gelman/arm/examples/radon/cty.dat),
      • srrs2.dat (http://www.stat.columbia.edu/~gelman/arm/examples/radon/srrs2.dat), and
      • radon_setup.R (http://www.stat.columbia.edu/~gelman/arm/examples/radon/radon_setup.R)
      to the project directory. Run 'radon_setup.R' in R.
  • redblue (http://www.stat.columbia.edu/~gelman/arm/examples/redblue)
  • risky.behavior (http://www.stat.columbia.edu/~gelman/arm/examples/risky.behavior)
  • roaches (http://www.stat.columbia.edu/~gelman/arm/examples/roaches)
  • rodents (http://www.stat.columbia.edu/~gelman/arm/examples/rodents)
  • rsquared (http://www.stat.columbia.edu/~gelman/arm/examples/rsquared)
  • samplesize (http://www.stat.columbia.edu/~gelman/arm/examples/samplesize)
  • schools (http://www.stat.columbia.edu/~gelman/arm/examples/schools)
  • sesame (http://www.stat.columbia.edu/~gelman/arm/examples/sesame)
  • simulation (http://www.stat.columbia.edu/~gelman/arm/examples/simulation)
  • sis (http://www.stat.columbia.edu/~gelman/arm/examples/sis)
  • smoking (http://www.stat.columbia.edu/~gelman/arm/examples/smoking)
  • speed.dating (http://www.stat.columbia.edu/~gelman/arm/examples/speed.dating)
  • storable (http://www.stat.columbia.edu/~gelman/arm/examples/storable)
  • supreme.court (http://www.stat.columbia.edu/~gelman/arm/examples/supreme.court)
  • unemployment (http://www.stat.columbia.edu/~gelman/arm/examples/unemployment)