Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

missing 3 small parts of code in section 19.2.1 #87

Closed
jimmyamp opened this issue Aug 10, 2019 · 1 comment
Closed

missing 3 small parts of code in section 19.2.1 #87

jimmyamp opened this issue Aug 10, 2019 · 1 comment

Comments

@jimmyamp
Copy link

jimmyamp commented Aug 10, 2019

Dear Rafael,

In the section 19.2.1 'Understanding confounding through stratification' of the online web version of the book.

Three small part of R code may be missing as below.

dat <- Teams %>% filter(yearID %in% 1961:2001) %>%
mutate(BB_strata = round(BB/G,1),
HR_per_game = HR/G,
R_per_game = R/G) %>%
filter(BB_strata >= 2.8 & BB_strata <= 3.9)

dat %>%
ggplot(aes(HR_per_game, R_per_game)) +
geom_point(alpha = 0.5) +
geom_smooth(method = "lm") +
facet_wrap(~BB_strata)

dat %>% group_by(BB_strata) %>%
summarize(slope = cor(HR_per_game, R_per_game)*sd(R_per_game)/sd(HR_per_game))

The above 3 small part of code are used to plot 3 x 4 scatter plots (HR_per_game versus R_per_game) and to show the slope of change from the original.
i.e. before showing below in the online version.

... In this case, the slopes do not change much from the original:

#> # A tibble: 12 x 2
#> BB_strata slope
#>
#> 1 2.8 1.53
#> 2 2.9 1.57
#> 3 3 1.52
#> 4 3.1 1.49
#> 5 3.2 1.58
#> 6 3.3 1.56
#> # ... with 6 more rows
...

These 3 small part of code can be found in file 'linear-models.Rmd' at
https://github.com/rafalab/dsbook/blob/master/regression/linear-models.Rmd

Please add back these 3 small part of R code in the online version of the book. Also, the PDF file of the whole book may be affected by this small issue.

Please check the online version.

If I am correct, please help us to add back these small parts of code in the next update.

Thanks in advance.

Best regards,
Jimmy

@rafalab
Copy link
Owner

rafalab commented Nov 1, 2019

In the html version of the book we don't include all the code. But you can get the code from the R markdown versions.

@rafalab rafalab closed this as completed Nov 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants