Political Science 209 - Fall 2018 Probability III Florian - - PowerPoint PPT Presentation

political science 209 fall 2018
SMART_READER_LITE
LIVE PREVIEW

Political Science 209 - Fall 2018 Probability III Florian - - PowerPoint PPT Presentation

Political Science 209 - Fall 2018 Probability III Florian Hollenbach 11th November 2018 Random Variables and Probability Distributions What is a random variable? We assigns a number to an event coin flip: tail= 0; heads= 1 Senate


slide-1
SLIDE 1

Political Science 209 - Fall 2018

Probability III

Florian Hollenbach 11th November 2018

slide-2
SLIDE 2

Random Variables and Probability Distributions

  • What is a random variable? We assigns a number to an event
  • coin flip: tail= 0; heads= 1
  • Senate election: Ted Cruz= 0; Beto O’Rourke= 1
  • Voting: vote = 1; not vote = 0

Florian Hollenbach 1

slide-3
SLIDE 3

Random Variables and Probability Distributions

  • What is a random variable? We assigns a number to an event
  • coin flip: tail= 0; heads= 1
  • Senate election: Ted Cruz= 0; Beto O’Rourke= 1
  • Voting: vote = 1; not vote = 0

Probability distribution: Probability of an event that a random variable takes a certain value

Florian Hollenbach 1

slide-4
SLIDE 4

Random Variables and Probability Distributions

  • P(coin =1); P(coin = 0)
  • P(election = 1); P(election = 0)

Florian Hollenbach 2

slide-5
SLIDE 5

Random Variables and Probability Distributions

  • Probability density function (PDF): f(x) How likely does X

take a particular value?

  • Probability mass function (PMF): When X is discrete,

f(x)=P(X =x)

Florian Hollenbach 3

slide-6
SLIDE 6

Random Variables and Probability Distributions

  • Probability density function (PDF): f(x) How likely does X

take a particular value?

  • Probability mass function (PMF): When X is discrete,

f(x)=P(X =x)

  • Cumulative distribution function (CDF): F(x) = P(X ≤ x)
  • What is the probability that a random variable X takes a value

equal to or less than x?

  • Area under the density curve (either we use the sum Σ or

integral

  • )
  • Non-decreasing

Florian Hollenbach 3

slide-7
SLIDE 7

Random Variables and Probability Distributions: Binomial Distribution

  • PMF: for x ∈ {0, 1, . . . , n},

f (x) = P(X = x) = n

x

  • px(1 − p)n−x
  • PMF function to tell us: what is the probability of x successes

given n trials with with P(x) = p

Florian Hollenbach 4

slide-8
SLIDE 8

Random Variables and Probability Distributions: Binomial Distribution

  • PMF: for x ∈ {0, 1, . . . , n},

f (x) = P(X = x) = n

x

  • px(1 − p)n−x
  • PMF function to tell us: what is the probability of x successes

given n trials with with P(x) = p In R: dbinom(x = 2, size = 4, prob = 0.1) ## prob of 2 successes in [1] 0.0486

Florian Hollenbach 4

slide-9
SLIDE 9

Random Variables and Probability Distributions: Binomial Distribution

  • CDF: for x ∈ {0, 1, . . . , n}

F(x) = P(X ≤ x) = x

k=0

n

k

  • pk(1 − p)n−k
  • CDF function to tell us: what is the probability of x or fewer

successes given n trials with with P(x) = p

Florian Hollenbach 5

slide-10
SLIDE 10

Random Variables and Probability Distributions: Binomial Distribution

  • CDF: for x ∈ {0, 1, . . . , n}

F(x) = P(X ≤ x) = x

k=0

n

k

  • pk(1 − p)n−k
  • CDF function to tell us: what is the probability of x or fewer

successes given n trials with with P(x) = p In R: pbinom(2, size = 4, prob = 0.1) ## prob of 2 or fewer successes [1] 0.9963

Florian Hollenbach 5

slide-11
SLIDE 11

PMF and CDF

