avehtari / ROS-Examples

Regression and other stories R examples
https://avehtari.github.io/ROS-Examples/
325 stars 256 forks source link

possible typo on p. 324 #87

Closed ASKurz closed 3 years ago

ASKurz commented 3 years ago

Toward the bottom of the page, we read: "in the Social Indicators Survey, 90% of African Americans but only 81% of whites report their earnings". As far as I can tell, the number should be 88% for African Americans. Here's my work:

# load the package and the data
library(tidyverse)

wave3 <- read_csv("ROS-Examples-master/Imputation/data/siswave3v4impute3.csv")

#' Set up some simplified variables to work with
na_fix <- function(a) {
  ifelse(a < 0 | a == 999999, NA, a)
}

# wrangle
wave3 %>% 
  filter(race %in% c(1, 2)) %>% 
  mutate(earnings = na_fix(rearn) + na_fix(tearn),
         race = ifelse(race == 1, "white", "black")) %>% 
  # compute
  group_by(race) %>% 
  count(is.na(earnings)) %>% 
  mutate(percent = round(100 * n / sum(n), digits = 0))
# A tibble: 4 x 4
# Groups:   race [2]
  race  `is.na(earnings)`     n percent
  <chr> <lgl>             <int>   <dbl>
1 black FALSE               355      88
2 black TRUE                 47      12
3 white FALSE               386      81
4 white TRUE                 92      19
andrewgelman commented 3 years ago

I'll assume you got this right on this and I'll make the change.