mikexcohen / Statistics_book

106 stars 24 forks source link

Exercise 1 part B stats_ch04_descriptives.R #5

Open Finterly opened 1 month ago

Finterly commented 1 month ago

Dear Dr. Cohen,

I was working on your exercises and noticed a possible typo in the code for Exercise #1 in stats_ch04_descriptives.R

When creating figure B code staring here: https://github.com/mikexcohen/Statistics_book/blob/b442b2159002c51befa7863e4f4e90155f4819d4/R/stats_ch04_descriptives.R#L1109

The family of gaussians are not normalized so you get this

image

instead of

image

This can be possibly fixed by adding the following in the bold after line 1114: https://github.com/mikexcohen/Statistics_book/blob/b442b2159002c51befa7863e4f4e90155f4819d4/R/stats_ch04_descriptives.R#L1114

for (i in 1:N) { a <- 1 / (sigmas[i] sqrt(2 pi)) # Normalization factor eTerm <- -x ^ 2 / (2 sigmas[i] ^ 2) G <- rbind(G, a exp(eTerm)) # Include scaling factor }

mikexcohen commented 1 month ago

Thanks for your careful read, Finterly :)

The "missing" normalization is actually part of Exercise 2, although I appreciate that it is confusing not to have it part of Exercise 1 code. My apologies for the confusion, and thanks for letting me know.