CDF of F(x) is equal to the sum of the results from calculating the PMF for all values smaller and equal to x

Florian Hollenbach 6

slide-12
SLIDE 12

PMF and CDF

CDF of F(x) is equal to the sum of the results from calculating the PMF for all values smaller and equal to x In R: pbinom(2, size = 4, prob = 0.1) ## CDF sum(dbinom(c(0,1,2),4,0.1)) ## summing up the pdfs [1] 0.9963 [1] 0.9963

Florian Hollenbach 6

slide-13
SLIDE 13

Random Variables and Probability Distributions: Binomial Distribution

  • Example: flip a fair coin 3 times

f (x) = P(X = x) = n

x

  • px(1 − p)n−x

f (x) = P(X = 1) = 3

1

  • 0.51(0.5)2 = 3 ∗ 0.5 ∗ 0.52 = 0.375

Florian Hollenbach 7

slide-14
SLIDE 14

Random Variables and Probability Distributions: Binomial Distribution

x <- 0:3 barplot(dbinom(x, size = 3, prob = 0.5), ylim = c(0, 0.4), names.arg = x, xlab = "x", ylab = "Density", main = "Probability mass function")

Florian Hollenbach 8

slide-15
SLIDE 15

Random Variables and Probability Distributions: Binomial Distribution

1 2 3

Probability mass function

x Density 0.0 0.1 0.2 0.3 0.4

Florian Hollenbach 9

slide-16
SLIDE 16

Random Variables and Probability Distributions: Binomial Distribution

x <- -1:4 pb <- pbinom(x, size = 3, prob = 0.5) plot(x[1:2], rep(pb[1], 2), ylim = c(0, 1), type = "s", xlim = c(-1, 4), xlab = "x", ylab = "Probability", main = "Cumulative distribution function") for (i in 2:(length(x)-1)) { lines(x[i:(i+1)], rep(pb[i], 2)) } points(x[2:(length(x)-1)], pb[2:(length(x)-1)], pch = 19) points(x[2:(length(x)-1)], pb[1:(length(x)-2)])

Florian Hollenbach 10

slide-17
SLIDE 17

Random Variables and Probability Distributions: Binomial Distribution

−1 1 2 3 4 0.0 0.2 0.4 0.6 0.8 1.0

Cumulative distribution function

x Probability

  • Florian Hollenbach

11

slide-18
SLIDE 18

Random Variables and Probability Distributions: Normal Dis- tribution

Normal distribution

Florian Hollenbach 12

slide-19
SLIDE 19

Random Variables and Probability Distributions: Normal Dis- tribution

Normal distribution also called Gaussian distribution

Florian Hollenbach 13

slide-20
SLIDE 20

Normal distribution

  • Takes on values from -∞ to ∞
  • Defined by two things: µ and σ2
  • Mean and Variance (standard deviation squared)
  • Mean defines the location of the distribution
  • Variance defines the spread

Florian Hollenbach 14

slide-21
SLIDE 21

Random Variables and Probability Distributions: Normal Dis- tribution

Normal distribution with mean µ and standard deviation σ

  • PDF: f (x) =

1 √ 2πσ exp

  • − (x−µ)2

2σ2

  • Florian Hollenbach

15

slide-22
SLIDE 22

Random Variables and Probability Distributions: Normal Dis- tribution

Normal distribution with mean µ and standard deviation σ

  • PDF: f (x) =

1 √ 2πσ exp

  • − (x−µ)2

2σ2

  • In R:

dnorm(2, mean = 2, sd = 2) ## probability of x =2 with normal [1] 0.1994711

Florian Hollenbach 15

slide-23
SLIDE 23

Random Variables and Probability Distributions: Normal Dis- tribution

  • CDF (no simple formula. use to compute it):

F(x) = P(X ≤ x) = x

−∞ 1 √ 2πσ exp

  • − (t−µ)2

2σ2

  • dt
  • What will be F(x =2) for N(2,4)?

Florian Hollenbach 16

slide-24
SLIDE 24

