Session Ready
Exercise

Computing probabilities

The where9am data frame contains 91 days (thirteen weeks) worth of data in which Brett recorded his location at 9am each day as well as whether the daytype was a weekend or weekday.

Using the conditional probability formula below, you can compute the probability that Brett is working in the office, given that it is a weekday.

$$ P(A|B) = \frac{P(A \text{ and } B)}{P(B)} $$

Calculations like these are the basis of the Naive Bayes destination prediction model you'll develop in later exercises.

Instructions
100 XP
  • Find P(office) using nrow() and subset() to count rows in the dataset and save the result as p_A.
  • Find P(weekday), using nrow() and subset() again, and save the result as p_B.
  • Use nrow() and subset() a final time to find P(office and weekday). Save the result as p_AB.
  • Compute P(office | weekday) and save the result as p_A_given_B.
  • Print the value of p_A_given_B.