knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
Even though we were trying to get everything right the first time, small errors can (and do!) slip through the cracks. Here we keep an updated list of errors and mistakes that have been gracefully pointed out to us by attentive readers.
anova(mod.linear,mod.quadratic, mod.cubic)
we write: "[...] but that the cubic model does not outperform the quadratic model, $\chi^2(1) = 0.27, p = 0.27$."smc()
that calculates the squared multiple correlation and we write that it is part of the dplyr
package. This is incorrect, as smc()
is implemented in the psych
package. library(dplyr) library(astatur) workout <- mutate(workout, healthage = health * age)
The mutate function may give an error (with recent versions of R and the dplyr
package) that it cannot compute the product of health and age, since health is of type haven_labelled
. The problem can be solved by applying the function zap_formats()
:
workout <- haven::zap_formats(workout)
country <- factor(c("Dutch", "Wales", "Scotland", "Holland", "Netherlands", "United Kingdom", "England", "Northern Ireland")) country <- fct_collapse(country, Netherlands = c("Friesland", "Holland", "Netherlands"), `United Kingdom` = c("Wales", "Scotland", "United Kingdom", "England", "Northern Ireland"))
Running this code will collapse the factor to categories "Netherlands", "United Kingdom" and "Dutch". Our intention was that category "Dutch" from the factor specification should be subsumed in the "Netherlands" category. Therefore, "Dutch" should be relabeled as "Friesland" or "Dutch" should be included in the list in the second statement using fct_collapse()
.
pivot_longer()
to convert a wide data.frame
into long format. The example is:depression.wide %>% pivot_longer(cols=starts_with("week") | starts_with("BDI"), names_to = c(".value", "session"), names_pattern="(BDI|week)([0-9+])", values_drop_na=T) %>% head()
There is a mistake in the line names_pattern="(BDI|week)([0-9+])"
. The regular expression [0-9+]
only captures a single integer and hence the code will not work as intended as values such as "BDI10" or "week12" will be coded as session=1
instead of session=10
and session=12
, respectively. The correct regular expression should be "(BDI|week)([0-9]+)"
such that the full code-example should read
depression.wide %>% pivot_longer(cols=starts_with("week") | starts_with("BDI"), names_to = c(".value", "session"), names_pattern="(BDI|week)([0-9]+)", values_drop_na=T) %>% head()
Thanks to Dan Mønster (http://au.dk/en/danm@econ.au.dk) for thoroughly reading and commenting on the book!
Thanks to Benjamin Holen Dybendal (https://www.ntnu.no/ansatte/benjamin.dybendal) for pointing out errors in the book.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.