Random Variables and Probability Distributions: Normal Dis- tribution

  • CDF (no simple formula. use to compute it):

F(x) = P(X ≤ x) = x

−∞ 1 √ 2πσ exp

  • − (t−µ)2

2σ2

  • dt
  • What will be F(x =2) for N(2,4)?

In R: pnorm(2, mean = 2, sd = 2) ## probability of x =2 with normal [1] 0.5

Florian Hollenbach 16

slide-25
SLIDE 25

Normal distribution

  • Normal distribution is symmetric around the mean
  • Mean = Median

Florian Hollenbach 17

slide-26
SLIDE 26

Random Variables and Probability Distributions: Normal Dis- tribution

−6 −4 −2 2 4 6 0.0 0.2 0.4 0.6 0.8

Probability density function

x density mean = 1 s.d. = 0.5 mean = 0 s.d. = 1 mean = 0 s.d. = 2

Florian Hollenbach 18

slide-27
SLIDE 27

Random Variables and Probability Distributions: Normal Dis- tribution in R

x <- seq(from = -7, to = 7, by = 0.01) plot(x, dnorm(x), xlab = "x", ylab = "density", type = "l", main = "Probability density function", ylim = c(0, 0.9)) lines(x, dnorm(x, sd = 2), col = "red", lwd = lwd) lines(x, dnorm(x, mean = 1, sd = 0.5), col = "blue", lwd = lwd) Florian Hollenbach 19

slide-28
SLIDE 28

Random Variables and Probability Distributions: Normal Dis- tribution in R

−6 −4 −2 2 4 6 0.0 0.2 0.4 0.6 0.8

Probability density function

x density

Florian Hollenbach 20

slide-29
SLIDE 29

Random Variables and Probability Distributions: Normal Dis- tribution in R

plot(x, pnorm(x), xlab = "x", ylab = "probability", type = "l", main = "Cumulative distribution function", lwd = lwd) lines(x, pnorm(x, sd = 2), col = "red", lwd = lwd) lines(x, pnorm(x, mean = 1, sd = 0.5), col = "blue", lwd = lwd) Florian Hollenbach 21

slide-30
SLIDE 30

Random Variables and Probability Distributions: Normal Dis- tribution in R

−6 −4 −2 2 4 6 0.0 0.2 0.4 0.6 0.8 1.0

Cumulative distribution function

x probability

Florian Hollenbach 22

slide-31
SLIDE 31

Random Variables and Probability Distributions: Normal Dis- tribution

Let X ∼ N(µ, σ2), and c be some constant

  • Adding/subtracting to/from a random variable that is normally

distributed also results in a variable with a normal distribution: Z = X + c then Z ∼ N(µ + c, σ2)

Florian Hollenbach 23

slide-32
SLIDE 32

Random Variables and Probability Distributions: Normal Dis- tribution

Let X ∼ N(µ, σ2), and c be some constant

  • Adding/subtracting to/from a random variable that is normally

distributed also results in a variable with a normal distribution: Z = X + c then Z ∼ N(µ + c, σ2)

  • Multiplying or dividing a random variable that is normally

distributed also results in a variable with a normal distribution: Z = X × c then Z ∼ N(µ × c, (σ × c)2)

  • Z-score of a random variable that is normally distributed has

mean 0 and sd = 1

Florian Hollenbach 23

slide-33
SLIDE 33

Random Variables and Probability Distributions: Normal Dis- tribution

Curve of the standard normal distribution:

  • Symmetric around 0
  • Total area under the curve is 100%
  • Area between -1 and 1 is ~68%
  • Area between -2 and 2 is ~95%
  • Area between -3 and 3 is ~99.7%

Florian Hollenbach 24

slide-34
SLIDE 34

Random Variables and Probability Distributions: Normal Dis- tribution

x <- seq(from = -7, to = 7, by = 0.01) lwd <- 1.5 plot(x, dnorm(x), xlab = "x", ylab = "density", type = "l", main = "Probability density function", ylim = c(0, 0.9)) abline(v= -1, col = "red") abline(v= 1, col = "red") abline(v= -2, col = "green") abline(v= 2, col = "green") Florian Hollenbach 25

