spiketools.stats.anova.fit_anova

spiketools.stats.anova.fit_anova(df, formula, feature=None, return_type='f_val', anova_type=2)[source]

Fit an ANOVA.

Parameters:
dfpd.DataFrame

Dataframe of data to fit the ANOVA to.

formulastr

The formula.

featurestr, optional

Which feature to extract from the model. Only used (and required) if return_type is ‘f_val’.

return_type{‘f_val’, ‘results’, ‘model’}

What to return after the model fitting. Options:

  • ‘f_val’ : returns the F-value for the requested feature

  • ‘results’ : returns the full set of model results

  • ‘model’ : returns the fit model object

anova_type{2, 3, 1}

Which type of ANOVA test to perform. See statsmodels.stats.anova.anova_lm for details.

Returns:
outputfloat or pd.DataFrame or statsmodels object

If return_type is ‘f_val’, the f-value statistic of the ANOVA model. If return_type is ‘results’, the results of the model fit. If return_type is ‘model’, the fit model object.

Examples

Fit an ANOVA on firing rates per spatial bin, returning model F-value:

>>> data = np.array([[1, 2, 3, 7, 2], [4, 5, 6, 4, 1], [8, 9, 10, 9, 8]])
>>> df = create_dataframe_bins(data)
>>> formula = 'fr ~ C(bin)'
>>> f_val = fit_anova(df, formula, feature='C(bin)', return_type='f_val', anova_type=1)
>>> round(f_val, 4)
0.4249