नॉन-पैरामीट्रिक टेस्ट्स

Python में Hypothesis Testing

James Chapman

Curriculum Manager, DataCamp

पैरामीट्रिक टेस्ट्स

  • z-test, t-test, और ANOVA सभी पैरामीट्रिक टेस्ट्स हैं
  • नॉर्मल डिस्ट्रीब्यूशन मानते हैं
  • पर्याप्त बड़ा सैंपल साइज चाहिए
Python में Hypothesis Testing

छोटा रिपब्लिकन वोट्स डेटा

print(repub_votes_small)
            state      county  repub_percent_08  repub_percent_12
80          Texas   Red River         68.507522         69.944817
84          Texas      Walker         60.707197         64.971903
33       Kentucky      Powell         57.059533         61.727293
81          Texas  Schleicher         74.386503         77.384464
93  West Virginia      Morgan         60.857614         64.068711
Python में Hypothesis Testing

pingouin.ttest() के नतीजे

  • 5 पेयर्स पेयर्ड t-test के सैंपल साइज कंडीशन के लिए काफी नहीं हैं:
  • सैंपल्स में कम-से-कम 30 पेयर्स के ऑब्ज़र्वेशन।
alpha = 0.01

import pingouin pingouin.ttest(x=repub_votes_potus_08_12_small['repub_percent_08'], y=repub_votes_potus_08_12_small['repub_percent_12'], paired=True, alternative="less")
               T  dof alternative     p-val          CI95%   cohen-d    BF10     power
T-test -5.875753    4        less  0.002096  [-inf, -2.11]  0.500068  26.468  0.239034
Python में Hypothesis Testing

नॉन-पैरामीट्रिक टेस्ट्स

  • नॉन-पैरामीट्रिक टेस्ट्स पैरामीट्रिक मान्यताओं और कंडीशंस से बचते हैं
  • कई नॉन-पैरामीट्रिक टेस्ट्स डेटा के ranks का उपयोग करते हैं
x = [1, 15, 3, 10, 6]
from scipy.stats import rankdata
rankdata(x)
array([1., 5., 2., 4., 3.])
Python में Hypothesis Testing

नॉन-पैरामीट्रिक टेस्ट्स

  • छोटे सैंपल साइज और जब डेटा नॉर्मली डिस्ट्रीब्यूटेड नहीं हो, तब नॉन-पैरामीट्रिक टेस्ट्स पैरामीट्रिक टेस्ट्स से अधिक भरोसेमंद होते हैं
Python में Hypothesis Testing

नॉन-पैरामीट्रिक टेस्ट्स

  • छोटे सैंपल साइज और जब डेटा नॉर्मली डिस्ट्रीब्यूटेड नहीं हो, तब नॉन-पैरामीट्रिक टेस्ट्स पैरामीट्रिक टेस्ट्स से अधिक भरोसेमंद होते हैं

 

Wilcoxon-signed rank test
  • 1945 में Frank Wilcoxon द्वारा विकसित
  • शुरुआती नॉन-पैरामीट्रिक प्रक्रियाओं में से एक
Python में Hypothesis Testing

Wilcoxon-signed rank test (कदम 1)

  • डेटा के पेयर्ड मानों के बीच के एब्सोल्यूट डिफरेंसेज़ के रैंक्स पर काम करता है
repub_votes_small['diff'] = repub_votes_small['repub_percent_08'] -
                            repub_votes_small['repub_percent_12']
print(repub_votes_small)
            state      county  repub_percent_08  repub_percent_12      diff
80          Texas   Red River         68.507522         69.944817 -1.437295
84          Texas      Walker         60.707197         64.971903 -4.264705
33       Kentucky      Powell         57.059533         61.727293 -4.667760
81          Texas  Schleicher         74.386503         77.384464 -2.997961
93  West Virginia      Morgan         60.857614         64.068711 -3.211097
Python में Hypothesis Testing

Wilcoxon-signed rank test (कदम 2)

  • डेटा के पेयर्ड मानों के बीच के एब्सोल्यूट डिफरेंसेज़ के रैंक्स पर काम करता है
repub_votes_small['abs_diff'] = repub_votes_small['diff'].abs()
print(repub_votes_small)
            state      county  repub_percent_08  repub_percent_12      diff  abs_diff
80          Texas   Red River         68.507522         69.944817 -1.437295  1.437295
84          Texas      Walker         60.707197         64.971903 -4.264705  4.264705
33       Kentucky      Powell         57.059533         61.727293 -4.667760  4.667760
81          Texas  Schleicher         74.386503         77.384464 -2.997961  2.997961
93  West Virginia      Morgan         60.857614         64.068711 -3.211097  3.211097
Python में Hypothesis Testing

Wilcoxon-signed rank test (कदम 3)

  • डेटा के पेयर्ड मानों के बीच के एब्सोल्यूट डिफरेंसेज़ के रैंक्स पर काम करता है
from scipy.stats import rankdata
repub_votes_small['rank_abs_diff'] = rankdata(repub_votes_small['abs_diff'])
print(repub_votes_small)
            state      county  repub_percent_08  repub_percent_12      diff  abs_diff  rank_abs_diff
80          Texas   Red River         68.507522         69.944817 -1.437295  1.437295            1.0
84          Texas      Walker         60.707197         64.971903 -4.264705  4.264705            4.0
33       Kentucky      Powell         57.059533         61.727293 -4.667760  4.667760            5.0
81          Texas  Schleicher         74.386503         77.384464 -2.997961  2.997961            2.0
93  West Virginia      Morgan         60.857614         64.068711 -3.211097  3.211097            3.0
Python में Hypothesis Testing

Wilcoxon-signed rank test (कदम 4)

            state      county  repub_percent_08  repub_percent_12      diff  abs_diff  rank_abs_diff
80          Texas   Red River         68.507522         69.944817 -1.437295  1.437295            1.0
84          Texas      Walker         60.707197         64.971903 -4.264705  4.264705            4.0
33       Kentucky      Powell         57.059533         61.727293 -4.667760  4.667760            5.0
81          Texas  Schleicher         74.386503         77.384464 -2.997961  2.997961            2.0
93  West Virginia      Morgan         60.857614         64.068711 -3.211097  3.211097            3.0
  • नेगेटिव और पॉज़िटिव डिफरेंसेज़ के रैंक्स के सम का उपयोग करें
T_minus = 1 + 4 + 5 + 2 + 3

T_plus = 0
W = np.min([T_minus, T_plus])
0
Python में Hypothesis Testing

pingouin.wilcoxon() के साथ इम्प्लिमेंटेशन

alpha = 0.01
pingouin.wilcoxon(x=repub_votes_potus_08_12_small['repub_percent_08'],
                  y=repub_votes_potus_08_12_small['repub_percent_12'],
                  alternative="less")
          W-val alternative    p-val  RBC  CLES
Wilcoxon    0.0        less  0.03125 -1.0  0.72

$H_0$ को खारिज नहीं करते, क्योंकि 0.03125 > 0.01

Python में Hypothesis Testing

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

Python में Hypothesis Testing

Preparing Video For Download...