Get startedGet started for free

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

View Course

Exercise instructions

  • Use the dnorm() function to compute the likelihoods.
  • Create a data frame bayes_df containing M, Prior, and Likelihood.
  • Compute the posterior probabilities using the bayesian_crank() function and save the result back to bayes_df.
  • Use the prior_post_plot() function to compare the prior and posterior probabilities for M.

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
Edit and Run Code