简体   繁体   中英

How to test the compliance of the sample with the given distribution by the Chi-square criterion?

Programming language - Python

I generate a sample like this, using the Numpy library, the approximate size is 1 million.

uniformSample = UniformSample(1000000)
uniformSample.generate()

def generate(self, a=0.0, b=1.0):
        self.left = a
        self.right = b
        self.sample = [np.random.uniform(low=self.left, high=self.right) for _ in range(self.size)]

I have various sample characteristics such as mean, variance, standard deviation and others. I need to check that the given sample corresponds to one or another type of distribution (there are 8 types in my case). You need to check this using the chi-square tes t. Dear mathematicians and programmers, can you please help me to check the conformity of the sample to any distribution in the most elegant and simple way possible?

Using built-in functions and libraries in Python is welcome!

Code examples in response to my question is welcome!

You can use the Kolmogorov-Smirnov test to test if a given data set could come from a given distribtuion. There is a scipy function scipy.stats.kstest that does this.

You don't say what distribution you are testing against, but for example, you could do something like

statistic, pvalue = scipy.stats.kstest(uniformSample.generate(), "norm") 

To test against a Gaussian distribution. The pvalue returned is the probability that the data could come from the passed distribution (in this case the p-value should be extremely small).

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