Metodo alternativo: distribuzione chi-quadro

Inferenza per dati categorici in R

Andrew Bray

Assistant Professor of Statistics at Reed College

Distribuzioni approssimanti: normale

  • Statistiche: $\hat{p}, \hat{p}_{1} - \hat{p}_{2}$

Curva normale

Inferenza per dati categorici in R

Distribuzioni approssimanti: chi-quadro

  • Statistiche: $\hat{x}^{2}$
  • La forma è determinata dai gradi di libertà
  • $df = (nrows - 1) \times (ncols - 1)$

Curva chi-quadro

Inferenza per dati categorici in R

Test H con approssimazione

null_spac <- gss_party %>%
  specify(natspac ~ party) %>%
  hypothesize(null = "independence") %>%
  generate(reps = 100, type = "permute") %>%
  calculate(stat = "Chisq")
ggplot(null_spac, aes(x = stat)) +
  geom_density() +
  stat_function(
    fun = dchisq, 
    args = list(df = 4), 
    color = "blue"
  ) +
  geom_vline(xintercept = chi_obs_spac, color = "red")

Test H tramite approssimazione

Inferenza per dati categorici in R

Test H con approssimazione

gss_party %>%
  select(natarms, party) %>%
  table()
             party
natarms        D  I  R
  TOO LITTLE  17 20 24
  ABOUT RIGHT 14 28  8
  TOO MUCH    12 24  2
pchisq(chi_obs_spac, df = 4)
X-squared 
0.1430612
1 - pchisq(chi_obs_spac, df = 4)
X-squared 
0.8569388

Test H tramite approssimazione

Inferenza per dati categorici in R

La distribuzione chi-quadro

Diventa una buona approssimazione quando:

  • $expected\_count >= 5$
  • $df >= 2$

Curva chi-quadro

Inferenza per dati categorici in R

Passiamo alla pratica !

Inferenza per dati categorici in R

Preparing Video For Download...