The products explored under the garment purchase were split into and categorized as children’s, women’s, and men’s wear. Due to differing social roles fulfilled by men and women, it was felt that there might be a major difference in the purchases made by men and women.
Women | Children | Men | Total |
---|---|---|---|
23 | 17 | 50 | 90 |
import scipy.stats as stats
observed = [23, 17, 50]
expected = [30, 30, 30]
x = stats.chisquare(f_obs=observed, f_exp=expected)
critical = stats.chi2.ppf(1 - 0.05, df=2)
print("Chi-Square =", x[0])
print("Critical =", critical)
print("p =", x[1])
Chi-Square = 20.6 Critical = 5.991464547107979 p = 3.3633095185718975e-05
In this case there are two dimensions (gender and buying designer clothes) and the question asked by the chi-square test for association is whether, in this case, gender and buying cheap clothes are independent of each other.
Men | Women | |
---|---|---|
Buy designer clothes | 37 | 32 |
Do not buy designer clothes | 20 | 31 |
import scipy.stats as stats
data = [[37, 20], [32, 31]]
x = chi2_contingency(data, correction=False)
critical = stats.chi2.ppf(1 - 0.05, df=1)
print("Chi-Square =", x[0])
print("Critical =", critical)
print("p =", x[1])
Chi-Square = 2.440970285902311 Critical = 3.841458820694124 p = 0.11820309038082191