116
Predicting the Outcome of an Election Carlos Fernandez-Granda www.cims.nyu.edu/~cfgranda cSplash 2018

Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

  • Upload
    others

  • View
    8

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Predicting the Outcome of an Election

Carlos Fernandez-Grandawww.cims.nyu.edu/~cfgranda

cSplash 2018

Page 2: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Acknowledgements

Support by NSF award DMS-1616340

Page 3: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Election

I Candidate against candidate

I New York: 8 million

I Goal: Estimate fraction of people who will vote for

Page 4: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Experiment

I True fraction is 0.547

I We ask 1000 people at random

I Outcome:

545! (estimate: 0.545)

I Did we get lucky?

Page 5: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Experiment

I True fraction is 0.547

I We ask 1000 people at random

I Outcome: 545! (estimate: 0.545)

I Did we get lucky?

Page 6: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Experiment

I True fraction is 0.547

I We ask 1000 people at random

I Outcome: 545! (estimate: 0.545)

I Did we get lucky?

Page 7: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Poll of 1 000 people (repeated 10 000 times)

Page 8: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Poll of 10 000 people (repeated 10 000 times)

Page 9: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Poll of 100 000 people (repeated 10 000 times)

Page 10: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Question to think about

Does the total population (8 million) matter?

Page 11: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Interesting phenomenon

# voters in poll#people in the poll

is close to# voters# people

Aim of the talk: Understand why this happens

Page 12: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Not so easy

# voters in poll changes every time: its value is uncertain

We need to reason probabilistically

We need mathematical tools to analyze uncertain quantities

Page 13: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Random variable

Mathematical objects that model uncertain quantities

A random variable X has a set of possible outcomes

Sampling X results in one of those outcomes

Page 14: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Probability

Maps outcomes to a number between 0 and 1

The probability of an outcome quantifies how likely it is

Intuitively

P (outcome i) =#samples equal to outcome i

# samples

when the number of samples is very large

Page 15: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Events

We can group outcomes in sets called events

An event occurs if we sample an outcome belonging to the event

X ∈ {0, 1}, Y ≤ 10, Z ≥ 1.2

The probability of an event quantifies how likely it is

Page 16: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Probability

Intuitively

P (event) =#times event happens

# samples

when the number of samples is very large

P (X ∈ {0, 3}) ≈ # samples equal to 0 or 3# samples of X

Page 17: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Properties of probability

Probability is nonnegative, like mass or length

Page 18: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Properties of probability

If events can’t happen simultaneously, we can add their probabilities

P (X ∈ {0, 4, 7}) = P (X = 0) + P (X ∈ {4, 7})

Makes sense:

P (X ∈ {0, 4, 7}) ≈ # samples equal to 0, 4 or 7# samples of X

=# samples equal to 0 +# samples equal to 4 or 7

# samples of X≈ P (X = 0) + P (X ∈ {4, 7})

Also like mass or length

Page 19: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Properties of probability

If events can’t happen simultaneously, we can add their probabilities

P (X ∈ {0, 4, 7}) = P (X = 0) + P (X ∈ {4, 7})

Makes sense:

P (X ∈ {0, 4, 7}) ≈ # samples equal to 0, 4 or 7# samples of X

=# samples equal to 0 +# samples equal to 4 or 7

# samples of X≈ P (X = 0) + P (X ∈ {4, 7})

Also like mass or length

Page 20: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Properties of probability

If events can’t happen simultaneously, we can add their probabilities

P (X ∈ {0, 4, 7}) = P (X = 0) + P (X ∈ {4, 7})

Makes sense:

P (X ∈ {0, 4, 7}) ≈ # samples equal to 0, 4 or 7# samples of X

=# samples equal to 0 +# samples equal to 4 or 7

# samples of X

≈ P (X = 0) + P (X ∈ {4, 7})

Also like mass or length

Page 21: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Properties of probability

If events can’t happen simultaneously, we can add their probabilities

P (X ∈ {0, 4, 7}) = P (X = 0) + P (X ∈ {4, 7})

