Randomized distributions

Foundations of Inference in R

Jo Hardin

Instructor

Logic of inference

ch1_2_v2_infer.002.png

Foundations of Inference in R

Logic of inference

ch1_2_v2_infer.003.png

Foundations of Inference in R

Logic of inference

ch1_2_v2_infer.004.png

Foundations of Inference in R

Logic of inference

ch1_2_v2_infer.005.png

Foundations of Inference in R

Logic of inference

ch1_2_v2_infer.006.png

Foundations of Inference in R

Logic of inference

Foundations of Inference in R

Understanding the null distribution

 

Generating a distribution of the statistic from the null population gives information about whether the observed data are inconsistent with the null hypothesis

Foundations of Inference in R

Understanding the null distribution

Original data

Location Cola Orange
East 28 6
West 19 7

 

$\hat{p}_\text{east} = 28/(28 + 6) = 0.82$

$\hat{p}_\text{west} = 19/(19 + 7) = 0.73$

Foundations of Inference in R

Understanding the null distribution

First shuffle, same as original

Location Cola Orange
East 28 6
West 19 7

ch1_2_v2_infer.017.png

Foundations of Inference in R

Understanding the null distribution

Second shuffle

Location Cola Orange
East 27 7
West 20 6

ch1_2_v2_infer.019.png

Foundations of Inference in R

Understanding the null distribution

Third shuffle

Location Cola Orange
East 28 8
West 21 5

ch1_2_v2_infer.020.png

Foundations of Inference in R

Understanding the null distribution

Fourth shuffle

Location Cola Orange
East 25 9
West 22 4

ch1_2_v2_infer.021.png

Foundations of Inference in R

Understanding the null distribution

Fifth shuffle

Location Cola Orange
East 29 5
West 18 8

ch1_2_v2_infer.022.png

Foundations of Inference in R

Understanding the null distribution

Fifth shuffle

Location Cola Orange
East 29 5
West 18 8

ch1_2_v2_infer.023.png

Foundations of Inference in R

Understanding the null distribution

ch1_2_v2_infer.024.png

Foundations of Inference in R

Understanding the null distribution

ch1_2_v2_infer.025.png

Foundations of Inference in R

Understanding the null distribution

ch1_2_v2_infer.026.png

Foundations of Inference in R

Understanding the null distribution

ch1_2_v2_infer.027.png

Foundations of Inference in R

Understanding the null distribution

ch1_2_v2_infer.028.png

Foundations of Inference in R

Understanding the null distribution

ch1_2_v2_infer.029.png

Foundations of Inference in R

One random permutation

soda %>%
group_by(location) %>%
summarize(prop_cola = 
    mean(drink == "cola")) %>%
summarize(diff(prop_cola))
# A tibble: 1 x 1
  `diff(prop_cola)`
              <dbl>
1        -0.09276018
library(infer)
soda %>% specify(drink ~ location,
                success = "cola") %>%
hypothesize(null = "independence") %>%
generate(reps = 1, type = "permute") %>%
calculate(stat = "diff in props", 
            order = c("west","east"))
# A tibble: 1 x 2
  replicate        stat
      <int>        <dbl>
1        1    -0.02488688
Foundations of Inference in R

Many random permutations

soda %>%
  specify(drink ~ location, success = "cola") %>%
  hypothesize(null = "independence") %>%
  generate(reps = 5, type = "permute") %>%
  calculate(stat = "diff in props", order = c("west", "east"))
# A tibble: 5 x 2
  replicate        stat
      <int>       <dbl>
1         1  0.04298643
2         2 -0.09276018
3         3  0.11085973
4         4  0.17873303
5         5 -0.16063348
Foundations of Inference in R

Random distribution

ch1_2_v2_infer.047.png

Foundations of Inference in R

Let's practice!

Foundations of Inference in R

Preparing Video For Download...