Cross tabulation
●

●

●
●

●

Comparison of 2 proportions

Comparison of proportions– Last week we learned the comparison of means or medians between
the 2 quantitative variables– In the case of categorical variables, comparison of proportions can beapplied (In the case of more than 2 groups, it's similarly applicable).
Independence of 2 categorical variables– Making cross table, then test the null-hypothesis that the 2 variables are
independent each other by chi-square test or fisher's exact probability
test.

●

●If we compare the proportions of smoker between patients andcontrols, 40 among 100 and 20 among 100, respectively, typeprop.test(c(40, 20), c(100, 100)) in the script window, and click[submit], then you can get the result, p-value=0.00337
The way to conduct it in EZR menu, see below.

The analyses above are essentially same.
(cf.) "How large the effect of the difference of groups on disease occurrenceis" can be measured by odds ratios, rate ratios, risk ratios, rate differences
or risk differences (already learned)(cf.2) Association between 2 categorical variables can be assessed byPearson's contingency coefficients, phi coefficients, Cramer's V, andpolychoric correlation coefficients

5/23/18

1

5/23/18

Comparison of 2 proportions (cont'd)●●Chi-square test for independence

From the raw category data, for example, in the case of [survey]
data of [MASS] package to compare the proportions of lefties
between males and females, typeprop.test(table(survey$Sex, survey$W.Hnd))in the script window and click [submit].
The way to conduct it in EZR menu,
see below.

●

●

●

5/23/18

23

In the chi-square test for independence,– First, make a cross table (contingency table) by the combination of2 categorical variables: each number of cells can be denoted asn[i, j]. If each variable is binary, the table will be a 2x2 cross table.
– Denote N1=n[1, 1]+n[2, 1], N2=n[1, 2]+n[2, 2], M1=n[1, 1] +n[1, 2],
M2=n[2, 1]+n[2, 2], N=N1+N2=M1+M2– Calculate the expected number x[i, j] of each cell if row andcolumn variables are independent.
●x[1, 1]=N1*M1/N, x[2, 1]=N1*M2/N, x[1, 2]=N2*M1/N,x[2, 2]=N2*M2/N.
– Calculate chi-squared as χ2=Σ {(n[i, j] – x[i, j])2/x[i, j]}– The value of χ2 obeys chi-square distribution of d.f.=1.
chisq.test(matrix(c(80, 20, 55, 45), 2, 2)) gives the result for the test
for independence between smoking and lung cancer (pp.91-92).
The way in EZR is similar to the comparison of proportions.

5/23/18

4

Fisher's exact probability test forindependence●●●Chi-square test uses approximation (thecombination can take only integer but the chisquare distribution is continuous) and thus is
not appropriate for a small-sized sample.
Fisher invented the direct calculation method tocalculate the sum of the probabilities for thegiven combination and less plausiblecombinations under the condition ofindependence, where all marginal numbers are
fixed, then the probability obeys
hypergeometric distribution.
This method for the same case is done byfisher.test(matrix(c(80, 20, 55, 45), 2, 2))
The way in EZR is similar to the comparison ofproportions, but check the [Fisher's exact test]of the dialogue.

5/23/18●●●

55/23/18

Association statistics (1): Pearson's
contingency coefficients, and so on●●

6

Association statistics (2): Polychoric
correlation coefficients

The extent of association between 2 categorical variables with 2
categories can be measured by the following indicators.
Let's consider the relationship between smoking habits and lungcancer as already mentioned: The numbers of past smokers were 80
and 55 in Lung cancer patients and healthy controls, respectively.
– Odds Ratio (rate and risk are unavailable in case-control study) is(80/20)/(55/45). It can be obtained by either offisher.test(matrix(c(80, 20, 55, 45), 2, 2))library(fmsb); oddsratio(80, 20, 55, 45)– The results are slightly different because fisher.test() uses
maximum likelihood estimation, but both significant.
– Other association statistics can be obtained by assocstats()
function of vcd package, such aslibrary(vcd); assocstats(matrix(c(80, 20, 55, 45), 2, 2))– Pearson's contingent coefficients and Cramer's V are applicablefor the variables with 3 or more levels without order.

5/23/18

Comparison of proportions among 3 groups– Schistosomiasis positive results of Kato-Katz fecal test wereobtained from 60, 30, and 8 in 100 fishermen, 80 farmers, and 30
office workers, respectively, thenprop.test(c(60, 30, 8), c(100, 80, 30))●
For graph of positive proportions, try
barplot(c(60, 30, 8)/c(100, 80, 30))●
For pairwise comparisons, try
pairwise.prop.test(c(60, 30, 8), c(100, 80, 30),
p.adjust.method="fdr")– If we assume the tendency in the risk of subpopulations as 4:2:1,Cochran-Armitage test is applicableprop.trend.test(c(60, 30, 8), c(100, 80, 30), c(4, 2, 1))
If the number of groups is more than 3, the way is similar.
In EZR, directly entering the data of positive and negative numbers
instead of positive and total, simple chi-square test is possible.

7

●

●

When you like to test the association between non-binary
categorical variables with order, polychoric correlation
coefficient is better than rank correlation or contingency
coefficients.
Please consider the association of smoking habits andexercise in the [survey] data.
– First, reorder factor levels of [Smoke] and [Exer] as[Smoke2] and [Exer2].
– library(polycor)
polychor(survey$Smoke2, survey$Exer2, std.err=TRUE)– It's different frompolychor(survey$Smoke, survey$Exer, std.err=TRUE)

5/23/18

1.0

0.8Frequency●

Comparison of proportions among 3 ormore groups

0.6

0.4

0.2

0.0
NeverOccas

Regul
Smoke2

Heavy
Exer2
FreqSomeNone8