chisquare(f_obs, f_exp=None, ddof=0, axis=0)
The chi-square test tests the null hypothesis that the categorical data has the given frequencies.
This test is invalid when the observed or expected frequencies in each category are too small. A typical rule is that all of the observed and expected frequencies should be at least 5. According to , the total number of samples is recommended to be greater than 13, otherwise exact tests (such as Barnard's Exact test) should be used because they do not overreject.
Also, the sum of the observed and expected frequencies must be the same for the test to be valid; chisquare raises an error if the sums do not agree within a relative tolerance of 1e-8.
The default degrees of freedom, k-1, are for the case when no parameters of the distribution are estimated. If p parameters are estimated by efficient maximum likelihood then the correct degrees of freedom are k-1-p. If the parameters are estimated in a different way, then the dof can be between k-1-p and k-1. However, it is also possible that the asymptotic distribution is not chi-square, in which case this test is not appropriate.
Observed frequencies in each category.
Expected frequencies in each category. By default the categories are assumed to be equally likely.
"Delta degrees of freedom": adjustment to the degrees of freedom for the p-value. The p-value is computed using a chi-squared distribution with k - 1 - ddof degrees of freedom, where k is the number of observed frequencies. The default value of ddof is 0.
Calculate a one-way chi-square test.
scipy.stats.barnard_exact
scipy.stats.fisher_exact
import numpy as np
from scipy.stats import chisquare
chisquare([16, 18, 16, 14, 12, 12])
chisquare([16, 18, 16, 14, 12, 12], f_exp=[16, 16, 16, 16, 16, 8])
obs = np.array([[16, 18, 16, 14, 12, 12], [32, 24, 16, 28, 20, 24]]).T
obs.shape
chisquare(obs)
chisquare(obs, axis=None)
chisquare(obs.ravel())
chisquare([16, 18, 16, 14, 12, 12], ddof=1)
chisquare([16, 18, 16, 14, 12, 12], ddof=[0,1,2])
chisquare([16, 18, 16, 14, 12, 12],
f_exp=[[16, 16, 16, 16, 16, 8], [8, 20, 20, 16, 12, 12]],
axis=1)
The following pages refer to to this document either explicitly or contain code examples using this.
scipy.stats.contingency:chi2_contingency
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them