- Mastering Python for Data Science
- Samir Madhavan
- 270字
- 2021-07-16 20:14:21
The chi-square distribution
The chi-square statistics are defined by the following formula:

Here, n is the size of the sample, s is the standard deviation of the sample, and σ is the standard deviation of the population.
If we repeatedly take samples and define the chi-square statistics, then we can form a chi-square distribution, which is defined by the following probability density function:

Here, Y0 is a constant that depends on the number of degrees of freedom, Χ2 is the chi-square statistic, v = n - 1 is the number of degrees of freedom, and e is a constant equal to the base of the natural logarithm system.
Y0 is defined so that the area under the chi-square curve is equal to one.

Chi-square for the goodness of fit
The Chi-square test can be used to test whether the observed data differs significantly from the expected data. Let's take the example of a dice. The dice is rolled 36 times and the probability that each face should turn upwards is 1/6. So, the expected distribution is as follows:

>>> expected = np.array([6,6,6,6,6,6])
The observed distribution is as follows:

>>> observed = observed = np.array([7, 5, 3, 9, 6, 6])
The null hypothesis in the chi-square test is that the observed value is similar to the expected value.
The chi-square can be performed using the chisquare
function in the SciPy package:
>>> stats.chisquare(observed,expected) (3.333333333333333, 0.64874235866759344)
The first value is the chi-square value and the second value is the p-value, which is very high. This means that the null hypothesis is valid and the observed value is similar to the expected value.
- Java語言程序設計
- Expert C++
- 程序員修煉之道:程序設計入門30講
- Learning C# by Developing Games with Unity 2020
- Developing Mobile Web ArcGIS Applications
- ADI DSP應用技術集錦
- Windows Server 2016 Automation with PowerShell Cookbook(Second Edition)
- 深入淺出Serverless:技術原理與應用實踐
- Hands-On Reinforcement Learning with Python
- Haskell Data Analysis Cookbook
- 寫給大家看的Midjourney設計書
- 黑莓(BlackBerry)開發從入門到精通
- ArcPy and ArcGIS(Second Edition)
- 零基礎學編程系列(全5冊)
- 例說FPGA:可直接用于工程項目的第一手經驗