Chi-square Χ2 Test for Independence of 2 categorical variables

Whether two variables (groups) are independent of each other or are related/linked to each other (affected by each other).
Does the observed distribution fit the theoretical/expected distribution derivable from independence?
Does the value of one variable affect the probability of the other variable?
The categorical variable's values are its categories. One variable's values are the rows, the other variable's values are the columns.

H0: the 2 categorical variables are independent
HA: the 2 categorical variables are dependent. (So, actually testing for dependence.)

Select a desired level of confidence (significance level, α) for the result of the test:
0.90 0.95 0.975 0.99 0.999

Type or paste your Observed joint distribution matrix/contingency/two-way frequency table (data only, no names, no totals):

#rows: #columns:

Calculations:

E (expected frequency P(A∩B), if independent, is P(A)*P(B)) of cell at row i, column j = (∑row i * ∑column j) / ∑∑cell.
Eij= (rowi total)(columnj total) / (grand total)    Each should be ≥5; if not, combine categories.

Expected joint distribution:

df =(rows-1)(cols-1):


Χ2 statistic=    critical value=
If the Χ2 test statistic > critical value, then null hypothesis (H0 that the two variables are independent) can be rejected, and the alternative hypothesis (HA that the variables are dependent, linked somehow) is supported.
If Χ2 test statistic < critical value, then, informally, the variables are independent, not linked.

p_value:
If >α, fail to reject H0, fail to reject independence, i.e. not sufficient evidence to reject independence [informally, the variables are probably independent].
If <α, reject H0, sufficient evidence to reject independence, [informally, the variables are probably dependent; but this is never "accepted"].

Contingency coefficient:<1
strength of the relationship, when there is one.

More about Χ2


doctors Vs nurses preference for new/old procedure
The variables are profession and preference.
       new   old   indifferent
docs   100    80       20
nurses  50   120       30
Do the professions feel the same or differently about the new procedure?
i.e. does profession make a difference? Is opinion is related to profession?


3 hospitals. 3 types of infections. Is number of infections related to hospital where occurred?
The variables are hospital and infection type.
infectionA infectionB infectionC
41   27  51
36    3  40
169 106 109


Is there a relationship between gender and alcohol consumption?
Male vs Female.
 Low    Moderate    High
 10       9           8
 13      16          12

       unvax vaxed
autism   25     64
no aut  362   1427

        M     F
smoke   14    11
no smok 17    19


color of helmet  B W Y
injured/not
 231 112  8
 491 377 31

dog right/wrong rows, malaria/not cols
 123 131
 52   14

Rows: handedness of parent (father/mother)    Cols: handedness of offspring (left/right) 
rt/rt
rt/lft
lft/rt
lft/lft
  5360    50928
   767     2736
   741     3667
    94      289

NFL overtime coin tosses.  Rows:cointoss winner won/lost game.  Cols: before/after rule change
252 59
208 52

home games  Rows: hometeam win/lose. Cols: 4 sports
127 53 50 57
 71 47 43 42

tornados 3 months, 4 years
48 33 3 0
12 10 9 18
113 62 50 43
relationship between month and year?