“Yalnızca tek bir test var” çerçevesi

R ile Hipotez Testi

Richie Cotton

Data Evangelist at DataCamp

Dengesiz veriler

stack_overflow_imbalanced %>% 
  count(hobbyist, age_cat, .drop = FALSE)
  hobbyist     age_cat    n
1       No At least 30    0
2       No    Under 30  191
3      Yes At least 30   15
4      Yes    Under 30 1025

Bazı gruplar diğerlerinden çok daha büyükse örneklem dengesizdir.

R ile Hipotez Testi

Hipotezler

$H_{0}$: 30 yaş altı hobicilerin oranı, en az 30 yaş hobicilerin oranıyla aynıdır.

$H_{A}$: 30 yaş altı hobicilerin oranı, en az 30 yaş hobicilerin oranından farklıdır.

alpha <- 0.1

R ile Hipotez Testi

Yine de oran testi ile ilerleme

stack_overflow_imbalanced %>% 
  prop_test(
    hobbyist ~ age_cat,
    order = c("At least 30", "Under 30"),
    success = "Yes",
    alternative = "two.sided",
    correct = FALSE
  )
# A tibble: 1 x 6
  statistic chisq_df p_value alternative lower_ci upper_ci
      <dbl>    <dbl>   <dbl> <chr>          <dbl>    <dbl>
1      2.79        1  0.0949 two.sided    0.00718   0.0217
R ile Hipotez Testi

Grafikler dilbilgisi

Grafik türü base-R ggplot2
Saçılım grafiği plot(, type = "p") ggplot() + geom_point()
Çizgi grafiği plot(, type = "l") ggplot() + geom_line()
Histogram hist() ggplot() + geom_histogram()
Kutu grafiği boxplot() ggplot() + geom_boxplot()
Çubuk grafiği barplot() ggplot() + geom_bar()
Pasta grafiği pie() ggplot() + geom_bar() + coord_polar()
R ile Hipotez Testi

Hipotez testleri dilbilgisi

  • Allen Downey'nin There is only one test çerçevesi.
  • R'de infer paketinde uygulanmıştır.
  • generate() benzetim verisi üretir.
    • Hesaplaması maliyetlidir.
    • Küçük örneklemlere veya dengesiz verilere karşı dayanıklıdır.
null_distn <- dataset %>% 
  specify() %>% 
  hypothesize() %>% 
  generate() %>% 
  calculate()
obs_stat <- dataset %>% 
  specify() %>% 
  calculate()
get_p_value(null_distn, obs_stat)
1 Allen Downey “Exploratory Data Analysis in Python” dersini veriyor.
R ile Hipotez Testi

İlgili değişkenleri belirtme

Sol tarafta bir veri çerçevesini temsil eden dikdörtgen hücre ızgarası var. İki sütun vurgulanmış. Bu ızgaranın sağında sağa okla gösterilen 'specify' kelimesi var. Okun sağında yalnızca iki vurgulu sütunu olan başka bir dikdörtgen ızgara bulunuyor.

R ile Hipotez Testi

specify()

specify() test etmek istediğiniz değişken(ler)i seçer.

  • 2 örneklemli testler için response ~ explanatory kullanın.
  • 1 örneklemli testler için response ~ NULL kullanın.
stack_overflow_imbalanced %>%
  specify(hobbyist ~ age_cat, success = "Yes")
Response: hobbyist (factor)
Explanatory: age_cat (factor)
# A tibble: 1,231 x 2
  hobbyist age_cat    
  <fct>    <fct>      
1 Yes      At least 30
2 Yes      At least 30
3 Yes      At least 30
4 Yes      Under 30   
5 Yes      At least 30
6 Yes      At least 30
7 No       Under 30   
# ... with 1,224 more rows
R ile Hipotez Testi

hypothesize()

hypothesize() sıfır hipotezi türünü belirtir.

  • 2 örneklemli testler için "independence" veya "point" kullanın.
  • 1 örneklemli testler için "point" kullanın.
stack_overflow_imbalanced %>%
  specify(hobbyist ~ age_cat, success = "Yes") %>%
  hypothesize(null = "independence")
Response: hobbyist (factor)
Explanatory: age_cat (factor)
Null Hypothesis: independence
# A tibble: 1,231 x 2
  hobbyist age_cat    
  <fct>    <fct>      
1 Yes      At least 30
2 Yes      At least 30
3 Yes      At least 30
4 Yes      Under 30   
5 Yes      At least 30
6 Yes      At least 30
7 No       Under 30   
# ... with 1,224 more rows
R ile Hipotez Testi

Hadi pratik yapalım!

R ile Hipotez Testi

Preparing Video For Download...