Icke-parametrisk ANOVA och parade t-test

Hypotestestning i R

Richie Cotton

Data Evangelist at DataCamp

Icke-parametriska test

Ett icke-parametriskt test är ett hypotestest som inte antar en sannolikhetsfördelning för teststatistikan.

Det finns två typer av icke-parametriska hypotestest:

  1. Simuleringsbaserade.
  2. Rangbaserade.
Hypotestestning i 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
Hypotestestning i R

Beräkna nollfördelningen

Simuleringsbaserad pipeline
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, för jämförelse
library(infer)
stack_overflow %>% 
  t_test(
    converted_comp ~ age_first_code_cut,
    order = c("child", "adult"),
    alternative = "greater"
  )
Hypotestestning i R

Beräkna den observerade statistikan

Simuleringsbaserad pipeline
obs_stat <- stack_overflow %>% 
  specify(converted_comp ~ age_first_code_cut) %>% 
  calculate(
    stat = "diff in means", 
    order = c("child", "adult")
  )
t-test, för jämförelse
library(infer)
stack_overflow %>% 
  t_test(
    converted_comp ~ age_first_code_cut,
    order = c("child", "adult"),
    alternative = "greater"
  )
Hypotestestning i R

Beräkna p-värdet

Simuleringsbaserad pipeline
get_p_value(
  null_distn, obs_stat, 
  direction = "greater"
)
# A tibble: 1 x 1
  p_value
    <dbl>
1  0.0066
t-test, för jämförelse
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
Hypotestestning i R

Ranger för vektorer

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

Ett Wilcoxon-Mann-Whitney-test (a.k.a. Wilcoxon rank sum test) är (mycket förenklat) ett t-test på rangerna av de numeriska indata.

Hypotestestning i R

Wilcoxon-Mann-Whitney-test

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 Kallas även "Wilcoxon rank-sum test" och "Mann-Whitney U test".
Hypotestestning i R

Kruskal-Wallis-test

Kruskal-Wallis-test förhåller sig till Wilcoxon-Mann-Whitney-test som ANOVA förhåller sig till t-test.

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
Hypotestestning i R

Nu kör vi en övning!

Hypotestestning i R

Preparing Video For Download...