biostats.paired_t_test#

biostats.paired_t_test(data, variable, between, group, pair)[source]#

Test whether the mean values of a variable are different in two paired groups.

Parameters:
datapandas.DataFrame

The input data. Must contain at least one numeric column and one categorical column, as well as a column specifying the pairs.

variablestr

The numeric variable that we want to calculate mean values of.

betweenstr

The categorical variable that specifies which group the samples belong to. Maximum 20 groups.

grouplist

List of the two groups to be compared.

pairstr

The variable that specifies the pair ID. Samples in the same pair should have the same ID. Maximum 2000 pairs.

Returns:
summarypandas.DataFrame

The estimations, standard errors, and confidence intervals of the mean values in the two groups, as well as the difference between them.

resultpandas.DataFrame

The degree of freedom, t statistic, and p-value of the test.

See also

two_sample_t_test

Compare the mean values between two independent groups.

wilcoxon_signed_rank_test

The non-parametric version of paired t-test.

Examples

>>> import biostats as bs
>>> data = bs.dataset("paired_t_test.csv")
>>> data
    Length  Feather Bird
0   -0.255  Typical    A
1   -0.213  Typical    B
2   -0.190  Typical    C
3   -0.185  Typical    D
4   -0.045  Typical    E
5   -0.025  Typical    F
6   -0.015  Typical    G
7    0.003  Typical    H
8    0.015  Typical    I
9    0.020  Typical    J
10   0.023  Typical    K
11   0.040  Typical    L
12   0.040  Typical    M
13   0.050  Typical    N
14   0.055  Typical    O
15   0.058  Typical    P
16  -0.324      Odd    A
17  -0.185      Odd    B
18  -0.299      Odd    C
19  -0.144      Odd    D
20  -0.027      Odd    E
21  -0.039      Odd    F
22  -0.264      Odd    G
23  -0.077      Odd    H
24  -0.017      Odd    I
25  -0.169      Odd    J
26  -0.096      Odd    K
27  -0.330      Odd    L
28  -0.346      Odd    M
29  -0.191      Odd    N
30  -0.128      Odd    O
31  -0.182      Odd    P

We want to test whether Length is different between Typical and Odd Feather for every Bird.

>>> summary, result = bs.paired_t_test(data=data, variable="Length", between="Feather", group=["Typical", "Odd"], pair="Bird")
>>> summary
            Estimate  Std. Error  95% CI: Lower  95% CI: Upper
Typical    -0.039000    0.026810      -0.096145       0.018145
Odd        -0.176125    0.027656      -0.235072      -0.117178
Difference  0.137125    0.033736       0.065218       0.209032

The mean values of the two groups and the difference between them are given.

>>> result
       D.F.  t Statistic   p-value    
Model    15     4.064653  0.001017  **

The p-value < 0.01, so there is a significant difference between Length of the two kinds of Feather.