numere-org / NumeRe

Framework for numerical computations, data analysis and visualisation
https://www.numere.org
GNU General Public License v3.0
20 stars 7 forks source link

Add two-way ANOVA #171

Closed mstranne closed 9 months ago

mstranne commented 10 months ago

SUMMARY

Implements necessary changes for #10

Reviewers: @numere-org/maintainers

IMPLEMENTATION

Implementation of two-way anova. The call tree for table.anovaof() was changed to support an array of columns for Categories/Labels/Factors, however you call it. A new recursive appraoch is implemented to calculate multi-way anovas. The Tree structure is implemented via the new structures AnovaCalculationStructure and FactorNode in memory.hpp.

one test was added to the table SW-Test repo. The results compaired where retrefed from following python code:

import numpy as np
import pandas as pd
import statsmodels.api as sm
from statsmodels.formula.api import ols

all = [4.8, 5, 6.4, 6.3,
      4.4, 5.2, 6.2, 6.4,
      3.2, 5.6, 4.7, 5.6,
      3.9, 4.3, 5.5, 4.8,
      4.4, 4.8, 5.8, 5.8,
      4.4, 4.9, 5.8, 6,
      4.2, 5.3, 6.2, 4.9,
      3.8, 5.7, 6.3, 4.6,
      3.7, 5.4, 6.5, 5.6,
      3.9, 4.8, 5.5, 5.5]

#perform two-way ANOVA
model = ols('height ~ C(water) + C(sun) + C(water):C(sun)', data=df).fit()
ret = sm.stats.anova_lm(model, typ=2)
print(ret)

DOCUMENTATION


TESTS BY REVIEWERS

numeredev commented 9 months ago

@mstranne Ready for merge