ANOVA neparametrică și teste t nepereche

Testarea ipotezelor în R

Richie Cotton

Data Evangelist at DataCamp

Teste neparametrice

Un test neparametric este un test de ipoteză care nu presupune o distribuție de probabilitate pentru statistica de test.

Există două tipuri de teste neparametrice:

  1. Bazate pe simulare.
  2. Bazate pe ranguri.
Testarea ipotezelor în 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
Testarea ipotezelor în R

Calcularea distribuției nule

Pipeline bazat pe simulare
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") )
Testul t, pentru comparație
library(infer)
stack_overflow %>% 
  t_test(
    converted_comp ~ age_first_code_cut,
    order = c("child", "adult"),
    alternative = "greater"
  )
Testarea ipotezelor în R

Calcularea statisticii observate

Pipeline bazat pe simulare
obs_stat <- stack_overflow %>% 
  specify(converted_comp ~ age_first_code_cut) %>% 
  calculate(
    stat = "diff in means", 
    order = c("child", "adult")
  )
Testul t, pentru comparație
library(infer)
stack_overflow %>% 
  t_test(
    converted_comp ~ age_first_code_cut,
    order = c("child", "adult"),
    alternative = "greater"
  )
Testarea ipotezelor în R

Obținerea valorii p

Pipeline bazat pe simulare
get_p_value(
  null_distn, obs_stat, 
  direction = "greater"
)
# A tibble: 1 x 1
  p_value
    <dbl>
1  0.0066
Testul t, pentru comparație
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
Testarea ipotezelor în R

Rangurile vectorilor

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

Testul Wilcoxon-Mann-Whitney (cunoscut și ca testul sumei rangurilor Wilcoxon) este (aproximativ) un test t aplicat rangurilor valorilor numerice.

Testarea ipotezelor în R

Testul 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 Cunoscut și ca „testul sumei rangurilor Wilcoxon" și „testul U Mann-Whitney".
Testarea ipotezelor în R

Testul Kruskal-Wallis

Testul Kruskal-Wallis este față de testul Wilcoxon-Mann-Whitney cum este ANOVA față de testul 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
Testarea ipotezelor în R

Să exersăm!

Testarea ipotezelor în R

Preparing Video For Download...