# pingouin.rm_anova

pingouin.rm_anova(data=None, dv=None, within=None, subject=None, correction='auto', detailed=False, effsize='np2')[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

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.

effsizestr

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

• 'np2': Partial 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)

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 partial eta-squared, which is equivalent to eta-square for one-way repeated measures ANOVA.

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

Results have been tested against R and JASP. Note however that if the dataset contains one or more other within subject factors, an automatic collapsing to the mean is applied on the dependent variable (same behavior as the ezANOVA R package). As such, results can differ from those of JASP.

Missing values are automatically removed (listwise deletion on the last factor) using the pingouin.remove_rm_na() function. This could drastically decrease the power of the ANOVA if many missing values are present, especially when working with two factors. In that case, we strongly recommend using either JASP to conduct the repeated measures ANOVA (which takes into account the missing values), or using more advanced statistical methods such as linear mixed effect models.

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
>>> pg.rm_anova(data)
Source  ddof1  ddof2         F     p-unc       np2       eps
0  Within      3     24  5.200652  0.006557  0.393969  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='ng2' means that we want to get the generalized eta-squared effect size instead of the default partial eta-squared.

>>> df = pg.read_dataset('rm_anova')
>>> aov = pg.rm_anova(dv='DesireToKill', within='Disgustingness',
...                   subject='Subject', data=df, detailed=True,
...                   effsize="ng2")
>>> aov.round(3)
Source       SS  DF      MS       F  p-unc    ng2  eps
0  Disgustingness   27.485   1  27.485  12.044  0.001  0.026  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       np2  eps
0  Disgustingness      1     92  12.043878  0.000793  0.115758  1.0