简体   繁体   中英

Performing the KS-test on a scaled distribution in python

I want to perform the KS-test on my data by comparing it to a uniform distribution that has been scaled.

How do I pass just a scale parameter to the args in scipy.stats.kstest (without passing any other argument to it)? I want it to take the default value for the other arguments (egs:loc)

See:
1. https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.uniform.html
2. https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.kstest.html

I tried the following but it did not work (invalid syntax)

stats.kstest(data, 'uniform',args=(scale=15.0))

In this case, create a lambda for the distribution you want and divide the x parameter by the desired scale. An example follows:

import random
import scipy.stats as stats
data=[random.random()*15 for i in range(10000)]
stats.kstest(data, lambda x: stats.uniform.cdf(x/15.0))

An alternative approach, which works for the distributions found in SciPy:

stats.kstest(data, lambda x: stats.uniform.cdf(x,scale=15.0))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM