Sampling Distributions - GitHub Pages · Every statistic has a sampling distribution, but not all...

49
Sampling Distributions David Gerard 2017-09-18 1

Transcript of Sampling Distributions - GitHub Pages · Every statistic has a sampling distribution, but not all...

Page 1: Sampling Distributions - GitHub Pages · Every statistic has a sampling distribution, but not all sampling distributions converge to a normal hist(max_vec,main="Sampling distribution

Sampling Distributions

David Gerard

2017-09-18

1

Page 2: Sampling Distributions - GitHub Pages · Every statistic has a sampling distribution, but not all sampling distributions converge to a normal hist(max_vec,main="Sampling distribution

Learning Objectives

• Statistics/parameters

• Sampling Distribution

• Sections 1.3.1, 1.3.2, 1.3.3, 4.1, 4.4 in DBC

2

Page 3: Sampling Distributions - GitHub Pages · Every statistic has a sampling distribution, but not all sampling distributions converge to a normal hist(max_vec,main="Sampling distribution

Population and Sample

Page 4: Sampling Distributions - GitHub Pages · Every statistic has a sampling distribution, but not all sampling distributions converge to a normal hist(max_vec,main="Sampling distribution

Recall: Population and Sample

population

A population is a set of cases (observational units) about which

information is wanted.

sample

A sample is a subset of the population.

3

Page 5: Sampling Distributions - GitHub Pages · Every statistic has a sampling distribution, but not all sampling distributions converge to a normal hist(max_vec,main="Sampling distribution

Examples

• We want to know demographic information of Americans so

we randomly select a group of 50 Americans and ask them a

bunch of questions. (sample? population?)

• We are interested in the quality of anchovies so we take 10

cans and taste them. (sample? population?)

4

Page 6: Sampling Distributions - GitHub Pages · Every statistic has a sampling distribution, but not all sampling distributions converge to a normal hist(max_vec,main="Sampling distribution

Why sample?

• It is expensive/impossible to collect information on the whole

population (when this is done it is called a census).

• Even when a census is performed, it is often less accurate

than a well-designed sample (hard to collect information on

everything, so this introduces biases into the observations you

see).

• With a large enough sample, we can be pretty sure of the

information we want on the population, making taking a

census unnecessary.

5

Page 7: Sampling Distributions - GitHub Pages · Every statistic has a sampling distribution, but not all sampling distributions converge to a normal hist(max_vec,main="Sampling distribution

Random Sampling

• Often, samples are collected randomly to remove bias.

• bias is where some cases are more likely to be in the sample

than other cases.

• E.g. some political pollsters mostly call landlines, which biases

the sample toward older individuals. What could be the issue

here?

6

Page 8: Sampling Distributions - GitHub Pages · Every statistic has a sampling distribution, but not all sampling distributions converge to a normal hist(max_vec,main="Sampling distribution

Statistics and Parameters

parameter

A parameter is a number that describes a population. It is

usually unknown and what we want information on. People

usually use greek letter µ, σ, ρ to represent parameters.

statistic

A statistic is a number that describes a sample. It is known and

is used to estimate a population parameter. People usually use

latin letters x̄ , s, r to represent statistics.

7

Page 9: Sampling Distributions - GitHub Pages · Every statistic has a sampling distribution, but not all sampling distributions converge to a normal hist(max_vec,main="Sampling distribution

Example

• We want to know the average height of U.S. males so we

measure the average height of a sample of 50 U.S. males and

came up with 5’11”. (parameter? statistic?)

8

Page 10: Sampling Distributions - GitHub Pages · Every statistic has a sampling distribution, but not all sampling distributions converge to a normal hist(max_vec,main="Sampling distribution

The sample mean

Page 11: Sampling Distributions - GitHub Pages · Every statistic has a sampling distribution, but not all sampling distributions converge to a normal hist(max_vec,main="Sampling distribution

Recall: NBA Data

Player statistics for the 2016-2017 season of the NBA

• player The name of the player.

• pts The total points for the season

• two pp Two point field goal percentage.

• three pp Three point field goal percentage.

• Many others ...

• Here, I only kept players that attempted at least 20 two-point

and 20 three-point field goals.

9

Page 12: Sampling Distributions - GitHub Pages · Every statistic has a sampling distribution, but not all sampling distributions converge to a normal hist(max_vec,main="Sampling distribution

Recall: NBA Data

library(tidyverse)

nba <- read_csv("../../data/nba2016.csv") %>%

filter(two_pa >= 20, three_pa >= 20) %>%

select(player, pts, two_pp, three_pp)

glimpse(nba)

Observations: 337

Variables: 4

$ player <chr> "Russell Westbrook", "James Harden", "...

$ pts <int> 2558, 2356, 2199, 2099, 2061, 2024, 20...

$ two_pp <dbl> 0.459, 0.530, 0.528, 0.524, 0.582, 0.4...

$ three_pp <dbl> 0.343, 0.347, 0.379, 0.299, 0.367, 0.3...

10

Page 13: Sampling Distributions - GitHub Pages · Every statistic has a sampling distribution, but not all sampling distributions converge to a normal hist(max_vec,main="Sampling distribution

The inference problem

• Suppose I want to know the average total points of NBA

players. However, I can only collect a sample of 5 players.

nsamp <- 5

samd <- sample(nba$pts, size = nsamp)

samd

[1] 709 479 130 1028 142

11

Page 14: Sampling Distributions - GitHub Pages · Every statistic has a sampling distribution, but not all sampling distributions converge to a normal hist(max_vec,main="Sampling distribution

Point Estimate

Of course, we know the actual mean number of points µ because

we have the entire population.

mean(nba$pts)

[1] 666.4

A good estimate might be the average of the sample x̄

mean(samd)

[1] 497.6

12

Page 15: Sampling Distributions - GitHub Pages · Every statistic has a sampling distribution, but not all sampling distributions converge to a normal hist(max_vec,main="Sampling distribution

Point Estimate

The sample average here is a point estimate of the population

mean.

point estimate

A point estimate is a single number used to estimate a

population parameter.

13

Page 16: Sampling Distributions - GitHub Pages · Every statistic has a sampling distribution, but not all sampling distributions converge to a normal hist(max_vec,main="Sampling distribution

Aside

• How would you estimate the population median?

• How would you estimate the population standard deviation?

14

Page 17: Sampling Distributions - GitHub Pages · Every statistic has a sampling distribution, but not all sampling distributions converge to a normal hist(max_vec,main="Sampling distribution

A different sample

However, since the sample was drawn at random, we could have

obtained a different sample, and so a different point estimate.

samd <- sample(nba$pts, size = nsamp)

samd

[1] 94 419 435 1742 1025

mean(samd)

[1] 743

15

Page 18: Sampling Distributions - GitHub Pages · Every statistic has a sampling distribution, but not all sampling distributions converge to a normal hist(max_vec,main="Sampling distribution

And another sample

samd <- sample(nba$pts, size = nsamp)

samd

[1] 1071 381 689 282 551

mean(samd)

[1] 594.8

16

Page 19: Sampling Distributions - GitHub Pages · Every statistic has a sampling distribution, but not all sampling distributions converge to a normal hist(max_vec,main="Sampling distribution

And another sample

samd <- sample(nba$pts, size = nsamp)

samd

[1] 327 59 700 281 107

mean(samd)

[1] 294.8

17

Page 20: Sampling Distributions - GitHub Pages · Every statistic has a sampling distribution, but not all sampling distributions converge to a normal hist(max_vec,main="Sampling distribution

And another sample

samd <- sample(nba$pts, size = nsamp)

samd

[1] 1002 425 1196 864 689

mean(samd)

[1] 835.2

18

Page 21: Sampling Distributions - GitHub Pages · Every statistic has a sampling distribution, but not all sampling distributions converge to a normal hist(max_vec,main="Sampling distribution

Sampling distribution

• With every sample we are getting a different x̄ .

• We can ask what possible values x̄ can take and how often it

takes those values.

• That is, we can ask about x̄ ’s distribution.

19

Page 22: Sampling Distributions - GitHub Pages · Every statistic has a sampling distribution, but not all sampling distributions converge to a normal hist(max_vec,main="Sampling distribution

Sampling distribution

sampling distribution

A sampling distribution is the distribution of a sample statistic.

20

Page 23: Sampling Distributions - GitHub Pages · Every statistic has a sampling distribution, but not all sampling distributions converge to a normal hist(max_vec,main="Sampling distribution

Repeat sample 1000 times.

itermax <- 1000

xbar_vec <- rep(NA, itermax)

for (index in 1:itermax) {samd <- sample(nba$pts, size = nsamp)

xbar_vec[index] <- mean(samd)

}

21

Page 24: Sampling Distributions - GitHub Pages · Every statistic has a sampling distribution, but not all sampling distributions converge to a normal hist(max_vec,main="Sampling distribution

Plot the results

hist(xbar_vec, main = "")

abline(v = mean(nba$pts), lty = 2, col = 2, lwd = 2)

legend("topright", "pop mean", lty = 2, col = 2, lwd = 2)

xbar_vec

Fre

quen

cy

500 1000 1500

050

100

150

pop mean

22

Page 25: Sampling Distributions - GitHub Pages · Every statistic has a sampling distribution, but not all sampling distributions converge to a normal hist(max_vec,main="Sampling distribution

The sampling distribution

• The sample mean has the correct center.

• There is a lot of variability about that center though.

sd(xbar_vec)

[1] 227.7

standard error

The standard deviation associated with a point estimate is called

a standard error.

23

Page 26: Sampling Distributions - GitHub Pages · Every statistic has a sampling distribution, but not all sampling distributions converge to a normal hist(max_vec,main="Sampling distribution

What if we have a bigger sample

nsamp <- 10

xbar10_vec <- rep(NA, itermax)

for (index in 1:itermax) {samd <- sample(nba$pts, size = nsamp)

xbar10_vec[index] <- mean(samd)

}sd(xbar10_vec)

[1] 156.3

24

Page 27: Sampling Distributions - GitHub Pages · Every statistic has a sampling distribution, but not all sampling distributions converge to a normal hist(max_vec,main="Sampling distribution

What if we have a bigger sample

nsamp <- 50

xbar50_vec <- rep(NA, itermax)

for (index in 1:itermax) {samd <- sample(nba$pts, size = nsamp)

xbar50_vec[index] <- mean(samd)

}sd(xbar50_vec)

[1] 66.51

25

Page 28: Sampling Distributions - GitHub Pages · Every statistic has a sampling distribution, but not all sampling distributions converge to a normal hist(max_vec,main="Sampling distribution

What if we have a bigger sample

nsamp <- 100

xbar100_vec <- rep(NA, itermax)

for (index in 1:itermax) {samd <- sample(nba$pts, size = nsamp)

xbar100_vec[index] <- mean(samd)

}sd(xbar100_vec)

[1] 42.61

26

Page 29: Sampling Distributions - GitHub Pages · Every statistic has a sampling distribution, but not all sampling distributions converge to a normal hist(max_vec,main="Sampling distribution

Standard error decreases with larger sample sizes!

400

800

1200

5 10 50 100

SampleSize

xbar

Dashed red line is population mean.

27

Page 30: Sampling Distributions - GitHub Pages · Every statistic has a sampling distribution, but not all sampling distributions converge to a normal hist(max_vec,main="Sampling distribution

Standard error

standard error

Given n independent observations from a population with

standard deviation σ, the standard error of the sample mean is

equal to

SE =σ√n.

• Since σ is generally unknown, we estimate SE with s/√n,

where s is the sample standard deviation.

28

Page 31: Sampling Distributions - GitHub Pages · Every statistic has a sampling distribution, but not all sampling distributions converge to a normal hist(max_vec,main="Sampling distribution

What happens as sample size increases?

Histogram of points

Points

Den

sity

0 500 1000 1500 2000 2500

0.00

000.

0006

0.00

12

29

Page 32: Sampling Distributions - GitHub Pages · Every statistic has a sampling distribution, but not all sampling distributions converge to a normal hist(max_vec,main="Sampling distribution

What happens as sample size increases?

Histogram of xbar

Mean Points, n = 5

Den

sity

200 400 600 800 1000 1200 1400 1600

0.00

000.

0010

0.00

20

30

Page 33: Sampling Distributions - GitHub Pages · Every statistic has a sampling distribution, but not all sampling distributions converge to a normal hist(max_vec,main="Sampling distribution

What happens as sample size increases?

Histogram of xbar

Mean Points, n = 5

Den

sity

500 600 700 800 900

0.00

00.

002

0.00

40.

006

31

Page 34: Sampling Distributions - GitHub Pages · Every statistic has a sampling distribution, but not all sampling distributions converge to a normal hist(max_vec,main="Sampling distribution

Wat happens as the sample size increases?

n = 1

qqnorm(nba$pts)

qqline(nba$pts)

−3 −2 −1 0 1 2 3

050

015

0025

00

Normal Q−Q Plot

Theoretical Quantiles

Sam

ple

Qua

ntile

s

32

Page 35: Sampling Distributions - GitHub Pages · Every statistic has a sampling distribution, but not all sampling distributions converge to a normal hist(max_vec,main="Sampling distribution

Wat happens as the sample size increases?

n = 5

qqnorm(xbar_vec)

qqline(xbar_vec)

−3 −2 −1 0 1 2 3

200

600

1000

1400

Normal Q−Q Plot

Theoretical Quantiles

Sam

ple

Qua

ntile

s

33

Page 36: Sampling Distributions - GitHub Pages · Every statistic has a sampling distribution, but not all sampling distributions converge to a normal hist(max_vec,main="Sampling distribution

Wat happens as the sample size increases?

n = 50

qqnorm(xbar50_vec)

qqline(xbar50_vec)

−3 −2 −1 0 1 2 3

500

600

700

800

900

Normal Q−Q Plot

Theoretical Quantiles

Sam

ple

Qua

ntile

s

34

Page 37: Sampling Distributions - GitHub Pages · Every statistic has a sampling distribution, but not all sampling distributions converge to a normal hist(max_vec,main="Sampling distribution

General result

• In general, sample means converge to a normal distribution as

the sample size increases.

• Many other statistics do this as well (proportions, medians,

standard devaitions).

• We will provide a heuristic proof of this result later.

35

Page 38: Sampling Distributions - GitHub Pages · Every statistic has a sampling distribution, but not all sampling distributions converge to a normal hist(max_vec,main="Sampling distribution

Skewed distributions

For highly skewed distributions, it takes more samples for normality

to be a good approximation.

data(email, package = "openintro")

hist(email$num_char)

Histogram of email$num_char

email$num_char

Fre

quen

cy

0 50 100 150 200

010

0020

0030

00

36

Page 39: Sampling Distributions - GitHub Pages · Every statistic has a sampling distribution, but not all sampling distributions converge to a normal hist(max_vec,main="Sampling distribution

Skewed distributions, n = 5

Histogram of xvec

xvec

Fre

quen

cy

0 10 20 30 40 50

010

020

030

0

37

Page 40: Sampling Distributions - GitHub Pages · Every statistic has a sampling distribution, but not all sampling distributions converge to a normal hist(max_vec,main="Sampling distribution

Skewed distributions, n = 10

Histogram of xvec

xvec

Fre

quen

cy

5 10 15 20 25 30

050

100

150

200

38

Page 41: Sampling Distributions - GitHub Pages · Every statistic has a sampling distribution, but not all sampling distributions converge to a normal hist(max_vec,main="Sampling distribution

Skewed distributions, n = 50

Histogram of xvec

xvec

Fre

quen

cy

6 8 10 12 14 16 18

050

100

150

200

39

Page 42: Sampling Distributions - GitHub Pages · Every statistic has a sampling distribution, but not all sampling distributions converge to a normal hist(max_vec,main="Sampling distribution

Skewed distributions, n = 100

Histogram of xvec

xvec

Fre

quen

cy

6 8 10 12 14 16

050

150

250

40

Page 43: Sampling Distributions - GitHub Pages · Every statistic has a sampling distribution, but not all sampling distributions converge to a normal hist(max_vec,main="Sampling distribution

More sampling distributions

Page 44: Sampling Distributions - GitHub Pages · Every statistic has a sampling distribution, but not all sampling distributions converge to a normal hist(max_vec,main="Sampling distribution

Every statistic has a sampling distribution

nsamp <- 50

sd_vec <- rep(NA, itermax)

for (index in 1:itermax) {samd <- sample(nba$pts, size = nsamp)

sd_vec[index] <- sd(samd)

}

41

Page 45: Sampling Distributions - GitHub Pages · Every statistic has a sampling distribution, but not all sampling distributions converge to a normal hist(max_vec,main="Sampling distribution

Every statistic has a sampling distribution

hist(sd_vec, main = "Sampling distribution

of sample standard deviation",

xlab = "sd")

Sampling distribution of sample standard deviation

sd

Fre

quen

cy

300 400 500 600 700

050

150

250

42

Page 46: Sampling Distributions - GitHub Pages · Every statistic has a sampling distribution, but not all sampling distributions converge to a normal hist(max_vec,main="Sampling distribution

Every statistic has a sampling distribution

nsamp <- 50

med_vec <- rep(NA, itermax)

for (index in 1:itermax) {samd <- sample(nba$pts, size = nsamp)

med_vec[index] <- median(samd)

}

43

Page 47: Sampling Distributions - GitHub Pages · Every statistic has a sampling distribution, but not all sampling distributions converge to a normal hist(max_vec,main="Sampling distribution

Every statistic has a sampling distribution

hist(med_vec, main = "Sampling distribution

of sample median",

xlab = "median")

Sampling distribution of sample median

median

Fre

quen

cy

300 400 500 600 700 800

010

020

030

0

44

Page 48: Sampling Distributions - GitHub Pages · Every statistic has a sampling distribution, but not all sampling distributions converge to a normal hist(max_vec,main="Sampling distribution

Every statistic has a sampling distribution, but not all sampling

distributions converge to a normal

nsamp <- 50

max_vec <- rep(NA, itermax)

for (index in 1:itermax) {samd <- sample(nba$pts, size = nsamp)

max_vec[index] <- max(samd)

}

45

Page 49: Sampling Distributions - GitHub Pages · Every statistic has a sampling distribution, but not all sampling distributions converge to a normal hist(max_vec,main="Sampling distribution

Every statistic has a sampling distribution, but not all sampling

distributions converge to a normal

hist(max_vec, main = "Sampling distribution

of sample maximum",

xlab = "max")

Sampling distribution of sample maximum

max

Fre

quen

cy

1200 1400 1600 1800 2000 2200 2400 2600

050

150

250

46