Skip to content Skip to sidebar Skip to footer

Statistics Tests (kolmogorov And T-test) With Python And Rpy2

I've runned some algorithms and wanted to make some statistics analysis with the results. I have two vectors with the averages of the error rate. With R, using the line below I wou

Solution 1:

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.


Solution 2:

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.

Post a Comment for "Statistics Tests (kolmogorov And T-test) With Python And Rpy2"