Random Variables
What Next?
• Probability is fun, but it is just a tool for
understanding how a random process works.
• Probability gives us an idea of what to expect
or at least how often to expect each outcome.
• We want more. There is more to understand
than just the likelihood of each outcome.
Tossing a Coin
• Think about tossing a quarter…
– Only two outcomes, either head or tail
– How do we describe the results of our experiment
without saying, HHTHTHTHHTTTTHHH… etc.
– What if we just counted the number of heads or
just counted the number of tails?
– Let X be the number of heads in N flips so N-X is the
number of tails…
– We just created something called a Random
Variable.
What is a Random Variable?
• A function that maps from the sample space
to the real line.
• A random variable is neither random or a
variable…
• It can summarize certain information about an
experiment and it can be used to describe the
distribution of probability across the different
outcomes.
Examples
• A Bernoulli trial is a random variable.
– Let X be a Bernoulli trial so X={0,1}
– P(X=1) = p and P(X=0)=1-p
• Choosing a random person we can create two
random variables
– The first r.v., H, could represent their height
– The second r.v., K, could represent the number of
children they have
Distributions
• We can start to define our random variable by
listing the possible outcomes in the sample
space and assigning each a probability.
• This shows us how the different outcomes are
distributed in the long run.
Discrete R.V.
• The possible outcomes being mapped are
finite and countable.
• The outcomes are restricted to only specific
values contained in the sample space.
• i.e. {head,tail}, {0,1,2,3,4}, {5,10,15,20}
• Our example of K representing how many
children is a discrete random variable…
– 2.3 kids not allowed
Continuous R.V.
• The possible outcomes being mapped are
infinite and usually expressed as an interval of
possible values.
• i.e. [0,1], (0,10], (5,96)
• Our example of H representing a random
person’s height is a continuous random
variable…
– 69.3 inches is acceptable
Probability Distribution
• Histograms show relative frequency of a data
set
• Probability distributions show the actual
probability of each value that the random
variable could adopt.
Example
X=x Pr(x) or f(X)
f(X)
-2 .15
0.3
0 .25
2 .25 0.25
4 .20
0.2
6 .15
0.15
0.1
0.05
0
-2 0 2 4 6
Cumulative Distribution
• Used to show the accumulation of probability
across the values of the random variable
• Very important relationship with the
probability distribution which we will see later
• Two ways of characterizing the distribution of
a random variable, probability and cumulative
distribution
Example
X=x F(x)
F(X)
-2 .15
1
0 .40
0.9
2 .65
0.8
4 .85
0.7
6 1 0.6
0.5
0.4
0.3
0.2
0.1
0
-2 0 2 4 6
Sample vs. Population
• Random variables represent the population.
• Samples combined with common distributions
can help us solve for the characteristics of the
population.
• Random variables can have common distributions
such as Binomial, Poisson, or Normal.
• Parameters like mean and variance describe the
specific distribution of a given random variable.
Frequentist vs. Bayesian
• Two conflicting schools of thought
– Frequentist
– Bayesian
• Frequentists believe that we use the sample to
model reality and ascertain the true
parameter values.
• Bayesians believe that we use the sample to
refine our understanding of the random
process itself.
The Math
• Random variables have a mean just like a sample
or a dataset does.
• Difference is that we calculate the mean with
probabilities instead of frequencies.
• Mean (X)=µx = x1*P(x1) + x2*P(x2) + … +xN*P(xN)
• Weighted average with the probabilities of each
outcome being the weights
Example
• Mean (X) = (-2)(.15) + (0)(.25) + (2)(.25) + (4)
(.20) + (6)(.15) = 1.9
• If we randomly selected an observation from
this distribution we would EXPECT the value to
be 1.9
Note: mean does not have to be equal to a
possible outcome of the r.v.
Expectations
• A weighted average of outcomes which uses
probabilities as the weights is referred to as an
expected value, denoted E(X).
• The mean of a random variable is equivalent
to its expected value.
E(X) = µx = x1*P(x1) + x2*P(x2) + … +xN*P(xN)
Variance and S.D.
• The variance of a random variable is
equivalent to the expected value of its
squared deviations from the mean…
Var(X) = σ2 = E[(X-µ)2] = E[X2] –(E[X])2
=(x1-µ)2P(x1) + (x2-µ)2P(x2) +… +(xN-µ)2P(xN)
S.D. = σ = sqrt(Var(X))
Example
• Var(X) = (-2 – 1.9)2(.15) + (0 – 1.9)2(.25) + (2 -
1.9)2(.25) + (4 – 1.9)2(.15) = 6.59
• S.D.(X) = sqrt(6.59) = 2.57
Properties of Expected Values
• Expectations are a linear operator
• E(c) = c where c is a constant
• E(X + c) = E(X) + E(c) = E(X) + c
• E(X – c) = E(X) – E(c) = E(X) – c
• E(cX) = cE(X)
• E(aX1 + bX2) = aE(X1) + bE(X2)
• E(a + bX) = a + bE(X)
Properties of Variance,S.D.
• Var(X +c) = Var(X)
• S.D. (X + c) = S.D. (X)
• Var(cX) = c2Var(X)
• S.D.(cX) = │c│S.D.(X)
• Var(a +bX) = b2Var(X)
• S.D.(a + bX) = │b│S.D(X)
Handout
• Lets practice…