12 PAUSE: Random Variables in Practice


Thus far in Unit 2:

Under the overarching goal of exploring univariate probability models, we have questioned:

  • What model is appropriate for any given random variable? Tools: pmf, pdf, cdf, named probability models (Uniform, Normal, Poisson, Binomial)

  • What are the features of a given model? Tools: expected value, variance, cdf

Thus far, we’ve focused on theoretical models and their features. In this activity, you’ll explore the behavior of data generated from these models.



Getting started



Directions

  • Open the Rmd template provided on Moodle. Once you get a chunk working without error, be sure to remove the eval = FALSE from that chunk.
  • The probability concepts are the most important part of this activity. The simulation / R code merely support our exploration of these concepts. With this in mind, pay careful attention along the way and keep track of the emerging patterns. You’ll be asked to summarize these at the end of the activity.



12.1 Part 1: Normal simulation

Let \(X\) measure body temperature in degrees Celsius and suppose that a reasonable model of \(X\) is \[X \sim N(37, (5/12)^2)\] with \(E(X) = 37\) degrees and \(SD(X) = 5/12\) degrees. Simulate a sample of body temperatures for 10000 individuals. How closely do the sample features follow the properties of the underlying theoretical model?



  1. U = X + b
    Define a new variable \(U = X + 32\), which adds 32 degrees to body temperatures \(X\).
    1. Gut check: On a scratch piece of paper, sketch what you imagine the probability model / pdf of \(U\) will look like. Think: How, if at all, does adding 32 change the expected value, variance, or shape of the model?
    2. Check your intuition. Transform your sample of \(X\) values into a sample of \(U\) values:

      Construct visual and numerical summaries of your \(U\) sample values. Was your intuition correct?



  1. V = aX
    Define another new variable \(V = \frac{9}{5}X\), which scales body temperatures \(X\) by 9/5.
    1. Gut check: On a scratch piece of paper, sketch what you imagine the probability model / pdf of \(V\) will look like. Think: How, if at all, does scaling \(X\) by 9/5 change the expected value, variance, or shape of the model?
    2. Check your intuition. Transform your sample of \(X\) values into a sample of \(V\) values:

      Construct visual and numerical summaries of your \(V\) sample values. Was your intuition correct?



  1. Y = aX + b
    Finally, define variable \(Y = \frac{9}{5}X + 32\). This transformation of \(X\) converts body temperatures from Celsius to Fahrenheit!
    1. Gut check: On a scratch piece of paper, sketch what you imagine the probability model / pdf of \(Y\) will look like.
    2. Check your intuition. Transform your sample of \(X\) values into a sample of \(Y\) values. Then construct visual and numerical summaries of your \(Y\) sample values. For comparison, plot \(Y\) relative to \(X\):



12.2 Part 2: Uniform simulation

Let \(X \sim \text{Unif}(0,1)\) with \(E(X) = 1/2\), \(Var(X) = 1/12\), and pdf

\[\begin{split} f_X(x) & = 1 \;\; \text{ for } x \in [0,1] \\ \end{split}\]

Simulate and examine a sample of 10000 \(X\) values:



  1. Transforming the Uniform
    Let \(U\), \(V\), and \(Y\) be the following transformations of \(X\):

    \[\begin{split} U & = 2X + 1 \;\;\; \text{(a linear transformation)}\\ V & = 0.5X - 1 \;\;\; \text{(a linear transformation)}\\ Y & = X^2 \;\;\; \text{(a NONlinear transformation)} \\ \end{split}\]

    1. Gut check: On a scratch piece of paper, sketch what you imagine the probability models / pdfs of \(U\), \(V\), and \(Y\) to look like.
    2. Check your intuition. Transform your sample of \(X\) values into a samples of \(U,V,Y\) values. Then construct visual and numerical summaries of \(U,V,Y\) sample values.

    3. Do \(U\) and \(V\) look Uniform? What about \(Y\)?



12.3 Part 3: Binomial simulation

Let \(X \sim \text{Bin}(10,0.5)\) with \(E(X) = 5\) and \(Var(X) = 2.5\). Simulate and examine a sample of 10000 \(X\) values:



  1. Linear transformations
    Let \(Y\) be the following linear transformation of \(X\): \[Y = 0.5 X\]
    1. Gut check: On a scratch piece of paper, sketch what you imagine the probability model / pmf of \(Y\) to look like.
    2. Check your intuition. Transform your sample of \(X\) values into a sample of \(Y\) values. Then construct visual and numerical summaries of your \(Y\) sample values.

    3. Does \(Y\) look Binomial?



12.4 Part 4: Bringing it together

You experienced above that a function of a random variable is itself a random variable with different properties! After reflecting on your simulations, try to summarize the general properties that emerged along the way.



  1. Linear transformations: general properties
    Let \(X\) be any random variable and \(Y\) be a linear transformation of \(X\):

    \[Y = aX + b\]

    1. Will the probability model of \(Y\) necessarily be from the same family as the probability model of \(X\)? For example:
      • If \(X\) is Normal will \(Y\) be Normal?
      • If \(X\) is Uniform will \(Y\) be Uniform?
      • If \(X\) is Binomial will \(Y\) be Binomial?
    2. In words: How (if at all) does \(b\) impact the expected value? How (if at all) does \(b\) impact the variance?
    3. In words: How (if at all) does \(a\) impact the expected value? How (if at all) does \(a\) impact the variance?



  1. Linear transformations: theoretical properties
    Suppose \(X\) is continuous with pdf \(f_X(x)\), \(E(X)\), and \(Var(X)\). (The proof for discrete random variables is similar.)
    1. Based on your simulations above, how do you think we can write \(E(Y)\) in terms of \(E(X)\), \(a\), and \(b\)? \[E(Y) = ???\]

    2. Challenge: provide a proof of your answer to part a.
    3. Based on your simulations above, how do you think we can write \(Var(Y)\) in terms of \(Var(X)\), \(a\), and \(b\)? \[Var(Y) = ???\]

    4. Challenge: provide a proof of your answer to part c.



  1. BONUS challenge
    The expected value and variance, \(E(Y)\) and \(Var(Y)\), provide key features of \(Y\). But what can we say about overall model of \(Y\)?

    1. Assume \(X\) is discrete with pmf \(p_X(x)\). Construct the pmf of \(Y\), \(p_Y(y)\).
    2. Assume \(X\) is continuous with pdf \(f_X(x)\). Construct the pdf of \(Y\), \(f_Y(y)\). HINT: First derive \(F_Y()\) from \(F_X()\), then \(f_Y()\) from \(F_Y()\).