11.1: Basic Probability Calculations

Statistical Thinking for the 21st Century · LibreTexts

0%

Contents

    Text

    Size
    100%
    Theme
    Typeface
    Line length
    Spacing

    From LibreTexts, under CC BY-NC 4.0, as the source states it; its equations are written in TeX, which the PDF shows typeset. This page at LibreTexts.

    11.1: Basic Probability Calculations

    Let’s create a vector of outcomes from one to 6, using the seq() function to create such a sequence:

    outcomes <- seq(1, 6)
    outcomes
    ## [1] 1 2 3 4 5 6

    Now let’s create a vector of logical values based on whether the outcome in each position is equal to 1. Remember that == tests for equality of each element in a vector:

    outcome1isTrue <- outcomes == 1 
    outcome1isTrue
    ## [1]  TRUE FALSE FALSE FALSE FALSE FALSE

    Rememer that the simple probability of an outcome is number of occurrences of the outcome divided by the total number of events. To compute a probability, we can take advantage of the fact that TRUE/FALSE are equivalent to 1/0 in R. The formula for the mean (sum of values divided by the number of values) is thus exactly the same as the formula for the simple probability! So, we can compute the probability of the event by simply taking the mean of the logical vector.

    p1isTrue <- mean(outcome1isTrue)
    p1isTrue
    ## [1] 0.17

    This page titled 11.1: Basic Probability Calculations was last modified on Mon, 11 Jan 2021 05:13:37 GMT and is shared under a CC BY-NC 4.0 license and was authored, remixed, and/or curated by Russell A. Poldrack via source content that was edited to the style and standards of the LibreTexts platform.