ANOVA non paramétrique et tests t non appariés

Tests d'hypothèse en R

Richie Cotton

Data Evangelist at DataCamp

Tests non paramétriques

Un test non paramétrique est un test d'hypothèse qui ne suppose aucune loi de probabilité pour la statistique de test.

Il existe deux types de tests d'hypothèse non paramétriques :

  1. Basés sur la simulation.
  2. Basés sur les rangs.
Tests d'hypothèse en R

t_test()

$H_{0}$ : $\mu_{child} - \mu_{adult} = 0$ $H_{A}$ : $\mu_{child} - \mu_{adult} > 0$

library(infer)
stack_overflow %>% 
  t_test(
    converted_comp ~ age_first_code_cut,
    order = c("child", "adult"),
    alternative = "greater"
  )
# A tibble: 1 x 6
  statistic  t_df p_value alternative lower_ci upper_ci
      <dbl> <dbl>   <dbl> <chr>          <dbl>    <dbl>
1      2.40 2083. 0.00814 greater        8438.      Inf
Tests d'hypothèse en R

Calcul de la distribution nulle

Chaîne basée sur la simulation
null_distn <- stack_overflow %>% 
  specify(converted_comp ~ age_first_code_cut) %>%

hypothesize(null = "independence") %>%
generate(reps = 5000, type = "permute") %>%
calculate( stat = "diff in means", order = c("child", "adult") )
Test t, pour comparaison
library(infer)
stack_overflow %>% 
  t_test(
    converted_comp ~ age_first_code_cut,
    order = c("child", "adult"),
    alternative = "greater"
  )
Tests d'hypothèse en R

Calcul de la statistique observée

Chaîne basée sur la simulation
obs_stat <- stack_overflow %>% 
  specify(converted_comp ~ age_first_code_cut) %>% 
  calculate(
    stat = "diff in means", 
    order = c("child", "adult")
  )
Test t, pour comparaison
library(infer)
stack_overflow %>% 
  t_test(
    converted_comp ~ age_first_code_cut,
    order = c("child", "adult"),
    alternative = "greater"
  )
Tests d'hypothèse en R

Obtenir la valeur p

Chaîne basée sur la simulation
get_p_value(
  null_distn, obs_stat, 
  direction = "greater"
)
# A tibble: 1 x 1
  p_value
    <dbl>
1  0.0066
Test t, pour comparaison
library(infer)
stack_overflow %>% 
  t_test(
    converted_comp ~ age_first_code_cut,
    order = c("child", "adult"),
    alternative = "greater"
  )
# A tibble: 1 x 6
  statistic  t_df p_value alternative lower_ci upper_ci
      <dbl> <dbl>   <dbl> <chr>          <dbl>    <dbl>
1      2.40 2083. 0.00814 greater        8438.      Inf
Tests d'hypothèse en R

Rangs de vecteurs

x <- c(1, 15, 3, 10, 6)
rank(x)
1 5 2 4 3

Un test de Wilcoxon-Mann-Whitney (aussi appelé test de la somme des rangs de Wilcoxon) est, très grossièrement, un test t appliqué aux rangs de l'entrée numérique.

Tests d'hypothèse en R

Test de Wilcoxon-Mann-Whitney

wilcox.test(
  converted_comp ~ age_first_code_cut,
  data = stack_overflow,
  alternative = "greater",
  correct = FALSE
) 
    Wilcoxon rank sum test

data:  converted_comp by age_first_code_cut
W = 967298, p-value <2e-16
alternative hypothesis: true location shift is greater than 0
1 Aussi appelé « Wilcoxon rank-sum test » et « Mann-Whitney U test ».
Tests d'hypothèse en R

Test de Kruskal-Wallis

Le test de Kruskal-Wallis est au test de Wilcoxon-Mann-Whitney ce que l'ANOVA est au test t.

kruskal.test(
  converted_comp ~ job_sat,
  data = stack_overflow
)
    Kruskal-Wallis rank sum test

data:  converted_comp by job_sat
Kruskal-Wallis chi-square = 81, df = 4, p-value <2e-16
Tests d'hypothèse en R

Passons à la pratique !

Tests d'hypothèse en R

Preparing Video For Download...