t h e n o rm a l d i stri b u ti o n · 2019-04-29 · f o u nd ati o ns o f p r o b a b i li ty i...

18
The normal distribution FOUNDATIONS OF PROBABILITY IN R David Robinson Chief Data Scientist, DataCamp

Upload: others

Post on 02-Aug-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: T h e n o rm a l d i stri b u ti o n · 2019-04-29 · F O U ND ATI O NS O F P R O B A B I LI TY I N R Properti es of the Poi s s on di s tri buti on binomial

The normal distributionF O U N D AT I O N S O F P R O B A B I L I T Y I N R

David RobinsonChief Data Scientist, DataCamp

Page 2: T h e n o rm a l d i stri b u ti o n · 2019-04-29 · F O U ND ATI O NS O F P R O B A B I LI TY I N R Properti es of the Poi s s on di s tri buti on binomial

FOUNDATIONS OF PROBABILITY IN R

Flipping 10 coins

flips <- rbinom(100000, 10, .5)

Page 3: T h e n o rm a l d i stri b u ti o n · 2019-04-29 · F O U ND ATI O NS O F P R O B A B I LI TY I N R Properti es of the Poi s s on di s tri buti on binomial

FOUNDATIONS OF PROBABILITY IN R

Flipping 1000 coins

flips <- rbinom(100000, 1000, .5)

Page 4: T h e n o rm a l d i stri b u ti o n · 2019-04-29 · F O U ND ATI O NS O F P R O B A B I LI TY I N R Properti es of the Poi s s on di s tri buti on binomial

FOUNDATIONS OF PROBABILITY IN R

Flipping 1000 coins

Page 5: T h e n o rm a l d i stri b u ti o n · 2019-04-29 · F O U ND ATI O NS O F P R O B A B I LI TY I N R Properti es of the Poi s s on di s tri buti on binomial

FOUNDATIONS OF PROBABILITY IN R

Normal distribution has mean and standarddeviation

X ∼ Normal(μ,σ) σ = √ Var(X)

Page 6: T h e n o rm a l d i stri b u ti o n · 2019-04-29 · F O U ND ATI O NS O F P R O B A B I LI TY I N R Properti es of the Poi s s on di s tri buti on binomial

FOUNDATIONS OF PROBABILITY IN R

Normal approximation to the binomial

binomial <- rbinom(100000, 1000, .5)

μ = size ⋅ p

σ =

expected_value <- 1000 * .5

variance <- 1000 * .5 * (1 - .5)

stdev <- sqrt(variance)

normal <- rnorm(100000, expected_value, stdev)

√ size ⋅ p ⋅ (1 − p)

Page 7: T h e n o rm a l d i stri b u ti o n · 2019-04-29 · F O U ND ATI O NS O F P R O B A B I LI TY I N R Properti es of the Poi s s on di s tri buti on binomial

FOUNDATIONS OF PROBABILITY IN R

Comparing histograms

compare_histograms(binomial, normal)

Page 8: T h e n o rm a l d i stri b u ti o n · 2019-04-29 · F O U ND ATI O NS O F P R O B A B I LI TY I N R Properti es of the Poi s s on di s tri buti on binomial

Let's practice!F O U N D AT I O N S O F P R O B A B I L I T Y I N R

Page 9: T h e n o rm a l d i stri b u ti o n · 2019-04-29 · F O U ND ATI O NS O F P R O B A B I LI TY I N R Properti es of the Poi s s on di s tri buti on binomial

The Poisson distributionF O U N D AT I O N S O F P R O B A B I L I T Y I N R

David RobinsonChief Data Scientist, DataCamp

Page 10: T h e n o rm a l d i stri b u ti o n · 2019-04-29 · F O U ND ATI O NS O F P R O B A B I LI TY I N R Properti es of the Poi s s on di s tri buti on binomial

FOUNDATIONS OF PROBABILITY IN R

Flipping many coins, each with low probability

binomial <- rbinom(100000, 1000, 1 / 1000)

Page 11: T h e n o rm a l d i stri b u ti o n · 2019-04-29 · F O U ND ATI O NS O F P R O B A B I LI TY I N R Properti es of the Poi s s on di s tri buti on binomial

FOUNDATIONS OF PROBABILITY IN R

Properties of the Poisson distributionbinomial <- rbinom(100000, 1000,

1 / 1000)

poisson <- rpois(100000, 1)

compare_histograms(binomial,

poisson)

X ∼ Poisson(λ)

E[X] = λ

Var(X) = λ

Page 12: T h e n o rm a l d i stri b u ti o n · 2019-04-29 · F O U ND ATI O NS O F P R O B A B I LI TY I N R Properti es of the Poi s s on di s tri buti on binomial

FOUNDATIONS OF PROBABILITY IN R

Poisson distribution

Page 13: T h e n o rm a l d i stri b u ti o n · 2019-04-29 · F O U ND ATI O NS O F P R O B A B I LI TY I N R Properti es of the Poi s s on di s tri buti on binomial

Let's practice!F O U N D AT I O N S O F P R O B A B I L I T Y I N R

Page 14: T h e n o rm a l d i stri b u ti o n · 2019-04-29 · F O U ND ATI O NS O F P R O B A B I LI TY I N R Properti es of the Poi s s on di s tri buti on binomial

The geometric distributionF O U N D AT I O N S O F P R O B A B I L I T Y I N R

David RobinsonChief Data Scientist, DataCamp

Page 15: T h e n o rm a l d i stri b u ti o n · 2019-04-29 · F O U ND ATI O NS O F P R O B A B I LI TY I N R Properti es of the Poi s s on di s tri buti on binomial

FOUNDATIONS OF PROBABILITY IN R

Simulating waiting for heads

flips <- rbinom(100, 1, .1)

flips

# [1] 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0

# [16] 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0

which(flips == 1)

# [1] 8 27 44 55 82 89

which(flips == 1)[1]

# [1] 8

Page 16: T h e n o rm a l d i stri b u ti o n · 2019-04-29 · F O U ND ATI O NS O F P R O B A B I LI TY I N R Properti es of the Poi s s on di s tri buti on binomial

FOUNDATIONS OF PROBABILITY IN R

Replicating simulationswhich(rbinom(100, 1, .1) == 1)[1]

# [1] 28

which(rbinom(100, 1, .1) == 1)[1]

# [1] 4

which(rbinom(100, 1, .1) == 1)[1]

# [1] 11

replicate(10, which(rbinom(100, 1, .1) == 1)[1])

# [1] 22 12 6 7 35 2 4 44 4 2

Page 17: T h e n o rm a l d i stri b u ti o n · 2019-04-29 · F O U ND ATI O NS O F P R O B A B I LI TY I N R Properti es of the Poi s s on di s tri buti on binomial

FOUNDATIONS OF PROBABILITY IN R

Simulating with rgeom

geom <- rgeom(100000, .1)

mean(geom)

# [1] 9.04376

X ∼ Geom(p)

E[X] = − 1p

1

Page 18: T h e n o rm a l d i stri b u ti o n · 2019-04-29 · F O U ND ATI O NS O F P R O B A B I LI TY I N R Properti es of the Poi s s on di s tri buti on binomial

Let's practice!F O U N D AT I O N S O F P R O B A B I L I T Y I N R