Page 12, Listing 1.2
Start the listing with the line
creditdata <- d.
Page 25 Listing 2.8, page 30 Listing 2.11 and any other use of H2DB
Starting with version 1.4 the H2DB database enforces that the
path specified for the database files must be absolute
(starting with "./", "/", or "~/"). The book examples were
written using 1.3 versions of H2DB which did not enforce this.
The fix is to edit the db definition xml files and R
connection commands to make sure
you have absolute paths. Use:
Pages 25 through 29 section 2.2.1 A production-sized example
We no longer recommend using H2DB, Java, and Squirrel SQL to load data. Instead we recommend using R, read.table, and dbWriteTable using either PostgreSQL (for a lot of data) or RSQlite (for in-memory practice). Nina has a write-up of the replacement screwdriver concept here.
Page 86, Table 5.1, second row, second column
The random forests cross-reference should be to section 9.1.2.
Pages 125-138, Section 6.3 Building models using many variables
We strongly recommend splitting your training set into
two pieces, and using one piece for the construction of single
variable models, and only the other disjoint portion of the training
data for model construction. The issue is any row of data examined
during single variable model construction is no longer exchangeable
with even test data (let alone future data). Models trained on rows
used to build the variable encodings tend to overestimate effect
sizes of the sub-models (or treated variables), underestimate degrees
of freedom, and get significances wrong. We think the KNN model in
this section happened to perform okay due to the aggressive variable
pruning heuristic in listing 6.11.
A rerun of chapter 6 with the stricter data separation
can be found
(including a newer run automating a lot of the steps using
library; files, of course, are in the course
Page 120, Section 6.2.1 Using categorical features
It is a good idea to harden the look-up
to defend against the irregular nature of
R's indexing operator (which would fail in this
case if we were to have
pos as a logical instead of a string).
Page 126, Section 6.2.3 Using cross-validation
First paragraph: "cross-reference" should be "cross-validation."
Page 126, Listing 6.11 Basic variable selection
Second "Run through categorical variables and pick based
on a deviance improvement" should read "Run through numerical
variables and pick based on a deviance improvement."
Page 126, Text and Listing 6.11 Basic variable selection
The "2 times" in listing 6.11 is because statistical deviance is
traditionally written as -2*(log(p|model) - log(p|saturatedModel)).
We are using a "delta deviance" or improvement of deviance given by
-2*(log(p|model) - log(p|saturatedModel)) - (-2*(log(p|nullModel) -
log(p|saturatedModel))). We wrote this as
and it is a deviance style metric (not an AIC style metric as claimed in the text,
which got behind the code zip file by one revision).
text above listing 6.11 on page 126 claims we are going to use an AIC-like metric. The original
implementation did this by subtracting a variable entropy
estimate from each liCheck in the the catVars list and subtracted 1
from each numeric variable (a placeholder). This turned out to not be
useful for the data set at hand (this is the sort of thing you do want to try variations of),
and evidently we removed it without
completely updating the text.
Corrected text, listings, and results now
and here .
Page 130, How decision tree models work
In the text explaining the decision tree
"predVar126 < -0.002810871" should read
"predVar126 < 0.07366888".
Page 146, Using categorical features, Listing 6.4
Replace "pPosWna <- (naTab/sum(naTab))[pos]" with
"pPosWna <- (naTab/sum(naTab))[as.character(pos)]" to get around
bad indexing issues due to R's treatment of logical types and expansion of vector lengths.
Page 148, Are there systematic errors?
Page 224, Footnote 5
Our description of "heteroscedasticity" is wrong and
(unintentionally) conflates a number of different negative issues.
Our intent was to expand on a simple definition such as "In
statistics, a collection of random variables is
heteroscedastic if there are sub-populations that have
different variabilities from others" (taken
Heteroscedasticity). Unfortunately we pushed this too
far (roughly saying "it is bad if errors correlate with y's"
meant to say "it was bad if errors correlate with unobserved
ideal y's which don't already have the error term added in", i.e. with functions of the x's).
The correct thing to do is state that regression
(and in particular the diagnostics of a regression) depends
on a number of assumptions about the data. Important properties
include (paraphrased from Gelman, Carlin,
Stern, Dunson, Vehtari, and Rubin "Bayesian
Data Analysis" 3rd edition pp. 369-376) model
structure, linearity of expected value of y as a function
of the x's, bias of error terms, normality of error terms,
independence of observations, and constancy of variance.
For more see
What are the key assumptions of linear regression?.
Also, the frequentest version of regression is commonly said to make no assumptions
on the distribution of data or parameters (only on distribution of errors).
This is not quite true as even the frequentest analysis depends on independence
of observations (which is a fact about x's in addition to y's and errors).
And a Bayesian treatment may need to assume some form of priors on one
or more of these to get well behaved detailed posterior estimates.
We will correct later editions of the book, and hope
our error does not overly distract from the important
lesson that you must be aware of modeling assumptions.
We do note with some amusement how rarely "Bayesian
Data Analysis" 3rd edition pp. 369-376 uses the
term "heteroscedasticity" even though these are
the pages tagged with this term in the index (these authors
rightly emphasizing concepts over naming).
Page 156, Section 7.1.5 Reading the model summary and characterizing coefficient quality
Normality of errors is desirable, but not necessary for linear regression (see
and What are the key assumptions of linear regression?). We had previously said the errors must be normally distributed (and we certainly did not mean to imply the
x need to be normally distributed).
Replace "INTERPRETING MODEL SIGNIFICANCES" with:
INTERPRETING MODEL SIGNIFICANCES
Many of the tests of linear regression, including the tests for coefficient and model significance, are sensitive to model assumptions. It's important to examine graphically or using quantile analysis to determine if the regression model is behaving as expected.
Page 157, Section 7.2.1 Understanding logistic regression
Unfortunate typo: the sigmoid function is
s(z) = 1/(1+exp(-z))
Page 180, Section 8.1.2, Preparing the data
scale() always clear attributes from result with
attr(., "scaled:center") = NULL; attr(., "scaled:scale") = NULL otherwise
predict(princ, .) does not always equal the desired projection
. %*% princ$rotation.
Page 187, Section 8.1.3, Total with sum of squares
Typo should read "The within sum of squares for a single cluster is the total squared distance ..." (not average). Code is correct.
Page 205, Section 8.1.1 Distances, Cosine Similarity
Change "Cosine similarity is a common similarity metric in text analysis. It measures the smallest angle between two vectors (the angle theta between two vectors is assumed to be between 0 and 90 degrees)." to "Cosine similarity is a common similarity metric in text analysis. It measures the smallest angle between two vectors (in our text example we assume non-negative vectors, so the angle theta between two vectors is between 0 and 90 degrees)."
Page 206, Section 8.2.3 Mining associations with the arules package, Listing 8.20
intersetMeasure now uses the argument
measure= instead of
method= (which now crashes). Switching the argument name brings the code up to date.
Page 214, Listing 9.1 Preparing Spambase data and evaluating the performance of decision trees
Bug: F1 is the harmonic mean of precision and recall:
See Page 96, Section 5.2.1 "F1" for the correct definition.
Page 230, Listing 8.17 examining the size distribution
Page 387, sqldf index entry
(Not an error) Another important cross-reference for sqldf
is page 327, where we show an option that prevents an R-crash