t-टेस्ट करना

R में Hypothesis Testing

Richie Cotton

Data Evangelist at DataCamp

Two-sample समस्याएँ

  • एक और समस्या है: किसी वैरिएबल के समूहों में sample statistics की तुलना करना.
  • converted_comp एक संख्यात्मक वैरिएबल है.
  • age_first_code_cut एक श्रेणीबद्ध वैरिएबल है, जिसके स्तर ("child" और "adult") हैं.
  • क्या जिन यूज़र ने बचपन में पहली बार कोड किया, उन्हें वयस्क होकर शुरू करने वालों से ज़्यादा compensation मिलता है?
R में Hypothesis Testing

परिकल्पनाएँ

$H_{0}$: जिन लोगों ने बचपन में पहली बार कोड किया और जिन लोगों ने वयस्क होने पर किया, उनके लिए औसत compensation (USD में) समान है.

$H_{0}$: $\mu_{child} = \mu_{adult}$

$H_{0}$: $\mu_{child} - \mu_{adult} = 0$

$H_{A}$: जिन लोगों ने बचपन में पहली बार कोड किया, उनका औसत compensation (USD में) वयस्क होकर शुरू करने वालों से ज़्यादा है.

$H_{A}$: $\mu_{child} > \mu_{adult}$

$H_{A}$: $\mu_{child} - \mu_{adult} > 0$

R में Hypothesis Testing

ग्रुप-वार summary statistics निकालना

stack_overflow %>% 
  group_by(age_first_code_cut) %>% 
  summarize(mean_compensation = mean(converted_comp))
# A tibble: 2 x 2
  age_first_code_cut mean_compensation
  <chr>                          <dbl>
1 adult                        111544.
2 child                        138275.
R में Hypothesis Testing

Test statistics

  • Sample mean, population mean का अनुमान लगाता है.
  • $\bar{x}$ sample mean को दर्शाता है.
  • $\bar{x}_{child}$ वह original sample mean compensation है, जब पहले बार कोडिंग बचपन में हुई.
  • $\bar{x}_{adult}$ वह original sample mean compensation है, जब पहले बार कोडिंग वयस्क होने पर हुई.
  • $\bar{x}_{child} - \bar{x}_{adult}$ एक test statistic है.
  • z-scores (standardized) test statistic का एक प्रकार हैं.
R में Hypothesis Testing

Test statistic को standardize करना

$z = \dfrac{\text{sample stat} - \text{population parameter}}{\text{standard error}}$

$t = \dfrac{\text{difference in sample stats} - \text{difference in population parameters}}{\text{standard error}}$

$t = \dfrac{(\bar{x}_{\text{child}} - \bar{x}_{\text{adult}}) - (\mu_{\text{child}} - \mu_{\text{adult}})}{SE(\bar{x}_{\text{child}} - \bar{x}_{\text{adult}})}$

R में Hypothesis Testing

Standard error

$SE(\bar{x}_{\text{child}} - \bar{x}_{\text{adult}}) \approx \sqrt{\dfrac{s_{\text{child}}^2}{n_{\text{child}}} + \dfrac{s_{\text{adult}}^2}{n_{\text{adult}}}}$

$s$ वैरिएबल का standard deviation है.

$n$ sample size है (sample में observations/rows की संख्या).

R में Hypothesis Testing

शून्य परिकल्पना सही मानकर

$t = \dfrac{(\bar{x}_{\text{child}} - \bar{x}_{\text{adult}}) - (\mu_{\text{child}} - \mu_{\text{adult}})}{SE(\bar{x}_{\text{child}} - \bar{x}_{\text{adult}})}$

$H_{0}$: $\mu_{\text{child}} - \mu_{\text{adult}} = 0$

$t = \dfrac{(\bar{x}_{\text{child}} - \bar{x}_{\text{adult}}) }{SE(\bar{x}_{\text{child}} - \bar{x}_{\text{adult}})}$

$t = \dfrac{(\bar{x}_{\text{child}} - \bar{x}_{\text{adult}})}{\sqrt{\dfrac{s_{\text{child}}^2}{n_{\text{child}}} + \dfrac{s_{\text{adult}}^2}{n_{\text{adult}}}}}$

stack_overflow %>%
  group_by(age_first_code_cut) %>%
  summarize(
    xbar = mean(converted_comp),
    s = sd(converted_comp),
    n = n()
  )
# A tibble: 2 x 4
  age_first_code_cut    xbar       s     n
  <chr>                <dbl>   <dbl> <int>
1 adult              111544. 270381.  1579
2 child              138275. 278130.  1001
R में Hypothesis Testing

Test statistic की गणना

# A tibble: 2 x 4
  age_first_code_cut    xbar       s     n
  <chr>                <dbl>   <dbl> <int>
1 adult              111544. 270381.  1579
2 child              138275. 278130.  1001

$t = \dfrac{(\bar{x}_{\text{child}} - \bar{x}_{\text{adult}})}{\sqrt{\dfrac{s_{\text{child}}^2}{n_{\text{child}}} + \dfrac{s_{\text{adult}}^2}{n_{\text{adult}}}}}$

numerator <- xbar_child - xbar_adult
denominator <- sqrt(
  s_child ^ 2 / n_child + s_adult ^ 2 / n_adult
)
t_stat <- numerator / denominator
2.4046
R में Hypothesis Testing

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

R में Hypothesis Testing

Preparing Video For Download...