slide-35
SLIDE 35

Random Variables and Probability Distributions: Normal Dis- tribution

−6 −4 −2 2 4 6 0.0 0.2 0.4 0.6 0.8

Probability density function

x density

Florian Hollenbach 26

slide-36
SLIDE 36

Random Variables and Probability Distributions: Normal Dis- tribution

Curve of the any normal distribution:

  • Symmetric around 0
  • Total area under the curve is 100%
  • Area between -1SD and +1SD is ~68%
  • Area between -2SD and +2SD is ~95%
  • Area between -3SD and +3SD is ~99.7%

Florian Hollenbach 27

slide-37
SLIDE 37

Random Variables

Expectations, Means, and Variances For probability distributions, means should not be confused with sample means Expectations or means of a random variable have specific meanings for its the probability distribution

Florian Hollenbach 28

slide-38
SLIDE 38

Means and Expectation

A sample mean varies from sample to sample Mean of a probability distribution is a theoretical construct and constant

Florian Hollenbach 29

slide-39
SLIDE 39

Means and Expectation

A sample mean varies from sample to sample Mean of a probability distribution is a theoretical construct and constant Example: Age of undergraduate body at A&M

Florian Hollenbach 29

slide-40
SLIDE 40

Means and Expectation

The expectation of a random variable is equal to the sum of all possibilities weighted by the probabilities

Florian Hollenbach 30

slide-41
SLIDE 41

Means and Expectation

The expectation of a random variable is equal to the sum of all possibilities weighted by the probabilities Example: expectation of rolling one die E(X) = 1

6 × 1 + 1 6 × 2 + 1 6 × 3 + 1 6 × 41 6 × 51 6 × 6 = 3.5 Florian Hollenbach 30

slide-42
SLIDE 42

Means and Expectation

The expectation of a random variable is equal to the sum of all possibilities weighted by the probabilities E(X) =

x x f (x)

if X is discrete

  • x f (x)dx

if X is continuous

Florian Hollenbach 31

slide-43
SLIDE 43

Means and Expectation

Remember the lottery! Expected value: winnings × p(winning) + 0 × p(not winning)

Florian Hollenbach 32

slide-44
SLIDE 44

Means and Expectation

What is E(X) for the number of heads in 100 coin flips?

Florian Hollenbach 33

slide-45
SLIDE 45

Means and Expectation

What is E(X) for the number of heads in 100 coin flips? E(X) = 0.5 × 1 + 0.5 × 1 + ... + 0.5 × 1 = 0.5 ∗ 100 = 50

Florian Hollenbach 33

slide-46
SLIDE 46

Variance

  • Variance is standard deviation squared
  • Variance in a probability distribution indicates how much

uncertainty exists

  • Similar but not the same as sample standard deviation

Florian Hollenbach 34

slide-47
SLIDE 47

Variance

Population variance: V(X) = E[{X − E(X)}2] = E(X 2) − {E(X)}2

Florian Hollenbach 35

slide-48
SLIDE 48

Large Sample Theorem

If we have a sample of i.i.d. observations from random variable X with expectation E(X), then ¯ Xn = 1

N

N

i=1 Xi → E(X) Florian Hollenbach 36

slide-49
SLIDE 49

Large Sample Theorem

If we have a sample of i.i.d. observations from random variable X with expectation E(X), then ¯ Xn = 1

N

N

i=1 Xi → E(X)

In English: As the number of draws increases, the sample mean approaches the variable’s distribution expectation

Florian Hollenbach 36

slide-50
SLIDE 50

Large Sample Theorem

Examples:

  • 1. Rolling a die, 1000 times
  • 2. Drawing respondents from a population of supporters and

non-supporters for politician A

  • 3. Birthday problem simulation

Florian Hollenbach 37

slide-51
SLIDE 51

Large Sample Theorem

