如何通过卡方准则检验样本是否符合给定的分布?

发布于 2025-01-12 03:13:47 字数 576 浏览 0 评论 0原文

编程语言-Python

我使用Numpy库生成了一个这样的样本,大约大小是100万。

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)]

我有各种样本特征,例如均值、方差、标准差等。 我需要检查给定的样本是否对应于一种或另一种分布类型(在我的例子中有 8 种类型)。您需要使用卡方检验来检查这一点。亲爱的数学家和程序员,你们能帮我以最优雅、最简单的方式检查样本对任何分布的符合性吗?

欢迎使用Python中的内置函数和库!

欢迎使用代码示例来回答我的问题!

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 test. 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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烙印 2025-01-19 03:13:47

您可以使用Kolmogorov-Smirnov测试测试给定的数据集是否来自给定的分布。有一个 scipy 函数 scipy.stats.kstest 可以执行此操作。

您没有说明要测试的分布,但例如,您可以执行类似

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

“测试高斯分布”之类的操作。返回的 pvalue 是数据可能来自传递的分布的概率(在这种情况下,p 值应该非常小)。

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文