Search code examples
pythonscipykolmogorov-smirnov

What Arguments to use while doing a KS test in python with student's t distribution?


I have data regarding metallicity in stars, I want to compare it with a student's t distribution. To do this I am running a Kolmogorov-Smirnov test using scipy.stats.kstest on python KSstudentst = scipy.stats.kstest(data,"t",args=(a,b)) But I am unable to find what the arguments are supposed to be. I know the student's t requires a degree of freedom (df) parameter but what is the other parameter. Also which one of the two is the df parameter. In the documentation for scipy.stats.t.cdf the inputs are the position at which value is to be calculated and df, but in the KS test there is no sense in providing the position.


Solution

  • Those seem like the arguments for scipy.stats.t.cdf: (df, loc=0, scale=1) for standard t. Since they have default values, you need to pass a tuple but it can be a singleton (args = (2, ) for df=2)

    import scipy.stats as ss
    import numpy as np
    np.random.seed(0)
    data = np.random.randn(100)
    ss.kstest(data, "t", args = (2, ))
    Out[45]: KstestResult(statistic=0.093219139130061066, pvalue=0.33069879934011182)
    

    Or passing loc=0 and scale=1, the same results:

    ss.kstest(data, "t", args = (2, 0, 1))
    Out[46]: KstestResult(statistic=0.093219139130061066, pvalue=0.33069879934011182)