rmcelreath / statrethinking_winter2019

Statistical Rethinking course at MPI-EVA from Dec 2018 through Feb 2019
2.02k stars 392 forks source link

Code inconsistency #26

Open mcol opened 5 years ago

mcol commented 5 years ago

The two following code blocks are meant to be the same example with different values in the likelihood. However, variable names are different (prob_p -> prior, prob_data ->likelihood), and in the call to samples() the order of parameters is different.

R code 3.2

p_grid <- seq( from=0 , to=1 , length.out=1000 )
prob_p <- rep( 1 , 1000 )
prob_data <- dbinom( 6 , size=9 , prob=p_grid )
posterior <- prob_data * prob_p
posterior <- posterior / sum(posterior)

R code 3.3:

samples <- sample( p_grid , prob=posterior , size=1e4 , replace=TRUE )

R code 3.11:

p_grid <- seq( from=0 , to=1 , length.out=1000 )
prior <- rep(1,1000)
likelihood <- dbinom( 3 , size=3 , prob=p_grid )
posterior <- likelihood * prior
posterior <- posterior / sum(posterior)
samples <- sample( p_grid , size=1e4 , replace=TRUE , prob=posterior )