Skip to content

Instantly share code, notes, and snippets.

@yudetamago
Created December 9, 2014 18:05
Show Gist options
  • Save yudetamago/637678c7feb05d80a3dd to your computer and use it in GitHub Desktop.
Save yudetamago/637678c7feb05d80a3dd to your computer and use it in GitHub Desktop.
import pandas as pd
import numpy as np
class Anova:
@classmethod
def two_way(self, stack):
"""
(対応のない)二元配置分散分析を行う。
Anova.two_way(pd.DataFrame(
{'A': pd.Series(['a1', 'a1', 'a2', 'a2']),
'B': pd.Series(['b1', 'b1', 'b2', 'b3']),
'Y': pd.Series([ 12, 14, 15, 24])})))
->
Df Sum Sq Mean Sq F value Pr(>F)
A 1 42.25 42.25 21.125 0.136385
B 1 40.50 40.50 20.250 0.139209
Y 1 2.00 2.00 NaN NaN
"""
import pyper
r = pyper.R()
r.assign('stack', stack)
A, B, y = stack.columns
cmd = "res <- summary(aov(" + y + "~" + A + "+" + B + ", stack))"
r(cmd)
summary = r.get('res')[0]
summary.index = stack.columns
return summary
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment