To Notes

IT 223 -- Feb 18, 2026

Review Exercises

  1. What is a discrete random variable?
    Answer: It is a random variable with only a finite number of outcomes. Contrast this with a normal random variable, which can output any value in the range (-∞, +∞)
  2. What is the expected value of a discrete random variable?
    Answer: If x1, x2, ... , xn are the values of the random variable x and p1, p2, ... , pn are the corresponding probilities, the expected value of X is
          E(X) = x1 p1 + x2 p2 + ... + xn pn
    Compute E(x) using R like this:
    > values <- c(x1, x2, x3, x4, x5)
    > probs <- c(p1, p2, p3, p4, p5)
    > expectedValue <- sum(values * probs)
    
  3. What is the variance of a discrete random variable?
    Answer: if P(X=xi) = pi for each i,
    Var(X) = (xi - E(X))2 * p1 + ... + (xn - E(X))2 * pn
    Compute the variance like this:
    variance <- sum((values - expected_value)^2 * probs)
    
  4. How is the variance related to the standard deviation of a dataset or of a random variable?
    Answer: The variance is the square of the standard deviation.
  5. What is the expected value of a Bernoulli random variable?
    Answer: for a Bernoulli random variable, P(X = 0) = 1 - p and P(X = 1) = p. Then
    E(X) = 0 * (1 - p) + 1 * p = p, so that E(X) = p.
  6. What is the variance of a Bernoulli random variable?
    Answer: Var(X) = (x1 - E(X))2 p1 + ... + (xn - E(X))2 pn
       = (0 - p)2 (1 - p) + (1 - p)2 p
       = p2 (1 - p) + (1 - 2p + p2) p
       = p2 - p3 + p - 2p2 + p3
       = p - p2 = p(1 - p), so
    Var(X) = p (1 - p)
  7. If S is the sum of n independent outcomes x1, ... , xn from a random variable X, what are E(S) and Var(S) in terms of E(X) and Var(X)?
    Answer: E(S) = E(X1 + ... + X1) = E(X1) + ... + E(Xn) = nE(X), so E(S) = nE(X)
  8. Undergrads at a university have these probabilities for number of times changing majors:
          Times:         0      1      2     3      4     5    
          Probability: 0.28 0.37 0.23 0.09 0.02 0.01
    1. expected value of the number of major changes for a randomly selected student at this university,
      Answer: We can use R to compute the expected value like this:
      > times <- 0:5
      > times
      [1] 0 1 2 3 4 5
      > prob <- scan( )
      1: 0.28 0.37 0.23 0.09 0.02 0.01
      7: 
      Read 6 items
      > prob
      [1] 0.28 0.37 0.23 0.09 0.02 0.01
      > # The next line computes the expected value:
      > sum(times * prob)
      [1] 1.23
      
    2. variance of the number of major changes for a student,
      > # Answer: The variance is computed like this:
      > sum((times - 1.23)^2 * prob)
      [1] 1.1571
      
    3. standard deviation of the number of major changes at a university,
      > # Answer: the SD is the square root of the variance:
      > sqrt(1.1571)
      [1] 1.075686
      
  9. If A and B are two events, what must we assume for
          P(A and B) = P(A) * P(B)
    to be true?
    Answer: A and B must be independent.
  10. If A and B are two events, what must be true for
          P(A or B) = P(A) + P(B) to be true?
    Answer: A and B must be mutually exclusive.
  11. When rolling a pair of dice, snakeeyes are double ones. What is the probability of rolling at least one pair of snakeeyes in twenty rolls of two dice?
    Answer: 1 - (1 - 1/36)20 = 0.4307 - 43%. We can use R to perform the calculation like this:
    > 1 - (1 - 1/36)^20
    [1] 0.4307397
    
    
  12. If the probability of getting a cold in a given week is 3%, what is the probability of getting at least one cold in a year (52 weeks)?
    Answer: 1 - (1 - p)n = 1 - (1 - 0.03)52 = 0.7948 = 79.5%.
    We can use R to perform the calculation like this:
    > 1 - (1 - 0.03)^52
    [1] 0.7948223
    

Properties of Random Variables

c is a constant. A constant can be thought of as a random variable with this probability distribution:

Outcome Probability
      c        1
  1. E(c) = c
  2. E(cx) = c E(x)
  3. E(x + y) = E(x) + E(y)
  4. E(x1 + ... + xn) = E(x1) + ... + E(xn)
  5. Var(x) = E(x2) - E(x)2
  6. Definition:   x and y are independent if E(xy) = E(x)E(y).
    If x and y are independent, Var(x + y) = Var(x) + Var(y)
  7. Var(cx) = c2 Var(x)

Here are the derivations.

Practice Problem

  1. Compute the variance and SD of a Bernoulli random variable with the formula Var(x) = E(x2) - E(x)2.
         Var(x) = E(x2) - E(x)2 = (02 (1 - p) + ... + 12 p) - p2
                  = p - p2 = p(1 - p)
    This is the same result that we obtained earlier.

Sums of Random Variables

Practice Problems

  1. Compute the expected value and standard deviation of the total amount of rain in a year (365 days) if the number of inches of rain in one day is this random variable:
          Amount:       0     1     2     3
          Probability: 0.3  0.4  0.2  0.1
  2. Compute the expected value and standard deviation of independent Bernoulli random variable outcomes for the sum of n trials.
  3. Assume that the probability of success is the same value p for all outcomes.

Using R to Simulate Bernoulli Outcomes

  1. Use R to simulate the random outcomes from flipping a fair coin 10 times. Answer: the probability experiment is flipping a coin once; this experiment is repeated 10 times. A binomial random variable is the sum of a specified number of independent outcomes from a Bernoulli random variable. We will see why this type of random variable is called a binomial random variable later.
    // Here are the meanings of the R arguments:
    // n = number of times the experiment is repeated
    // size = number of Bernoulli outcomes in one experiment
    // prob = the probability of success for Bernoulli rv.
    rbinom(n=10, size=1, prob=0.5)
     [1] 1 0 0 1 1 1 1 0 0 1
    
  2. Use R to simulate 20 repetitions of flipping a coin 2 times.
    Answer: in this case, n = 20, size = 2, and prob = 0.5.
    > rbinom(n=20, size=2, prob=0.5)
    # or
    > rbinom(20, 2, 0.5)
     [1] 1 2 1 2 0 1 1 1 0 2 0 2 2 2 0 1 1 1 1 1
    
  3. Use R to simulate flipping a fair coin one million times. Repeat the experiment twice. Answer:
    > > rbinom(2, 1000000, 0.5) 
    [1] 500664 499815
    
  4. Elena Delle Donne is the best free throw shooter in WNBA history with a career average of 93.4%. Simulate 10 seasons of shooting 90 free throws per season with a success rate of 93.4%. Answer:
    > rbinom(10, 90, 0.934)
    [1] 79 82 84 87 86 81 85 86 82 87
    

Averages of Random Variables

The Law of Averages

Factorials and Counting Combinations