Paired Samples t-Test System

From GM-RKB
Jump to navigation Jump to search

A Paired Samples t-Test System is a parametric statistical hypothesis test system that solves a paired samples t-test task.

# Importing python modules: pandas, scipy statistcal functions and numpy modules and reading data file
In[1]: import pandas
In[2]: from scipy import stats
In[3]: import numpy
In[4]: data = pandas.read_csv('http://www.scipy-lectures.org/_downloads/brain_size.csv', sep=';', na_values=".")
# Perfoming Levene's Test.
In [5]: stats.levene(data['FSIQ'], data['PIQ'])
Out [5]: (2.24213973542, 0.138330970566)
Result: Levene's test statistic is 2.24213973542 and p-value is 0.138330970566. Considering a significance level = 0.05, Levene's test fails to reject the null hypothesis (p-value is greater than significance level). Therefore, we can claim that population variances are homogeneous/equal
# Performing Paired Samples t-test.
In [5]: stats.ttest_rel(data['FSIQ'], data['PIQ'])
Out [5]: (1.78420194059, 0.0821726381836)
Result: Paired samples t-test statistic is 1.78420194059 and p-value is 0.0821726381836. P-value is greater than significance level = 0.05. Paired samples t-test fails to reject the null hypothesis: Mean FSIQ and Mean PIQ are very similar.


References

2017a

Calculates the T-test on TWO RELATED samples of scores, a and b.
This is a two-sided test for the null hypothesis that 2 related or repeated samples have identical average (expected) values.
Parameters: a, b : array_like
The arrays must have the same shape.
axis : int or None, optional
Axis along which to compute test. If None, compute over the whole arrays, a, and b.
nan_policy : {‘propagate’, ‘raise’, ‘omit’}, optional
Defines how to handle when input contains nan. ‘propagate’ returns nan, ‘raise’ throws an error, ‘omit’ performs the calculations ignoring nan values. Default is ‘propagate’.
Returns: statistic : float or array
The calculated t-statistic.
pvalue : float or array
The two-tailed p-value.
Notes
Examples for the use are scores of the same set of student in different exams, or repeated sampling from the same units. The test measures whether the average score differs significantly across samples (e.g. exams). If we observe a large p-value, for example greater than 0.05 or 0.1 then we cannot reject the null hypothesis of identical average scores. If the p-value is smaller than the threshold, e.g. 1%, 5% or 10%, then we reject the null hypothesis of equal averages. Small p-values are associated with large t-statistics.

2017b

  • (Varoquaux, 2017) ⇒ Retrieved on 2017-02-16 from "Statistics in Python" http://www.scipy-lectures.org/packages/statistics/index.html#student-s-t-test-the-simplest-statistical-test
    • QUOTE:PIQ, VIQ, and FSIQ give 3 measures of IQ. Let us test if FISQ and PIQ are significantly different. We can use a 2 sample test (...) The problem with this approach is that it forgets that there are links between observations: FSIQ and PIQ are measured on the same individuals. Thus the variance due to inter-subject variability is confounding, and can be removed, using a “paired test”, or “repeated measures test” (...)=== 2015 ===
  • (Hamelg, 2015) ⇒ Retrieved on 2017-02-26 from "Python for Data Analysis Part 24: Hypothesis Testing and the T-Test", http://hamelg.blogspot.ca/2015/11/python-for-data-analysis-part-24.html
    • The basic two sample t-test is designed for testing differences between independent groups. In some cases, you might be interested in testing differences between samples of the same group at different points in time. For instance, a hospital might want to test whether a weight-loss drug works by checking the weights of the same group patients before and after treatment. A paired t-test lets you check whether the means of samples from the same group differ.
We can conduct a paired t-test using the scipy function stats.ttest_rel(). Let's generate some dummy patient weight data and do a paired t-test (...)