pingouin.rm_anova

pingouin.
rm_anova
(data=None, dv=None, within=None, subject=None, correction='auto', detailed=False, effsize='np2')[source] Oneway and twoway repeated measures ANOVA.
 Parameters
 data
pandas.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 longformat dataframe are supported for oneway repeated measures ANOVA. However,data
must be in long format for twoway 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). Ifwithin
is a single string, then compute a oneway repeated measures ANOVA, ifwithin
is a list with two strings, compute a twoway 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 GreenhouseGeisser corrected pvalue.
The default for oneway design is to compute Mauchly’s test of sphericity to determine whether the pvalues needs to be corrected (see
pingouin.sphericity()
).The default for twoway design is to return both the uncorrected and GreenhouseGeisser corrected pvalues. Note that sphericity test for twoway design are not currently implemented in Pingouin.
 detailedboolean
If True, return a full ANOVA table.
 effsizestr
Effect size. Must be one of ‘np2’ (partial etasquared), ‘n2’ (etasquared) or ‘ng2’(generalized etasquared). Note that for oneway repeated measure ANOVA partial etasquared is the same as etasquared.
 data
 Returns
 aov
pandas.DataFrame
ANOVA summary:
'Source'
: Name of the withingroup factor'ddof1'
: Degrees of freedom (numerator)'ddof2'
: Degrees of freedom (denominator)'F'
: Fvalue'punc'
: Uncorrected pvalue'np2'
: Partial etasquare effect size'eps'
: GreenhouseGeisser epsilon factor (= index of sphericity)'pGGcorr'
: GreenhouseGeisser corrected pvalue'Wspher'
: Sphericity test statistic'pspher'
: pvalue of the sphericity test'sphericity'
: sphericity of the data (boolean)
 aov
See also
anova
Oneway and Nway ANOVA
mixed_anova
Two way mixed ANOVA
friedman
Nonparametric oneway repeated measures ANOVA
Notes
Data can be in wide or long format for oneway repeated measures ANOVA but must be in long format for twoway repeated measures ANOVA.
In oneway repeatedmeasures 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 Fstatistics is then defined as:
\[F^* = \frac{MS_{\text{effect}}}{MS_{\text{error}}} = \frac{\frac{SS_{\text{effect}}} {r1}}{\frac{SS_{\text{error}}}{(n  1)(r  1)}}\]and the pvalue can be calculated using a Fdistribution 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 etasquared, which is equivalent to etasquare for oneway 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 twoway repeated measures ANOVA where both factors have more than two levels slightly differs than from R and JASP. Please always make sure to doublecheck your results with another software.
Warning
Sphericity tests for the interaction term of a twoway repeated measures ANOVA are not currently supported in Pingouin. Instead, please refer to the GreenhouseGeisser epsilon value (a value close to 1 indicates that sphericity is met.) For more details, see
pingouin.sphericity()
.Examples
Oneway repeated measures ANOVA using a wideformat dataset
>>> import pingouin as pg >>> data = pg.read_dataset('rm_anova_wide') >>> pg.rm_anova(data) Source ddof1 ddof2 F punc np2 eps 0 Within 3 24 5.200652 0.006557 0.393969 0.694329
Oneway repeatedmeasures ANOVA using a longformat dataset.
We’re also specifying two additional options here:
detailed=True
means that we’ll get a more detailed ANOVA table, andeffsize='ng2'
means that we want to get the generalized etasquared effect size instead of the default partial etasquared.>>> 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 punc 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
Twoway repeatedmeasures ANOVA
>>> aov = pg.rm_anova(dv='DesireToKill', ... within=['Disgustingness', 'Frighteningness'], ... subject='Subject', data=df)
As a
pandas.DataFrame
method
>>> df.rm_anova(dv='DesireToKill', within='Disgustingness', ... subject='Subject', detailed=False) Source ddof1 ddof2 F punc np2 eps 0 Disgustingness 1 92 12.043878 0.000793 0.115758 1.0