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

Chapter 10.1.1: plot of shape and entropy #39

Closed hamedbh closed 2 years ago

hamedbh commented 2 years ago

I think the issue with the slope looking different to that in the book is because you're computing entropy with a grid approximation. When I used the exact formula for the entropy of the generalised normal distribution (also on the Wikipedia page) I got something that looked much more like the book. Here's my code (my styling is slightly different to yours as I'm sticking more closely to the book's look, although I like the Studio Ghibli palette):

tibble(beta = seq(1, 4, length.out = 100)) %>% 
  mutate(alpha = solve_for_alpha(beta)) %>% 
  mutate(entropy = (1 / beta) - log((beta) / (2 * alpha * gamma(1 / beta)))) %>% 
  ggplot(aes(beta, entropy)) + 
  geom_line(colour = "steelblue") + 
  geom_vline(xintercept = 2, linetype = 2, colour = "grey50") + 
  scale_x_continuous("shape", breaks = seq(1, 5, by = 0.5))

I only noticed the difference because I was originally computing entropy on a grid as well, but a much finer one. When I got much higher values for the entropy than the book it got me digging around to figure out why. image

ASKurz commented 2 years ago

You're right, that's the solution. Thanks! @hamedbh, I would like to thank you in the text. What name should I use?

hamedbh commented 2 years ago

It’s Hamed Bastan-Hagh.