ASKurz / Statistical_Rethinking_with_brms_ggplot2_and_the_tidyverse_2_ed

The bookdown version lives here:
https://bookdown.org/content/4857/
Creative Commons Zero v1.0 Universal
125 stars 37 forks source link

Section 12. 4 Figure 12.8 #40

Closed icrichmond closed 2 years ago

icrichmond commented 2 years ago

Hi there, thanks so much for publishing this resource! It is an absolute life-saver when trying to work through the Statistical Rethinking course while using brms.

I am opening this issue because I think the labels on your version of Fig 12.8 in Section 12.4 may be incorrect. Perhaps I am misunderstanding the differences between the rethinking and brms packages but I think the code for the GGally paired plot should be switched from:

library(GGally)

delta_labels <- c("Elem", "MidSch", "SHS", "HSG", "SCol", "Bach", "Mast", "Grad")

posterior_samples(b12.6) %>% 
  select(contains("simo_moedu_new1")) %>% 
  set_names(str_c(delta_labels[2:8], "~(delta[", 1:7, "])")) %>% 
  ggpairs(upper = list(continuous = my_upper),
          diag = list(continuous = my_diag),
          lower = list(continuous = my_lower),
          labeller = label_parsed) +
  theme(strip.text = element_text(size = 8))

to:

library(GGally)

delta_labels <- c("Elem", "MidSch", "SHS", "HSG", "SCol", "Bach", "Mast", "Grad")

posterior_samples(b12.6) %>% 
  select(contains("simo_moedu_new1")) %>% 
  set_names(str_c(delta_labels[1:7], "~(delta[", 1:7, "])")) %>% 
  ggpairs(upper = list(continuous = my_upper),
          diag = list(continuous = my_diag),
          lower = list(continuous = my_lower),
          labeller = label_parsed) +
  theme(strip.text = element_text(size = 8))

where delta_labels are subset from 1:7 instead of from 2:8.

Thanks again for this amazing resource!

ASKurz commented 2 years ago

Hey @icrichmond, I can see your point. I actually think the plot in McElreath’s text (p. 396) is misleading and probably based on a typo in his code. The lowest educational category is Elem. Since this would be treated as the reference category for the simplex, it would be assigned delta[0]. Further, within the context of the simplex, delta[0] is not a parameter, but is fixed to zero. You can get a sense of this on page 394 in the text. If you were to base the results on McElreath’s rethinking and base-R code, I think he’d need to change his R code block on page 395 to read:

delta_labels <- c("Elem","MidSch","SHS","HSG","SCol","Bach","Mast","Grad") 
pairs( m12.6 , pars="delta" , labels=delta_labels[-1])
icrichmond commented 2 years ago

Ahhhh okay, I see what you mean and you're absolutely right - on p. 392 of the text he even says

"The first level (Elementary School) will be absorbed into the intercept. Then the first increment comes from moving Elementary School to Middle School"

I was misinterpreting because of the previous section, where on p. 383 he mentions:

"Since the largest response value always has a cumulative probability of 1, we effectively do not need a parameter for it"

Thanks so much for your response and apologies for the unnecessary issue!

ASKurz commented 2 years ago

Yep, the whole thing is very tricky. Thanks for reporting your concerns and for the kind words, above.