Note: To the best of my knowledge, the errors listed in the "first printing errata" section below were all corrected in the second printing, although I haven't checked myself … the "errata in the second printing" are not new errors introduced in the second printing, but ones discovered after the second printing and hence not yet corrected.
Errata in the second printing
Significant
- p. 45: attach(SeedPred) is needed before the code on pp. 45-46 (if I publish a second edition I won't use attach() at all …
- p. 46: caption to figure 2.5: plot.CI=TRUE should be plot.ci=TRUE
- p. 61: In the text below the second chunk, dat_25[-(40:44),] should be dat_25[,-(40:44)] (i.e. we mean to remove columns 40-44, not rows 40-44) (Wessel Nieuwland)
- p. 66, first line of code: should subtract 1 to convert from row indices to numbers available, i.e. avail = row(t1)[t1>0] - 1 rather than avail = row(t1)[t1>0] (Tomas Stevens)
- p. 151:
y_det=a[g]/(b[g]+x)
Should be:
y_det=a[g]*b[g]/(b[g]+x)
(Michael Folkes)
- p. 155: there are a couple of inconsistencies within the text, and between the text and code, in the third full paragraph describing the crowding index. The ambiguity is in whether $C$ (in text) and ci are the same, and whether they include the self-competition term (added 1) or not. If we take the definition of the crowding index as $C = 1 + c_{pp} n_{p} + c_{vp} n_{v} = 1 + 3 n_p$, then the shape parameter of the Gamma distribution should be specified as $m/C$ rather than $m/(1+C)$, and accordingly in the code:
ci = 1 + nbrcrowd*3
...
Mass_det = m/ci
(Tomas Stevens)
- p. 160: the p-value and power values on this page only make sense if the standard deviation is set to 8 (i.e. set a=2, b=1, sd=8, N=20) before running the code on this page) (Xu/"dipterocarpaceae")
- p. 172-174: predation rate (number killed) and number surviving are mixed up in this section. In order for everything to make sense, either replace
k = x$surv
in the last chunk with
k = x$density - x$surv
and accept the corresponding changes in the estimated probability from 0.75 to 0.25, or change "predation probability" to "survival probability" and "number killed" to "number surviving" throughout the text (Jesse Brunner)
- p. 186, last code chunk (inits = …: in the initial parameters for the third chain, b=0 should be b=0.4 instead (Jennyffer Cruz Bernal, also reported by Etienne Laliberté)
- p. 209: The text refers to lprob.10 and lprob.theta, which are not in the model presented. Text should read: (The highly significant $p$-values for the intercept terms lprob.(Intercept) and ltheta.(Intercept) are not biologically significant: …) (Brett Sandercock)
- p. 217: I'm not sure whether this counts or not, but in order to reproduce Figure 5.6 you need this batch file (Erwin Brunio)
- p. 232: the metropSB call
MSBfit = metropSB(fn = gammaNLL2, start = c(20, 0.05), nmax = 2500)
won't work unless you first redefine gammaNLL2 as
gammaNLL2 = function(p) {
-sum(dgamma(myxdat$titer,shape=p[1],scale=p[2],log=TRUE))
}
(i.e., it takes a vector of parameters as a single argument, rather than a list of arguments as defined on pp. 184-185)
- p. 236: Furthermore, I don't know exactly what happened, perhaps MCMCmetrop1R got more sensitive to NAs, but the MCMCmetrop1R chunk on this page no longer works. The function below just sets the result to be really bad when the results are NA … the other (perhaps more sensible) way to do this would be to fit the log-shape and log-scale parameters, so that they never became negative and caused NAs).
library(emdbook)
library(MCMCpack)
data(MyxoTiter_sum)
myxdat = subset(MyxoTiter_sum,grade==1)
gammaNLL2B = function(p) {
v <- sum(dgamma(myxdat$titer,shape=p[1],scale=p[2],log=TRUE))
if (!is.finite(v)) v <- -20000
v
}
m3 <- MCMCmetrop1R(gammaNLL2B,theta.init=c(shape=20,scale=0.2),
thin=30,mcmc=30000,
optim.lower=rep(0.004,2),
optim.method="L-BFGS-B",tune=3)
colnames(m3) = c("shape","scale")
- pp. 352, 356: the book refers to a data set y.procobs2 which is generated in the underlying code for the book but not explicitly referred to in the text: this code is available on the book website, but I'm reproducing a slightly more compact version here for convenience.
simlogistdata = function(seed=1001,
r=1,K=10,n0=1,t0=1,tot.t=10,dt=0.5,
sd.proc=1,sd.obs=1) {
if (!is.null(seed)) set.seed(seed)
tvec = seq(1,tot.t,by=dt)
n=length(tvec)
y = numeric(n)
ydet=numeric(n)
y[1] = n0
ydet[1] = n0
e.proc = rnorm(n,mean=0,sd=sd.proc)
e.obs = rnorm(n,mean=0,sd=sd.obs)
for (i in 2:n) {
ydet[i] = ydet[i-1]+r*ydet[i-1]*(1-ydet[i-1]/K)*dt
y[i] = y[i-1]+(r*y[i-1]*(1-y[i-1]/K)+e.proc[i-1])*dt ## process only
}
y.procobs = y+e.obs
y.obs = ydet+e.obs
cbind(tvec,y.procobs)
}
newdata2 = simlogistdata(tot.t=100,sd.proc=sqrt(0.5),sd.obs=sqrt(0.5),
n0=3,r=0.25,seed=1002,dt=1)
y.procobs2 = newdata2[,2]
(Saang-Yoon Hyun)
- p. 361: On the third-to-last line of the nlkflik function, Nobs = y.procobs2 should be Nobs = obs.data instead (Elizabeth Crone)
Minor, or merely typographical
- p. 48, last line: survprop should be propsurv
- p. 123: in summary of Poisson distribution, the range description uses $0 \le x$ while the distribution uses $n$ for the index. Should be consistent (probably both $x$)? (Toshi Okuyama)
- p. 145: display equations. Notation in the second equation is bad: it should read something like $\mbox{Prob}(x|x > 0) = (1 - p_z )P(x)$ (technically, $\mbox{Prob}(x>0) = 1-\mbox{Prob}(x=0)$). While I'm at it, I would change the first equation to $\mbox{Prob(x=0)} = p_z + (1 - p_z )P(0)$ (Toshinori Okuyama)
- p. 173: second paragraph, "exponentiate the minimum negative log-likelihood that optim returns to get the maximum likelihood:" (delete "log-" before the final word) (Andrew Edwards)
- p. 204 Para 3. l. 3, and (p. 205) caption of figure 6.16 (l. 2): Ricker should be $a x e^{-bx}$ rather than $a e^{-bx}$ (Andrew Edwards)
- p. 273 2 lines below last code chunk on the page: "size-predation" should be "density-predation" (Michael Gilchrist)
- p. 379: in Ripley (2004), the third editor should be "Hand", not "Haud"
- p. 420: Table 4.1, "Continous" should be "Continuous" (Richie Erickson)
Errata in the first printing
Significant or confusing errors
- p. 36: as pointed out by Francois Teste, species is the third and not the second column of the SeedPred data set, hence the first two code chunks and intervening text should read:
> SeedPred[[3]]
> SeedPred[["species"]]
> SeedPred$species
all extract the third column (a factor containing species abbreviations) from the
data frame SeedPred. You can also treat the data frame as a matrix and use square
brackets [] to extract the third column:
> SeedPred[, 3]
i.e., replace all references to the second column with references to the third column.
- p. 42: the second mosaicplot example should be mosaicplot(available~taken,data=SeedPred) (rather than available+taken). It's also potentially useful to do mosaicplot(available~taken,data=SeedPred,subset=taken>0) (Francois Teste)
- p. 44: in the caption, barplot(t(log10(t1+1)), beside = FALSE) should be …beside = TRUE) (Francois Teste)
- pp. 45-46: this example does not work as written in R 2.7.x (but does work in R 2.6.x, 2.8.x, and presumably later versions). The change is listed in the R NEWS file as:
o co[rv](use = "complete.obs") now always gives an error if there are no complete cases: they used to give NA if method = "pearson" but an error for the other two methods. (Note that this is pretty arbitrary, but zero-length vectors always give an error so it is at least consistent.)
The effects of this change are discussed here and here; in short, it means that (e.g.) sd(c(NA,NA,NA),rm.na=TRUE) gives an error rather than returning NA. In turn, that breaks the first code chunk (computing the standard deviations) on p. 46, because the observations with zero seeds available all have taken/available equal to NA. To fix this, I would replace the first code chunk on p. 45 with something like:
detach(SeedPred)
nz = subset(SeedPred,avail>0)
attach(nz)
frac.taken = taken/available
and then detach(nz) at the end of p. 46 (the first code chunk on p. 47 also becomes redundant in this case). (Thanks to Nicole Gottdanker.) [update 16 Sep 2008: it now looks as though R will revert to the original behavior in version 2.8.0. On the other hand, the replacement code here is slightly nicer.]
- p. 68: Before plotting init.dens against surv.dens, you have to define them: in the code for chapter 2 this was actually done (invisibly) in the code for Figure 2.9 (search for "chunk number 39" in the R code) as:
init.dens = init/area*1000
surv.dens = surv/area*1000
(Thanks to Jack Finn.)
The factors of 1000 are for scaling from per cm^2 to per 0.1 m^2.
- p. 82, "plot$x/y$ against $y$" should be "plot$x/y$ against $x$" (Martin Schlather)
- p. 87, polynomial examples under "Cubics": $\sum_i^n a_i x_i$ should be $\sum_i^n a_i x^i$ (Martin Schlather)
- p. 97, von Bertalanffy curve (figure and text): the expression for the generalized von Bertalanffy function should be
(not $a (1-\exp(-k(a-d)(t-t_0)))^{\frac{1}{1-d}}$ as stated) — see Essington et al 2001. I could have sworn I checked this …
- p. 105 (after eq 4.2.2): $\mbox{Prob}(A)=\mbox{Prob}(A|B) + \mbox{Prob}(A|\mbox{not } B)$ should be $\mbox{Prob}(A)=\mbox{Prob}(A|B) \mbox{Prob(B)} + \mbox{Prob}(A|\mbox{not } B) \mbox{Prob}(\mbox{not } B)$ (Martin Schlather)
- p. 120: range for the beta-binomial distribution should be [0,N], not [0,8] (Duncan Menge)
- p. 121: 2 and 3 lines from end of page: "samples per trial" should read "trials per sample" (twice, in two successive sentences (Will White).
- p. 160: there is a missing code chunk before the examples here, which defines the values of the variables for the simulation:
x = 1:20
a =2; b=1; sd=8
N = 20
(You can check this out in the chapter 5 code; search for "chunk number 31".) Thanks to Gavin Simpson.
- p. 174: the footnote gives a p-value of 0.22 for a maximum log-likelihood lower than -7.57 when simulating 4 trials of 10 tadpoles each with per-capita mortality probability 0.75. I did the wrong calculation … the right answer if we do unrestricted simulation is 0.124. Arguably, one could also ask about the probability of a maximum log-likelihood lower than the observed value given that 30/40 tadpoles were eaten; the answer in this case would be 0.54. More detail is given here (Aaron Ellison).
- p. 183: End of first line should be "using a numeric vector p=${a,h}$" (rather than {a,s}) [Jeanne DeNoyer]
- p. 183: The first code chunk should read
> binomNLL2 = function(params, N, k) {
+ a = params[1]
+ h = params[2]
+ predprob = a/(1 + a * h * N)
+ -sum(dbinom(k, prob = predprob, size = N, log = TRUE))
+ }
[The first function argument given in the book is p rather than params.] (Barney Luttbeg)
- p. 186: BUGS code is wrong (got out of sync with what is included in the emdbook package). You can find the real file by invoking
system.file("BUGS","myxo1.bug",package="emdbook")
which will show you
model {
for (i in 1:n) {
mean[i] <- a*day[i]*exp(-b*day[i])
rate[i] <- shape/mean[i]
titer[i] ~ dgamma(shape,rate[i])
}
## priors
a ~ dgamma(0.1,0.1)
b ~ dgamma(0.1,0.1)
shape ~ dgamma(0.1,0.01)
}
(the mistake is a confusion between the rate and scale parameterizations of the Gamma distribution, as warned about directly below this example on p. 186!) (Thanks to Mike Meredith.)
- p. 190 and 191: figure captions are switched between 6.8 and 6.9! (This one is really unfortunate because I told PUP about this in the copy-editing process — not my fault!) Also, on p. 188, last line, figure reference should be to Figure 6.8 (this one was my fault.) (Thanks to Mike Meredith.)
- p. 239-240: should have used = rather than <- for assignment in R in the code chunks on these two pages
- p. 249: $p_i = \exp(y_i )/(1 + \sum \exp (y_i ))$ should be $p_i = \exp(y_i )/(1 + \sum_{j=1}^{n-1} \exp (y_j ))$ (need proper "dummy variable" for summation) (Fernando Miguez)
- p. 264: the first displayed equation should be
(there was a missing set of parentheses in the denominator). Thanks to Fernando Taboada.
- p. 317: not quite an error, but: in the last paragraph the notation would really be much clearer if we replaced $P_{BL}(B,L) dB$ (the probability that a plant found at light level $L$ will have a biomass between $B$ and $B+dB$) by $P_{BL}(B|L) dB$. This notation would make it clearer that $P_{BL}$ is meant to be a conditional probability density … (Ian Carroll)
- p. 318: mle2 code should use dnbinom rather than dbinom (Barney Luttbeg)
- p. 321: eq. 10.3.2: $(-x-\mu)^2$ should be $-(x-\mu)^2$ (another one that's not my fault!) (Mike Meredith again.)
- p. 366: eq. A.7.1. should indicate that the derivatives are evaluated at the expected values of the variables, i.e.
Similarly, the next display equation should have bars over the $x$ and $y$ on the right-hand side
(4)The next line should say "A similar form holds for the coefficient of variation (CV): …"
(Martin Schlather)
- l. 366, l. -3 should say "then A can be multiplied on the left by B (i.e. BA is well-defined)". (Martin Schlather)
Minor glitches
- p. 2: Sandin and Pacala 2005b should be just Sandin and Pacala 2005 (Eric Walters)
- p. 3, footnote 1: spurious "a" after "to" ("I wanted to a write a book …")
- Figure 5.1, p. 149: this figure somehow got screwed up between the galleys and the printed version :-(. The lines in the right subfigure (5.1b) got truncated/erased. The correct figure looks like this:
- p. 175: "just very much" should be "just"
- p. 193 (l. -3): "the a values below the maximum" should be "the $a$ values below the maximum" (Martin Schlather)
- p. 223 (l. -3): "is not be" should be "may not be" (John Poulsen)
- p. 248: top line, spurious "can"
- p. 269: there is a big, spurious "OR" in the middle of the page. Don't know where that came from, it wasn't in the galley proofs???
- p. 298, l. 6 "it may help you understand maximum likelihood better" (Martin Schlather)
- p. 338: Bjørnstad is missing its slash
- p. 342 l. 14 Finkenstädt is missing its umlaut
- p. 326: "Clark and Poulsen et al., 2005" should be "Clark et al., 2005"
- p. 371: Crawley 2007: repeated author, should be horizontal line instead (Eric Walters)
The score so far: