Advertisement
SeptalNuclei

T-test in Python

Aug 5th, 2018
1,767
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.74 KB | None | 0 0
  1. # This script is accompanying the YouTube Tutorial: https://youtu.be/ZR6bf8_s-hw
  2. import numpy as np
  3. from statsmodels.stats.weightstats import ttest_ind
  4.  
  5. db = np.random.normal(2.3, 0.9, 1000)
  6. da = np.random.normal(1.8, 0.7, 1000)
  7.  
  8. print(ttest_ind(db, da))
  9.  
  10. # Now the same test can of course be carried out using scipy... lets have a QUICK look ath the documentation
  11. from scipy.stats import ttest_ind
  12. ttest_sp = ttest_ind(db, da)
  13.  
  14. print(ttest_sp)
  15.  
  16. # We don't get the degrees of freedom and we don't get the confidence intervall!!! DF can be calulated
  17. n = len(drinks_before) + len(drinks_after)
  18. df = n-2
  19.  
  20. # Paired samples t-test
  21. from scipy.stats import ttest_rel
  22.  
  23. ttest_pair = ttest_rel(drinks_before, drinks_after)
  24.  
  25. print(ttest_pair)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement