Statistics Tests (Kolmogorov and T-test) with Python and Rpy2

人走茶凉 提交于 2019-12-01 11:15:35

As it says: "SyntaxError: keyword can't be an expression (, line 1)."

In Python, symbols cannot contain the character ".".

from rpy2.robjects.packages import importr
from rpy2.robjects.vectors import StrVector
stats = importr("stats")
stats.t_test(methodresults1, methodresults2,
             **{'var.equal': False,
                'paired': False,
                'alternative': StrVector(("less", ))})

Check the rpy2 documentation about functions for more details.


to perform ks test with python, in case of a two-sample test, you can

>>> from scipy.stats import ks_2samp
>>> import numpy as np
>>> 

where x, y are two nupmy.array:

>>> ks_2samp(x, y)
(0.022999999999999909, 0.95189016804849658)

first value is the test statistics, and second value is the p-value. if the p-value is less than 95 (for a level of significance of 5%), this means that you cannot reject the Null-Hypothese that the two sample distributions are identical.

for one sample ks test, see for example here: http://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.kstest.html#scipy.stats.kstest

this test lets you test the goodness of fit of your empirical distribution to a given probability distribution.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!