draws <- c(seq(from = 1, to = 1000, by = 10),seq(1000,5000,500)) avgs <- rep(NA, length(draws)) for(i in 1:length(draws)){ samp <-sample(c(1:6),draws[i],replace = T) avgs[i] <- mean(samp) } plot(draws,avgs, type = "l")

Florian Hollenbach 38

slide-52
SLIDE 52

Large Sample Theorem

1000 2000 3000 4000 5000 3.0 3.5 4.0 4.5 draws avgs

Florian Hollenbach 39

slide-53
SLIDE 53

Central Limit Theorem

But, we want to learn from samples about the true underlying distribution (population)! How do we know when the sample mean is close to the population expectation?

Florian Hollenbach 40

slide-54
SLIDE 54

Central Limit Theorem

Here is where it gets crazy! CLT: distribution of sample means approaches a normal distribution as number of samples increases!

Florian Hollenbach 41

slide-55
SLIDE 55

Central Limit Theorem

Example:

  • 1. Experiment: flip a coin 10 times and record the number of

heads

  • 2. Do experiment above 1000 times

What is E(X) if X = # of Heads?

Florian Hollenbach 42

slide-56
SLIDE 56

Central Limit Theorem

avgs <- rep(NA,1000) for(i in 1:1000){ samp <- rbinom(1000,10,p=0.5) avgs[i] <- mean(samp) } plot(density(avgs))

Florian Hollenbach 43

slide-57
SLIDE 57

Central Limit Theorem

Mean across all samples = 4.96

4.8 4.9 5.0 5.1 2 4 6 8

density.default(x = avgs)

N = 1000 Bandwidth = 0.01117 Density

Florian Hollenbach 44

slide-58
SLIDE 58

Central Limit Theorem

In fact, the z-score of the sample mean converges in distribution to the standard normal distribution! Theorem: Z =

X n−E(X n)

V(X)

=

X−E(X)

V(X)/n approaches to the standard

Normal distribution N(0, 1)

Florian Hollenbach 45

slide-59
SLIDE 59

Central Limit Theorem

Remember E(X) = n × p and V (X) = n × p × (1 − p) for binomial z_avgs <- rep(NA,1000) for(i in 1:1000){ samp <- rbinom(1000,10,p=0.5) z_avgs[i] <- (mean(samp)- 5)/sqrt(2.5/1000) } plot(density(z_avgs))

Florian Hollenbach 46

slide-60
SLIDE 60

Central Limit Theorem

−4 −2 2 4 0.0 0.1 0.2 0.3

density.default(x = z_avgs)

N = 1000 Bandwidth = 0.2309 Density

Florian Hollenbach 47

slide-61
SLIDE 61

CLT: Example rolling a die 10 times

avgs <- rep(NA,1000) for(i in 1:1000){ samp <- sample(c(1:6),10, replace = T) avgs[i] <- sum(samp) } plot(density(avgs))

Florian Hollenbach 48

slide-62
SLIDE 62

Central Limit Theorem

20 30 40 50 0.00 0.02 0.04 0.06

density.default(x = avgs)

N = 1000 Bandwidth = 1.181 Density

Florian Hollenbach 49

slide-63
SLIDE 63

Central Limit Theorem: Why do we care?

  • Hypothetically repeated polls with sample size N
  • Xi = 1 if support for Jimbo Fisher, Xi = 0 if supports Kevin

Sumlin

  • Probability model: n

i=1 Xi ∼ Binom(n, p) Florian Hollenbach 50

slide-64
SLIDE 64

Central Limit Theorem: Why do we care?

  • Hypothetically repeated polls with sample size N
  • Xi = 1 if support for Jimbo Fisher, Xi = 0 if supports Kevin

Sumlin

  • Probability model: n

i=1 Xi ∼ Binom(n, p)

  • Jimbo’s support rate: X n = n

i=1 Xi/n

  • LLN: X n −

→ p as n tends to infinity

  • CLT: X n

approx.

∼ N

  • 0, p(1−p)

n

  • for a large n

Florian Hollenbach 50