Makes sense:

P (X ∈ {0, 4, 7}) ≈ # samples equal to 0, 4 or 7# samples of X

=# samples equal to 0 +# samples equal to 4 or 7

# samples of X≈ P (X = 0) + P (X ∈ {4, 7})

Also like mass or length

Page 22: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Properties of probability

If events can’t happen simultaneously, we can add their probabilities

P (X ∈ {0, 4, 7}) = P (X = 0) + P (X ∈ {4, 7})

Makes sense:

P (X ∈ {0, 4, 7}) ≈ # samples equal to 0, 4 or 7# samples of X

=# samples equal to 0 +# samples equal to 4 or 7

# samples of X≈ P (X = 0) + P (X ∈ {4, 7})

Also like mass or length

Page 23: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Properties of probability

The probability of all events that can’t happen simultaneously adds to one

m∑i=1

P (X = oi ) = 1

where {o1, . . . , om} are the possible outcomes of X

Not like mass or length!

Page 24: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Properties of probability

Makes sense:m∑i=1

P (X = oi )

≈m∑i=1

# samples equal to oi# samples of X

=# samples equal to o1 +# samples equal to o2 + · · ·+# samples equal to om

# samples of X

=# samples of X# samples of X

= 1

Page 25: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Properties of probability

Makes sense:m∑i=1

P (X = oi )

≈m∑i=1

# samples equal to oi# samples of X

=# samples equal to o1 +# samples equal to o2 + · · ·+# samples equal to om

# samples of X

=# samples of X# samples of X

= 1

Page 26: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Properties of probability

Makes sense:m∑i=1

P (X = oi )

≈m∑i=1

# samples equal to oi# samples of X

=# samples equal to o1 +# samples equal to o2 + · · ·+# samples equal to om

# samples of X

=# samples of X# samples of X

= 1

Page 27: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Modeling a coin flip

When we flip a coin, it lands heads a fraction p of the time

I Possible outcomes?

0 (tails) or 1 (heads)

I Probability of outcomes?

P (X = 1) = p

P (X = 0) = 1− p

Page 28: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Modeling a coin flip

When we flip a coin, it lands heads a fraction p of the time

I Possible outcomes? 0 (tails) or 1 (heads)

I Probability of outcomes?

P (X = 1) =

p

P (X = 0) =

1− p

Page 29: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Modeling a coin flip

When we flip a coin, it lands heads a fraction p of the time

I Possible outcomes? 0 (tails) or 1 (heads)

I Probability of outcomes?

P (X = 1) = p

P (X = 0) =

1− p

Page 30: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Modeling a coin flip

When we flip a coin, it lands heads a fraction p of the time

I Possible outcomes? 0 (tails) or 1 (heads)

I Probability of outcomes?

P (X = 1) = p

P (X = 0) = 1− p

Page 31: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Election

We poll a voter at random from a population of T people

Chosen voter is a random variable X

Possible outcomes? 1, 2, . . . , T

Assumption: We are equally likely to pick any voter

Probability that we pick a specific person?

Page 32: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Election

All possible outcomes must sum to one

T∑i=1

P (X = i) = 1

and

P (X = 1) = P (X = 2) = · · · = P (X = T )

=1T

Page 33: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Election

All possible outcomes must sum to one

T∑i=1

P (X = i) = 1

and

P (X = 1) = P (X = 2) = · · · = P (X = T ) =1T

Page 34: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Election

Pick a voter at random from T people from which # are voters

New random variable

V = 1 if voter is voter

otherwise V = 0

Probability that we pick a voter? P (V = 1)

Page 35: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Election

Let’s order the voters, first # are voters

