"There is only one test" फ्रेमवर्क

R में Hypothesis Testing

Richie Cotton

Data Evangelist at DataCamp

Imbalanced डेटा

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

अगर कुछ समूह दूसरों से बहुत बड़े हों, तो सैंपल imbalanced कहलाता है.

R में Hypothesis Testing

Hypotheses

$H_{0}$: 30 से कम उम्र के hobbyists का proportion, कम से कम 30 के hobbyists के proportion के "बराबर" है.

$H_{A}$: 30 से कम उम्र के hobbyists का proportion, कम से कम 30 के hobbyists के proportion से "अलग" है.

alpha <- 0.1

R में Hypothesis Testing

स्थिति चाहे जो हो, proportion test से आगे बढ़ना

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 में Hypothesis Testing

A grammar of graphics

Plot type base-R ggplot2
Scatter plot plot(, type = "p") ggplot() + geom_point()
Line plot plot(, type = "l") ggplot() + geom_line()
Histogram hist() ggplot() + geom_histogram()
Box plot boxplot() ggplot() + geom_boxplot()
Bar plot barplot() ggplot() + geom_bar()
Pie plot pie() ggplot() + geom_bar() + coord_polar()
R में Hypothesis Testing

A grammar of hypothesis tests

  • Allen Downey का There is only one test फ्रेमवर्क.
  • R में infer पैकेज से implemented.
  • generate() simulated डेटा बनाता है.
    • computation महँगा.
    • छोटे सैंपल या imbalanced डेटा पर robust.
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" पढ़ाते हैं.
R में Hypothesis Testing

रुचि वाले वैरिएबल specify करना

बाएँ ओर एक आयताकार सेल-ग्रिड है जो data frame दर्शाता है. दो कॉलम हाइलाइट हैं. इस ग्रिड के दाएँ "specify" लिखा है, दाएँ तीर के साथ. तीर के दाएँ एक और ग्रिड है जिसमें केवल वही दो हाइलाइट कॉलम हैं.

R में Hypothesis Testing

specify()

specify() वे वैरिएबल चुनता है जिन्हें आप टेस्ट करना चाहते हैं.

  • 2-sample tests के लिए response ~ explanatory.
  • 1-sample tests के लिए response ~ NULL.
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 में Hypothesis Testing

hypothesize()

hypothesize() null hypothesis का प्रकार बताता है.

  • 2-sample tests के लिए "independence" या "point".
  • 1-sample tests के लिए "point".
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 में Hypothesis Testing

अभ्यास करते हैं!

R में Hypothesis Testing

Preparing Video For Download...