I have a friend who used this function to compute a chi-squared contingency table in a paper they are writing, and I don't think I fully understand what the results of this test are.
Function docstring in case the link breaks:
Chi-square test of independence of variables in a contingency table.
This function computes the chi-square statistic and p-value for the hypothesis test of independence of the observed frequencies in the contingency table [1] observed. The expected frequencies are computed based on the marginal sums under the assumption of independence; see scipy.stats.contingency.expected_freq. The number of degrees of freedom is (expressed using numpy functions and attributes):
dof = observed.size - sum(observed.shape) + observed.ndim - 1
The null hypothesis, as I understand it, is that the predictor variables are independent of the groups. More accurately, it is saying that the same distribution generated the data for all the groups.
What I don't understand is the alternative hypothesis. Is this saying that none of the variables are associated with the groups, or that they are collectively independent from the groups?