Neparametrická ANOVA a nepárové t-testy

Testování hypotéz v R

Richie Cotton

Data Evangelist at DataCamp

Neparametrické testy

Neparametrický test je hypotézový test, který nepředpokládá žádné pravděpodobnostní rozdělení testové statistiky.

Existují dva typy neparametrických hypotézových testů:

  1. Simulační.
  2. Pořadové.
Testování hypotéz v 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
Testování hypotéz v R

Výpočet nulového rozdělení

Simulační postup
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") )
t-test, pro srovnání
library(infer)
stack_overflow %>% 
  t_test(
    converted_comp ~ age_first_code_cut,
    order = c("child", "adult"),
    alternative = "greater"
  )
Testování hypotéz v R

Výpočet pozorované statistiky

Simulační postup
obs_stat <- stack_overflow %>% 
  specify(converted_comp ~ age_first_code_cut) %>% 
  calculate(
    stat = "diff in means", 
    order = c("child", "adult")
  )
t-test, pro srovnání
library(infer)
stack_overflow %>% 
  t_test(
    converted_comp ~ age_first_code_cut,
    order = c("child", "adult"),
    alternative = "greater"
  )
Testování hypotéz v R

Získání p-hodnoty

Simulační postup
get_p_value(
  null_distn, obs_stat, 
  direction = "greater"
)
# A tibble: 1 x 1
  p_value
    <dbl>
1  0.0066
t-test, pro srovnání
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
Testování hypotéz v R

Pořadí vektorů

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

Test Wilcoxon-Mann-Whitney (jinak Wilcoxonův test součtu pořadí) je (velmi zhruba) t-testem na pořadích numerického vstupu.

Testování hypotéz v R

Test 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 Také znám jako „Wilcoxonův test součtu pořadí" a „Mann-Whitneyův U test".
Testování hypotéz v R

Kruskal-Wallisův test

Kruskal-Wallisův test je k testu Wilcoxon-Mann-Whitney jako ANOVA k t-testu.

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
Testování hypotéz v R

Pojďme si procvičit!

Testování hypotéz v R

Preparing Video For Download...