pingouin.rm_anova#

pingouin.rm_anova(data=None, dv=None, within=None, subject=None, correction='auto', detailed=False, effsize='ng2')[source]#

One-way and two-way repeated measures ANOVA.

Parameters:
datapandas.DataFrame

DataFrame. Note that this function can also directly be used as a pandas.DataFrame method, in which case this argument is no longer needed. Both wide and long-format dataframe are supported for one-way repeated measures ANOVA. However, data must be in long format for two-way repeated measures.

dvstring

Name of column containing the dependent variable (only required if data is in long format).

withinstring or list of string

Name of column containing the within factor (only required if data is in long format). If within is a single string, then compute a one-way repeated measures ANOVA, if within is a list with two strings, compute a two-way repeated measures ANOVA.

subjectstring

Name of column containing the subject identifier (only required if data is in long format).

correctionstring or boolean

If True, also return the Greenhouse-Geisser corrected p-value.

The default for one-way design is to compute Mauchly’s test of sphericity to determine whether the p-values needs to be corrected (see pingouin.sphericity()).

The default for two-way design is to return both the uncorrected and Greenhouse-Geisser corrected p-values. Note that sphericity test for two-way design are not currently implemented in Pingouin.

detailedboolean

If True, return a full ANOVA table.

effsizestring

Effect size. Must be one of ‘np2’ (partial eta-squared), ‘n2’ (eta-squared) or ‘ng2’(generalized eta-squared, default). Note that for one-way repeated measure ANOVA, eta-squared is the same as the generalized eta-squared.

Returns:
aovpandas.DataFrame

ANOVA summary:

  • 'Source': Name of the within-group factor

  • 'ddof1': Degrees of freedom (numerator)

  • 'ddof2': Degrees of freedom (denominator)

  • 'F': F-value

  • 'p-unc': Uncorrected p-value

  • 'ng2': Generalized eta-square effect size

  • 'eps': Greenhouse-Geisser epsilon factor (= index of sphericity)

  • 'p-GG-corr': Greenhouse-Geisser corrected p-value

  • 'W-spher': Sphericity test statistic

  • 'p-spher': p-value of the sphericity test

  • 'sphericity': sphericity of the data (boolean)

See also

anova

One-way and N-way ANOVA

mixed_anova

Two way mixed ANOVA

friedman

Non-parametric one-way repeated measures ANOVA

Notes

Data can be in wide or long format for one-way repeated measures ANOVA but must be in long format for two-way repeated measures ANOVA.

In one-way repeated-measures ANOVA, the total variance (sums of squares) is divided into three components

\[SS_{\text{total}} = SS_{\text{effect}} + (SS_{\text{subjects}} + SS_{\text{error}})\]

with

\[ \begin{align}\begin{aligned}SS_{\text{total}} = \sum_i^r \sum_j^n (Y_{ij} - \overline{Y})^2\\SS_{\text{effect}} = \sum_i^r n_i(\overline{Y_i} - \overline{Y})^2\\SS_{\text{subjects}} = r\sum (\overline{Y}_s - \overline{Y})^2\\SS_{\text{error}} = SS_{\text{total}} - SS_{\text{effect}} - SS_{\text{subjects}}\end{aligned}\end{align} \]

where \(i=1,...,r; j=1,...,n_i\), \(r\) is the number of conditions, \(n_i\) the number of observations for each condition, \(\overline{Y}\) the grand mean of the data, \(\overline{Y_i}\) the mean of the \(i^{th}\) condition and \(\overline{Y}_{subj}\) the mean of the \(s^{th}\) subject.

The F-statistics is then defined as:

\[F^* = \frac{MS_{\text{effect}}}{MS_{\text{error}}} = \frac{\frac{SS_{\text{effect}}} {r-1}}{\frac{SS_{\text{error}}}{(n - 1)(r - 1)}}\]

and the p-value can be calculated using a F-distribution with \(v_{\text{effect}} = r - 1\) and \(v_{\text{error}} = (n - 1)(r - 1)\) degrees of freedom.

The default effect size reported in Pingouin is the generalized eta-squared, which is equivalent to eta-squared for one-way repeated measures ANOVA.

\[\eta_g^2 = \frac{SS_{\text{effect}}}{SS_{\text{total}}}\]

The partial eta-squared is defined as:

\[\eta_p^2 = \frac{SS_{\text{effect}}}{SS_{\text{effect}} + SS_{\text{error}}}\]

Missing values are automatically removed using a strict listwise approach (= complete-case analysis). In other words, any subject with one or more missing value(s) is completely removed from the dataframe prior to running the test. This could drastically decrease the power of the ANOVA if many missing values are present. In that case, we strongly recommend using linear mixed effect modelling, which can handle missing values in repeated measures.

Warning

The epsilon adjustement factor of the interaction in two-way repeated measures ANOVA where both factors have more than two levels slightly differs than from R and JASP. Please always make sure to double-check your results with another software.

Warning

Sphericity tests for the interaction term of a two-way repeated measures ANOVA are not currently supported in Pingouin. Instead, please refer to the Greenhouse-Geisser epsilon value (a value close to 1 indicates that sphericity is met.) For more details, see pingouin.sphericity().

Examples

  1. One-way repeated measures ANOVA using a wide-format dataset

>>> import pingouin as pg
>>> data = pg.read_dataset('rm_anova_wide')
>>> pg.rm_anova(data)
   Source  ddof1  ddof2         F     p-unc       ng2       eps
0  Within      3     24  5.200652  0.006557  0.346392  0.694329
  1. One-way repeated-measures ANOVA using a long-format dataset.

We’re also specifying two additional options here: detailed=True means that we’ll get a more detailed ANOVA table, and effsize='np2' means that we want to get the partial eta-squared effect size instead of the default (generalized) eta-squared.

>>> df = pg.read_dataset('rm_anova')
>>> aov = pg.rm_anova(dv='DesireToKill', within='Disgustingness',
...                   subject='Subject', data=df, detailed=True, effsize="np2")
>>> aov.round(3)
           Source       SS  DF      MS       F  p-unc    np2  eps
0  Disgustingness   27.485   1  27.485  12.044  0.001  0.116  1.0
1           Error  209.952  92   2.282     NaN    NaN    NaN  NaN
  1. Two-way repeated-measures ANOVA

>>> aov = pg.rm_anova(dv='DesireToKill', within=['Disgustingness', 'Frighteningness'],
...                   subject='Subject', data=df)
  1. As a pandas.DataFrame method

>>> df.rm_anova(dv='DesireToKill', within='Disgustingness', subject='Subject',  detailed=False)
           Source  ddof1  ddof2          F     p-unc       ng2  eps
0  Disgustingness      1     92  12.043878  0.000793  0.025784  1.0