Errata

General note. R packages often change their computation algorithms, function names, and requirements. If your code doesn't work or the output doesn't match what is shown in the book, see Section 1.5.4 in the book for notes and ideas.

Specific errata and package update notes

Page Change
86-87 The X axis label refers to a different variable in the code and Figure 4.3). This could be changed in line 4 of the code block on p. 86 to read:

xlab="Prior 12 months in-store sales ($)",

instead of referring to online sales.
101 In the printed book, the code and caption for Figure 4.10 refer to cust.df$store.trans but the plot shows cust.df$store.spend. Although the lesson is the same with either variable, code to generate the plot as shown is:

plot(cust.df$distance.to.store, cust.df$store.spend)
plot(1/sqrt(cust.df$distance.to.store), cust.df$store.spend)

The .R code file for Chapter 4 is correct; this erratum applies only to the printed code.
116 The first code block should index along i.seq in the loop instead of NULL, as follows:

i.seq <- NULL
for (i in seq_along(i.seq)) { print (i) } #better
163 Add following line at beginning of first code block:

library(gpairs)  # also, install gpairs package if needed

(for print only; the available .R file is correct)
314 The call to Mclust() hangs or returns an error. This was caused by changes in the mclust package update from version 4.4 to 5.0. There are two possible workarounds:

(1) to match the book, install mclust 4.4 instead. This can be done in several ways per the general instructions here.

For example, on Mac or Linux, this can be done as follows:

old.mc <- "https://cran.r-project.org/src/contrib/Archive/mclust/mclust_4.4.tar.gz"
install.packages(old.mc, repos=NULL, type="source")

(2) alternatively, to use mclust v5 (but obtain results that differ from those in the book), add the following line before calling mclust():

mclust.options(hcUse = "SVD")
329 Add following line at beginning of first code block:

seg.rf.class <- predict(seg.rf, seg.df.test)

(for print only; the available .R file is correct)
365 To ensure that the results obtained from the simulated data match the results obtained when the data is loaded from the data file, the code block should be replaced with:

cbc.df <- read.csv("http://goo.gl/5xQObB", 
                    colClasses = c(seat = "factor", price = "factor", 
                                   choice="integer"))
cbc.df$eng <- factor(cbc.df$eng, levels=c("gas", "hyb", "elec"))
cbc.df$carpool <- factor(cbc.df$carpool, levels=c("yes", "no"))
summary(cbc.df)
369 In the printed book, the rm() line is misplaced, and should occur after the final "}" that closes the for loop:

  ...
  cbc.df <- rbind(cbc.df, conjoint.i)
}   # <-- goes here, not at end

# Tidy up, keeping only cbc.df and attrib
rm(a, i, resp.id, carpool, mu, Sigma, coefs, coef.names,
     conjoint.i, profiles, profiles.i, profiles.coded, utility,
     wide.util, probs, choice, nalt, nques)

The .R code file for Chapter 13 is correct; this erratum applies only to the printed code.
384 The output of "summary(m1.hier)" shows negative estimates for sd.seat7 and sd.price, which is incorrect because variance cannot be negative. The negative sign is an artifact of the estimation routine that mlogit() uses when reporting summary(), as of Oct 30, 2015. The command "stdev(m1.hier)" is another way to check the estimates of standard errors for the population distribution, and correctly reports them all as positive.
387 The first line of code at the top of the page should reference the model input to the function, rather than the m2.hier model object as follows:

coef.mu <- model[1:dim(coef.Sigma)[1]]

This will not affect the output of the code in the book, but it would produce an error, if the function is used with a different model.

Bug reports

What How
Report a suspected bug
Include the chapter and page, with a reproducible example.
email: cnchapman+rbug@gmail.com
or better, report to the bugs mailing list.
Join the bugs mailing list Sign up here
Check mailing list archives Bug archives