La scorciatoia dell’approssimazione

Inferenza per dati categorici in R

Andrew Bray

Assistant Professor of Statistics at Reed College

Intervalli di confidenza

SE
0.009998905
SE_small_n
0.03809731
SE_low_p
0.00547912

L’errore standard aumenta quando

  • n è piccolo
  • p è vicino a 0,5
Inferenza per dati categorici in R

Diagramma di approssimazione 1

Inferenza per dati categorici in R

Diagramma di approssimazione 2

Inferenza per dati categorici in R

La distribuzione normale

Anche detta “curva a campana”.

Se

  • le osservazioni sono indipendenti
  • n è grande

Allora

  • $\hat{p}$ segue una distribuzione normale

Curva normale ch1v3

Inferenza per dati categorici in R

Deviazione standard

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

Inferenza per dati categorici in R

Verificare le assunzioni del modello

Come verifico che “le osservazioni sono indipendenti”?

  • Dipende dal metodo di raccolta dati.

Cosa significa “n è grande”?

  • $n \times \hat{p} \gt 10$
  • $n \times(1 - \hat{p}) \gt 10$
Inferenza per dati categorici in R

Calcolo dell’errore standard: approssimazione

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
Inferenza per dati categorici in R

Calcolo dell’errore standard: computazione

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
Inferenza per dati categorici in R

Distribuzioni campionarie

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

Curva di densità ch1v3-1.png

Inferenza per dati categorici in R

Distribuzioni campionarie

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

Curva di densità ch1v3-1.png

Inferenza per dati categorici in R

Distribuzioni campionarie

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

Curva di densità ch1v3-2.png

Inferenza per dati categorici in R

Ayo berlatih!

Inferenza per dati categorici in R

Preparing Video For Download...