The approximation shortcut

Inference for Categorical Data in R

Andrew Bray

Assistant Professor of Statistics at Reed College

Confidence Intervals

SE
0.009998905
SE_small_n
0.03809731
SE_low_p
0.00547912

Standard errors increase when

  • n is small
  • p is close to 0.5
Inference for Categorical Data in R

bootstrap_one.png

Inference for Categorical Data in R

bootstrap_two.png

Inference for Categorical Data in R

The normal distribution

A.K.A the "bell curve".

If

  • observations are independent
  • n is large

Then

  • $\hat{p}$ follows a normal distribution

ch1v3-normal-curve.png

Inference for Categorical Data in R

Standard deviation

$$\sqrt{\frac{ \hat{p} \times (1 - \hat{p})}{n}}$$

Inference for Categorical Data in R

Assessing model assumptions

How do I check "observations are independent"?

  • This depends upon the data collection method.

What does "n is large" mean?

  • $n \times \hat{p} \gt 10$
  • $n \times(1 - \hat{p}) \gt 10$
Inference for Categorical Data in R

Calculating standard error: approximation

p_hat <- gss2016 %>%
  summarize(mean(happy == "HAPPY")) %>%
  pull()
n <- nrow(gss2016)
c(n * p_hat, n * (1 - p_hat))
116  35
SE_approx <- sqrt(p_hat * (1 - p_hat) / n)
SE_approx
0.03418468
Inference for Categorical Data in R

Calculating standard error: computation

boot <- gss2016 %>%
  specify(response = happy, success = "HAPPY") %>%
  generate(reps = 500, type = "bootstrap") %>%
  calculate(stat = "prop")
SE_boot <- boot %>%
  summarize(sd(stat)) %>%
  pull()
SE_boot
0.03176741
Inference for Categorical Data in R

Sampling distributions

ggplot(boot, aes(x = stat)) +
  geom_density()

ch1v3-density-curve-1.png

Inference for Categorical Data in R

Sampling distributions

ggplot(boot, aes(x = stat)) +
  geom_density() +
  stat_function(fun = dnorm, 
                color = "purple",
                args = 
                  list(mean = p_hat,
                       sd = SE_approx))

ch1v3-density-curve-1.png

Inference for Categorical Data in R

Sampling distributions

ggplot(boot, aes(x = stat)) +
  geom_density() +
  stat_function(fun = dnorm, 
                color = "purple",
                args = 
                  list(mean = p_hat,
                       sd = SE_approx))

ch1v3-density-curve-2.png

Inference for Categorical Data in R

Let's practice!

Inference for Categorical Data in R

Preparing Video For Download...