pingouin.pairwise_ttests

pingouin.
pairwise_ttests
(data=None, dv=None, between=None, within=None, subject=None, parametric=True, marginal=True, alpha=0.05, tail='twosided', padjust='none', effsize='hedges', correction='auto', nan_policy='listwise', return_desc=False, interaction=True)[source] Pairwise Ttests.
 Parameters
 datapandas DataFrame
DataFrame. Note that this function can also directly be used as a Pandas method, in which case this argument is no longer needed.
 dvstring
Name of column containing the dependant variable.
 betweenstring or list with 2 elements
Name of column(s) containing the betweensubject factor(s).
Warning
Note that Pingouin gives slightly different T and pvalues compared to JASP posthoc tests for 2way factorial design, because Pingouin does not pool the standard error for each factor, but rather calculate each pairwise Ttest completely independent of others.
 withinstring or list with 2 elements
Name of column(s) containing the withinsubject factor(s), i.e. the repeated measurements.
 subjectstring
Name of column containing the subject identifier. This is compulsory when
within
is specified. parametricboolean
If True (default), use the parametric
ttest()
function. If False, usepingouin.wilcoxon()
orpingouin.mwu()
for paired or unpaired samples, respectively. marginalboolean
If True, average over repeated measures factor when working with mixed or twoway repeated measures design. For instance, in mixed design, the betweensubject pairwise Ttest(s) will be calculated after averaging across all levels of the withinsubject repeated measures factor (the socalled “marginal means”).
Similarly, in twoway repeated measures factor, the pairwise Ttest(s) will be calculated after averaging across all levels of the other repeated measures factor.
Setting
marginal=True
is recommended when doing posthoc testing with multiple factors in order to avoid violating the assumption of independence and conflating the degrees of freedom by the number of repeated measurements. This is the default behavior of JASP.Warning
The default behavior of Pingouin <0.3.2 was
marginal = False
, which may have led to incorrect pvalues for mixed or twoway repeated measures design. Make sure to always use the latest version of Pingouin.New in version 0.3.2.
 alphafloat
Significance level
 tailstring
Specify whether the alternative hypothesis is ‘twosided’ or ‘onesided’. Can also be ‘greater’ or ‘less’ to specify the direction of the test. ‘greater’ tests the alternative that
x
has a larger mean thany
. If tail is ‘onesided’, Pingouin will automatically infer the onesided alternative hypothesis of the test based on the test statistic. padjuststring
Method used for testing and adjustment of pvalues. Available methods are
'none' : no correction 'bonf' : onestep Bonferroni correction 'sidak' : onestep Sidak correction 'holm' : stepdown method using Bonferroni adjustments 'fdr_bh' : Benjamini/Hochberg FDR correction 'fdr_by' : Benjamini/Yekutieli FDR correction
 effsizestring or None
Effect size type. Available methods are
'none' : no effect size 'cohen' : Unbiased Cohen d 'hedges' : Hedges g 'glass': Glass delta 'r' : Pearson correlation coefficient 'etasquare' : Etasquare 'oddsratio' : Odds ratio 'AUC' : Area Under the Curve 'CLES' : Common Language Effect Size
 correctionstring or boolean
For unpaired two sample Ttests, specify whether or not to correct for unequal variances using Welch separate variances Ttest. If ‘auto’, it will automatically uses Welch Ttest when the sample sizes are unequal, as recommended by Zimmerman 2004.
New in version 0.3.2.
 nan_policystring
Can be ‘listwise’ for listwise deletion of missing values in repeated measures design (= completecase analysis) or ‘pairwise’ for the more liberal pairwise deletion (= availablecase analysis).
New in version 0.2.9.
 return_descboolean
If True, append group means and std to the output dataframe
 interactionboolean
If there are multiple factors and
interaction
is True (default), Pingouin will also calculate Ttests for the interaction term (see Notes).New in version 0.2.9.
 Returns
 statsDataFrame
Stats summary
'A' : Name of first measurement 'B' : Name of second measurement 'Paired' : indicates whether the two measurements are paired or not 'Parametric' : indicates if (non)parametric tests were used 'Tail' : indicate whether the pvalues are onesided or twosided 'T' : T statistic (only if parametric=True) 'Uval' : MannWhitney U stat (if parametric=False and unpaired data) 'Wval' : Wilcoxon W stat (if parametric=False and paired data) 'dof' : degrees of freedom (only if parametric=True) 'punc' : Uncorrected pvalues 'pcorr' : Corrected pvalues 'padjust' : pvalues correction method 'BF10' : Bayes Factor 'hedges' : effect size (or any effect size defined in ``effsize``)
See also
Notes
Data are expected to be in longformat. If your data is in wideformat, you can use the
pandas.melt()
function to convert from wide to long format.If
between
orwithin
is a list (e.g. [‘col1’, ‘col2’]), the function returns 1) the pairwise Ttests between each values of the first column, 2) the pairwise Ttests between each values of the second column and 3) the interaction between col1 and col2. The interaction is dependent of the order of the list, so [‘col1’, ‘col2’] will not yield the same results as [‘col2’, ‘col1’], and will only be calculated ifinteraction=True
.In other words, if
between
is a list with two elements, the output model is between1 + between2 + between1 * between2.Similarly, if
within
is a list with two elements, the output model is within1 + within2 + within1 * within2.If both
between
andwithin
are specified, the output model is within + between + within * between (= mixed design).Missing values in repeated measurements are automatically removed using a listwise (default) or pairwise deletion strategy. However, you should be very careful since it can result in undesired values removal (especially for the interaction effect). We strongly recommend that you preprocess your data and remove the missing values before using this function.
This function has been tested against the pairwise.t.test R function.
Warning
Versions of Pingouin below 0.3.2 gave incorrect results for mixed and twoway repeated measures design (see above warning for the
marginal
argument).Warning
Pingouin gives slightly different results than the JASP’s posthoc module when working with multiple factors (e.g. mixed, factorial or 2way repeated measures design). This is mostly caused by the fact that Pingouin does not pool the standard error for betweensubject and interaction contrasts. You should always double check your results with JASP or another statistical software.
Examples
For more examples, please refer to the Jupyter notebooks
One betweensubject factor
>>> from pingouin import pairwise_ttests, read_dataset >>> df = read_dataset('mixed_anova.csv') >>> pairwise_ttests(dv='Scores', between='Group', data=df)
One withinsubject factor
>>> post_hocs = pairwise_ttests(dv='Scores', within='Time', ... subject='Subject', data=df) >>> print(post_hocs)
Nonparametric pairwise paired test (wilcoxon)
>>> pairwise_ttests(dv='Scores', within='Time', subject='Subject', ... data=df, parametric=False)
Mixed design (within and between) with bonferronicorrected pvalues
>>> posthocs = pairwise_ttests(dv='Scores', within='Time', ... subject='Subject', between='Group', ... padjust='bonf', data=df)
Two betweensubject factors. The order of the list matters!
>>> posthocs = pairwise_ttests(dv='Scores', between=['Group', 'Time'], ... data=df)
Same but without the interaction
>>> posthocs = df.pairwise_ttests(dv='Scores', between=['Group', 'Time'], ... interaction=False)