P (V = 1) = P (X ∈ {1, . . . ,# })

=

#∑i=1

P (X = i)

=#

T

Just like coin flip with p = # /T

Page 36: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Election

Let’s order the voters, first # are voters

P (V = 1) = P (X ∈ {1, . . . ,# })

=

#∑i=1

P (X = i)

=#

T

Just like coin flip with p = # /T

Page 37: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Election

Let’s order the voters, first # are voters

P (V = 1) = P (X ∈ {1, . . . ,# })

=

#∑i=1

P (X = i)

=#

T

Just like coin flip with p =

# /T

Page 38: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Election

Let’s order the voters, first # are voters

P (V = 1) = P (X ∈ {1, . . . ,# })

=

#∑i=1

P (X = i)

=#

T

Just like coin flip with p = # /T

Page 39: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Election

If T = 8 million and the fraction of voters is 0.547

What is the probability that we choose a voter?

Does this depend on T?

Page 40: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Multiple random variables

We can consider several random variables at the same time

Every time we sample, we sample all the random variables

Events can include any of the random variables

{X = 0 and Y ≤ 10}, {Z = 1.2 or W ∈ {10, 21}}

Page 41: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Probability

The probability of the event still quantifies how likely it is

Same intuition

P (event) =#times event happens

# samples

when the number of samples is very large

P (X = 0 and Y ≤ 10) ≈ # samples for which X = 0 and Y ≤ 10# samples of (X ,Y )

Page 42: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Conditional probability

If we know an event B (for example Y ≤ 10)

How likely is that another event A (for example X = 0) also happened?

P (B |A), the conditional probability of B given A

Page 43: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Conditional probability

Intuition

P (event B | event A) = #samples for which A and B happen# samples for which A happens

when the number of samples is very large

P (X = 0 |Y ≤ 10) ≈ # samples for which X = 0 and Y ≤ 10# samples for which Y ≤ 10

Page 44: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Chain rule

P (A and B) = P (A)P (B |A)

Makes sense:

P (A)P (B |A) ≈ # A happens# samples

· # A and B happen# A happens

=# A and B happen

# samples≈ P (A and B)

Page 45: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Chain rule

P (A and B) = P (A)P (B |A)

Makes sense:

P (A)P (B |A) ≈ # A happens# samples

· # A and B happen# A happens

=# A and B happen

# samples≈ P (A and B)

Page 46: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Independence

If knowing that A happened does not affect how likely B is

A and B are independent

P (B |A) = P (B)

In that case

P (A and B) = P (A)P (B |A) = P (A)P (B)

Page 47: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Modeling coin flips

When we flip a coin, it lands heads a fraction p of the time

If we flip it n times, what is the probability that k flips are heads?

Assumptions:

I Probability of heads in a single flip is p

I Flips are independent

Page 48: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Modeling coin flips

We model the problem using random variables:

Vi = 1 if ith flip is heads, 0 if it isn’t

V1, V2, . . . , Vn are independent

S = V1 + · · ·+ Vn, number of heads

Page 49: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Example

3 flips, probability of 2 heads?

P (S = 2) = P( {V1 = 1,V2 = 1,V3 = 0}or {V1 = 1,V2 = 0,V3 = 1}or {V1 = 0,V2 = 1,V3 = 1})

Page 50: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Example

P (V1 = 1 and V2 = 1 and V3 = 0) = P (V1 = 1)P (V2 = 1)P (V3 = 0)

= p2 (1− p)

P (V1 = 0 and V2 = 1 and V3 = 1) ? Does not depend on order!

In general, k heads and n − k tails in fixed order

P (k heads and n − k tails) = pk (1− p)n−k

Page 51: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Example

P (V1 = 1 and V2 = 1 and V3 = 0) = P (V1 = 1)P (V2 = 1)P (V3 = 0)

= p2 (1− p)

P (V1 = 0 and V2 = 1 and V3 = 1) ?

Does not depend on order!

In general, k heads and n − k tails in fixed order

P (k heads and n − k tails) = pk (1− p)n−k

Page 52: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Example

P (V1 = 1 and V2 = 1 and V3 = 0) = P (V1 = 1)P (V2 = 1)P (V3 = 0)

= p2 (1− p)

P (V1 = 0 and V2 = 1 and V3 = 1) ? Does not depend on order!

In general, k heads and n − k tails in fixed order

P (k heads and n − k tails) = pk (1− p)n−k

Page 53: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Example

P (V1 = 1 and V2 = 1 and V3 = 0) = P (V1 = 1)P (V2 = 1)P (V3 = 0)

= p2 (1− p)

P (V1 = 0 and V2 = 1 and V3 = 1) ? Does not depend on order!

In general, k heads and n − k tails in fixed order

P (k heads and n − k tails) = pk (1− p)n−k

Page 54: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Example

3 flips, probability of 2 heads?

P (S = 2) = P( {V1 = 1,V2 = 1,V3 = 0}or {V1 = 1,V2 = 0,V3 = 1}or {V1 = 0,V2 = 1,V3 = 1})

=3p2(1− p)

Page 55: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Modeling coin flips

In general

P (S = k) = # combinations of k heads in n flips · P (k heads in fixed order)

=

(n

k

)pk (1− p)n−k

(n

k

):=

n!

k! (n − k)!

S is a binomial random variable with parameters n and p

Page 56: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Binomial random variable n = 100, p = 0.547

40 45 50 55 60 65 70

0

2

4

6

8

·10−2

k

P(S

=k)

Page 57: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Binomial random variable n = 1000, p = 0.547

400 450 500 550 600 650 700

0

0.5

1

1.5

2

2.5

·10−2

k

P(S

=k)

Page 58: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Election

Population of T people with # voters

We poll n voters at random

How many are voters? Random variable S

Assumption 1: We are equally likely to pick any voter every time we poll

Assumption 2: Picks are all independent

What kind of random variable is S?

Page 59: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Election

S is binomial with parameters n and # /T

But we are interested in fraction of voters S/n !

P(S

n=

k

n

)=

P (S = k)

=

(n

k

)pk (1− p)n−k

We can compute exact probability of poll outcome for any n!

Page 60: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Election

S is binomial with parameters n and # /T

But we are interested in fraction of voters S/n !

P(S

n=

k

n

)= P (S = k)

=

(n

k

)pk (1− p)n−k

We can compute exact probability of poll outcome for any n!

Page 61: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Election

S is binomial with parameters n and # /T

But we are interested in fraction of voters S/n !

P(S

n=

k

n

)= P (S = k)

=

(n

k

)pk (1− p)n−k

We can compute exact probability of poll outcome for any n!

Page 62: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Fraction of voters in poll, n = 100, # /T = 0.547

0.4 0.45 0.5 0.547 0.6 0.65 0.7

0

2

4

6

8

·10−2

x

P(S

/n=x)

Page 63: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Binomial random variable n = 1000, # /T = 0.547

0.4 0.45 0.5 0.547 0.6 0.65 0.7

0

0.5

1

1.5

2

2.5

·10−2

x

P(S

/n=x)

Page 64: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Mean

Average of a random variable

E (X ) =∑i=1

oiP (X = oi )

= o1P (X = o1) + o2P (X = o2) + · · ·+ omP (X = om)

where {o1, . . . , om} are the possible outcomes of X

Page 65: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

The mean is the center of mass of the probabilities

0 5 10 15 200

5 · 10−2

0.1

0.15

0.2

k

P(X

=k)

Page 66: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Election

Population of T people with # voters

We poll n voters at random

S = # of voters in poll

What is the average estimate S/n?

Page 67: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Modeling a coin flip

When we flip a coin, it lands heads a fraction p of the time

Random variable X equal to 0 (tails) or 1 (heads)

Mean

E (X ) =

0 · P (X = 0) + 1 · P (X = 1)= p

Page 68: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Modeling a coin flip

When we flip a coin, it lands heads a fraction p of the time

Random variable X equal to 0 (tails) or 1 (heads)

Mean

E (X ) = 0 · P (X = 0) + 1 · P (X = 1)

= p

Page 69: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Modeling a coin flip

When we flip a coin, it lands heads a fraction p of the time

Random variable X equal to 0 (tails) or 1 (heads)

Mean

E (X ) = 0 · P (X = 0) + 1 · P (X = 1)= p

Page 70: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Mean of sum

The sum of the averages is the average of the sums

E (X + Y ) =

m∑i=1

m∑j=1

(oi + o ′j

)P(X = oi ,Y = o ′j

)=

m∑i=1

m∑j=1

oiP(X = oi ,Y = o ′j

)+

m∑i=1

m∑j=1

o ′jP(X = oi ,Y = o ′j

)=

m∑i=1

oi

m∑j=1

P(X = oi ,Y = o ′j

)+

m∑j=1

o ′j

m∑i=1

P(X = oi ,Y = o ′j

)=

m∑i=1

oiP (X = oi ) +m∑j=1

o ′jP(Y = o ′j

)

= E (X ) + E (Y )

Page 71: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Mean of sum

The sum of the averages is the average of the sums

E (X + Y ) =m∑i=1

m∑j=1

(oi + o ′j

)P(X = oi ,Y = o ′j

)=

m∑i=1

m∑j=1

oiP(X = oi ,Y = o ′j

)+

m∑i=1

m∑j=1

o ′jP(X = oi ,Y = o ′j

)=

m∑i=1

oi

m∑j=1

P(X = oi ,Y = o ′j

)+

m∑j=1

o ′j

m∑i=1

P(X = oi ,Y = o ′j

)=

m∑i=1

oiP (X = oi ) +m∑j=1

o ′jP(Y = o ′j

)= E (X ) + E (Y )

Page 72: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Election

S is a sum of n coin flips with p = # /T

S =n∑

i=1

Vi

E (S) = E

(n∑

i=1

Vi

)

=n∑

i=1

E (Vi )

=n #

T

What about Sn ?

Page 73: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Election

S is a sum of n coin flips with p = # /T

S =n∑

i=1

Vi

E (S) = E

(n∑

i=1

Vi

)

=n∑

i=1

E (Vi )

=n #

T

What about Sn ?

Page 74: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Election

S is a sum of n coin flips with p = # /T

S =n∑

i=1

Vi

E (S) = E

(n∑

i=1

Vi

)

=n∑

i=1

E (Vi )

=n #

T

What about Sn ?

Page 75: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Election

S is a sum of n coin flips with p = # /T

S =n∑

i=1

Vi

E (S) = E

(n∑

i=1

Vi

)

=n∑

i=1

E (Vi )

=n #

T

What about Sn ?

Page 76: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Expectation of scaled random variable

The average of a scaled random variable is just the scaled average

E (c X ) =

m∑i=1

c oiP (X = oi )

= cm∑i=1

oiP (X = oi )

= c E (X )

Page 77: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Expectation of scaled random variable

The average of a scaled random variable is just the scaled average

E (c X ) =m∑i=1

c oiP (X = oi )

= cm∑i=1

oiP (X = oi )

= c E (X )

Page 78: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Expectation of scaled random variable

The average of a scaled random variable is just the scaled average

E (c X ) =m∑i=1

c oiP (X = oi )

= cm∑i=1

oiP (X = oi )

= c E (X )

Page 79: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Expectation of scaled random variable

The average of a scaled random variable is just the scaled average

E (c X ) =m∑i=1

c oiP (X = oi )

= cm∑i=1

oiP (X = oi )

= c E (X )

Page 80: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Election

Population of T people with # voters

We poll n voters at random

S = # of voters

What is the average estimate S/n?

E (S) =n #

T

E (S/n) =

#

T(!)

Page 81: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Election

Population of T people with # voters

We poll n voters at random

S = # of voters

What is the average estimate S/n?

E (S) =n #

T

E (S/n) =#

T(!)

Page 82: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Fraction of voters in poll, n = 100, # /T = 0.547

0.547

0

2

4

6

8

·10−2

x

P(S

/n=x)

Page 83: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Fraction of voters in poll n = 1000, # /T = 0.547

0.547

0

1

2

·10−2

x

P(S

/n=x)

Page 84: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Variance

Square deviation from D := (X − E (X ))2

The variance is the mean of the square deviation

Var (X ) = E (Y )

Standard deviation σX :=√

Var (X )

Page 85: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Standard deviation ≈ average variation around mean

0 5 10 15 200

5 · 10−2

0.1

0.15

0.2

k

Page 86: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Election

Population of T people with # voters

We poll n voters at random

On average

E (S/n) =#

T

Standard deviation σS/n quantifies average deviation from truth

Key question: Does σS/n decrease as n grows?

Page 87: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Coin flip

Var (X ) = E((X − E (X ))2

)

=∑

possible values of (X − E (X ))2 · corresponding probability

= (1− p)2 p + p2 (1− p)

= (1− p) p

Page 88: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Coin flip

Var (X ) = E((X − E (X ))2

)=∑

possible values of (X − E (X ))2 · corresponding probability

= (1− p)2 p + p2 (1− p)

= (1− p) p

Page 89: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Coin flip

Var (X ) = E((X − E (X ))2

)=∑

possible values of (X − E (X ))2 · corresponding probability

= (1− p)2 p + p2 (1− p)

= (1− p) p

Page 90: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Coin flip

Var (X ) = E((X − E (X ))2

)=∑

possible values of (X − E (X ))2 · corresponding probability

= (1− p)2 p + p2 (1− p)

= (1− p) p

Page 91: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Variance of a sum

Var (X + Y ) =

E((X + Y − E (X + Y ))2

)= E

((X − E (X ))2

)+ E

((Y − E (Y ))2

)+ 2E ((X − E (X )) (Y − E (Y )))

= E((X − E (X ))2

)+ E

((Y − E (Y ))2

)+ 2E (XY )− 2E (X )E (Y )

= Var (X ) + Var (Y ) + 2E (XY )− 2E (X )E (Y )

Page 92: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Variance of a sum

Var (X + Y ) = E((X + Y − E (X + Y ))2

)= E

((X − E (X ))2

)+ E

((Y − E (Y ))2

)+ 2E ((X − E (X )) (Y − E (Y )))

= E((X − E (X ))2

)+ E

((Y − E (Y ))2

)+ 2E (XY )− 2E (X )E (Y )

= Var (X ) + Var (Y ) + 2E (XY )− 2E (X )E (Y )

Page 93: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Variance of a sum

If X and Y are independent, then

E (XY ) =

m∑i=1

m∑j=1

oio′jP(X = oi ,Y = o ′j

)=

m∑i=1

m∑j=1

oio′jP (X = oi )P

(Y = o ′j

)= E (X )E (Y )

Variance of X + Y if Y := −X

Not true if not independent!

Page 94: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Variance of a sum

If X and Y are independent, then

E (XY ) =m∑i=1

m∑j=1

oio′jP(X = oi ,Y = o ′j

)

=m∑i=1

m∑j=1

oio′jP (X = oi )P

(Y = o ′j

)= E (X )E (Y )

Variance of X + Y if Y := −X

Not true if not independent!

Page 95: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Variance of a sum

If X and Y are independent, then

E (XY ) =m∑i=1

m∑j=1

oio′jP(X = oi ,Y = o ′j

)=

m∑i=1

m∑j=1

oio′jP (X = oi )P

(Y = o ′j

)

= E (X )E (Y )

Variance of X + Y if Y := −X

Not true if not independent!

Page 96: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Variance of a sum

If X and Y are independent, then

E (XY ) =m∑i=1

m∑j=1

oio′jP(X = oi ,Y = o ′j

)=

m∑i=1

m∑j=1

oio′jP (X = oi )P

(Y = o ′j

)= E (X )E (Y )

Variance of X + Y if Y := −X

Not true if not independent!

Page 97: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Election

S is a sum of n coin flips with p = # /T

S =n∑

i=1

Vi

Var (S) =

Var

(n∑

i=1

Vi

)

=n∑

i=1

Var (Vi )

= np (1− p)

What about S/n ?

Page 98: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Election

S is a sum of n coin flips with p = # /T

S =n∑

i=1

Vi

Var (S) = Var

(n∑

i=1

Vi

)

=n∑

i=1

Var (Vi )

= np (1− p)

What about S/n ?

Page 99: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Election

S is a sum of n coin flips with p = # /T

S =n∑

i=1

Vi

Var (S) = Var

(n∑

i=1

Vi

)

=n∑

i=1

Var (Vi )

= np (1− p)

What about S/n ?

Page 100: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Election

S is a sum of n coin flips with p = # /T

S =n∑

i=1

Vi

Var (S) = Var

(n∑

i=1

Vi

)

=n∑

i=1

Var (Vi )

= np (1− p)

What about S/n ?

Page 101: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Election

S is a sum of n coin flips with p = # /T

S =n∑

i=1

Vi

Var (S) = Var

(n∑

i=1

Vi

)

=n∑

i=1

Var (Vi )

= np (1− p)

What about S/n ?

Page 102: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Variance

Var (c X ) = E((c X − E (c X ))2

)

= E(c2 (X − E (X ))2

)= c2E

((X − E (X ))2

)= c2 Var (X )

Page 103: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Variance

Var (c X ) = E((c X − E (c X ))2

)= E

(c2 (X − E (X ))2

)

= c2E((X − E (X ))2

)= c2 Var (X )

Page 104: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Variance

Var (c X ) = E((c X − E (c X ))2

)= E

(c2 (X − E (X ))2

)= c2E

((X − E (X ))2

)

= c2 Var (X )

Page 105: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Variance

Var (c X ) = E((c X − E (c X ))2

)= E

(c2 (X − E (X ))2

)= c2E

((X − E (X ))2

)= c2 Var (X )

Page 106: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Election

S is a sum of n coin flips with p = # /T

S =n∑

i=1

Vi

Var(S

n

)

=1n2 Var (S)

=np(1− p)

n2

=p (1− p)

n

σS/n =

√p (1− p)

n

Decreases as n grows!

Page 107: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Election

S is a sum of n coin flips with p = # /T

S =n∑

i=1

Vi

Var(S

n

)=

1n2 Var (S)

=np(1− p)

n2

=p (1− p)

n

σS/n =

√p (1− p)

n

Decreases as n grows!

Page 108: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Election

S is a sum of n coin flips with p = # /T

S =n∑

i=1

Vi

Var(S

n

)=

1n2 Var (S)

=np(1− p)

n2

=p (1− p)

n

σS/n =

√p (1− p)

n

Decreases as n grows!

Page 109: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Election

S is a sum of n coin flips with p = # /T

S =n∑

i=1

Vi

Var(S

n

)=

1n2 Var (S)

=np(1− p)

n2

=p (1− p)

n

σS/n =

√p (1− p)

n

Decreases as n grows!

Page 110: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Election

S is a sum of n coin flips with p = # /T

S =n∑

i=1

Vi

Var(S

n

)=

1n2 Var (S)

=np(1− p)

n2

=p (1− p)

n

σS/n =

√p (1− p)

n

Decreases as n grows!

Page 111: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Fraction of voters in poll, n = 100, # /T = 0.547

0.547

0

2

4

6

8

·10−2

x

P(S

/n=x)

Page 112: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Fraction of voters in poll, n = 1000, # /T = 0.547

0.547

0

1

2

·10−2

x

P(S

/n=x)

Page 113: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Poll of 1 000 people (repeated 10 000 times)

Page 114: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Poll of 10 000 people (repeated 10 000 times)

Page 115: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Poll of 100 000 people (repeated 10 000 times)

Page 116: Predicting the Outcome of an Election - NYU Courantcfgranda/pages/stuff/election.pdf · Predicting the Outcome of an Election Carlos Fernandez-Granda cfgranda cSplash2018

Some elections are difficult to predict

I It’s very hard to sample a population uniformly

I Also hard to make samples independent

I Often not interested in just popular vote (e.g. presidential election)