Skip to content

R Stats: Introduction to Discrete Probability

Abish Pius edited this page Feb 21, 2020 · 1 revision

Discrete Probability

  • The probability of an event is the proportion of times the event occurs when we repeat the experiment independently under the same conditions.
    Pr(A)=probability of event A
  • An event is defined as an outcome that can occur when when something happens by chance.
  • We can determine probabilities related to discrete variables (picking a red bead, choosing 48 Democrats and 52 Republicans from 100 likely voters) and continuous variables (height over 6 feet).

Monte Carlo Simulations

  • Monte Carlo simulations model the probability of different outcomes by repeating a random process a large enough number of times that the results are similar to what would be observed if the process were repeated forever.
  • The sample() function draws random outcomes from a set of options.
  • The replicate() function repeats lines of code a set number of times. It is used with sample() and similar functions to run Monte Carlo simulations.

Code: Monte Carlo Simulation

beads <- rep(c("red", "blue"), times = c(2,3))    # create an urn with 2 red, 3 blue
beads    # view beads object
sample(beads, 1)    # sample 1 bead at random

B <- 10000    # number of times to draw 1 bead
events <- replicate(B, sample(beads, 1))    # draw 1 bead, B times
tab <- table(events)    # make a table of outcome counts
tab    # view count table
prop.table(tab)    # view table of outcome proportions

Sidenote: Mean function for probability

In R, applying the mean() function to a logical vector returns the proportion of elements that are TRUE. When the mean function is applied, R coerces the logical values to numeric values, changing TRUE to 1 and FALSE to 0. The mean of the zeros and ones thus gives the proportion of TRUE values.

Probability Distributions

  • The probability distribution for a variable describes the probability of observing each possible outcome.
  • For discrete categorical variables, the probability distribution is defined by the proportions for each group.

Independence

  • Conditional probabilities compute the probability that an event occurs given information about dependent events. For example, the probability of drawing a second king given that the first draw is a king is: Pr(Card 2 is a king∣Card 1 is a king)=3/51
  • If two events A and B are independent, Pr(A∣B)=Pr(A).
  • To determine the probability of multiple events occurring, we use the multiplication rule.
  • The multiplication rule for independent events is: Pr(A and B and C)=Pr(A)×Pr(B)×Pr(C)
  • The multiplication rule for dependent events considers the conditional probability of both events occurring: Pr(A and B)=Pr(A)×Pr(B∣A)
  • We can expand the multiplication rule for dependent events to more than 2 events: Pr(A and B and C)=Pr(A)×Pr(B∣A)×Pr(C∣A and B)

Clone this wiki locally