Updating by Bayes' rule
Good work!
The vector times
contains ten reaction time measurements. These times are assumed to be a sample from a normal curve with mean M
and standard deviation s
= 20 milliseconds. For these data, \(\bar y = 275.9\) and \(se = 6.32\).
In the editor, the vectors M
, Prior
, times
, and constants ybar
, se
are defined.
This exercise is part of the course
Beginning Bayes in R
Exercise instructions
- Use the
dnorm()
function to compute the likelihoods. - Create a data frame
bayes_df
containingM
,Prior
, andLikelihood
. - Compute the posterior probabilities using the
bayesian_crank()
function and save the result back tobayes_df
. - Use the
prior_post_plot()
function to compare the prior and posterior probabilities forM
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Define models and prior: M, Prior
M <- seq(250, 290, by = 10)
Prior <- rep(.2, 5)
# Collect observations
times <- c(240, 267, 308, 275, 271,
268, 258, 295, 315, 262)
# Compute ybar and standard error
ybar <- mean(times); n <- 10
sigma <- 20; se <- sigma / sqrt(n)
# Compute likelihoods using dnorm(): Likelihood
# Collect the vectors M, Prior, Likelihood in a data frame: bayes_df
# Use bayesian_crank to compute the posterior probabilities: bayes_df
# Use prior_post_plot() to graph the prior and posterior probabilities