Download as pdf or txt
Download as pdf or txt
You are on page 1of 25

Statistical methods for Categorical

variables

By Eshetu Ejeta (PhD)

4/20/2021 Eshetu Ejeta, MPH, PhD, Ass't Prof. 1


Categorical Data Analysis..
• Categorical variables
• arises when individuals are categorized into two more mutually exclusive
groups.
• The measurement scale may be nominal or ordinal scale e.g Blood group,
social class, sex, presence of disease…etc.
• Non-Numerical
• Numerical (continuous variable) can be condensed into categorical variable.
• In a sample of individuals the number of falling into a particular
group is count or frequency.
• Therefore, analysis of categorical data is the analysis counts or
frequencies associated with each category of variables
• When two or more groups are compared the data are presented using
a frequency table(cross tabulation)

4/20/2021 Eshetu Ejeta, MPH, PhD, Ass't Prof. 2


Categorical Data…

The data can be summarized as the proportion of the total


number of individuals in one of the categories.

Suppose that 81 of a random sample of 1076 women from the


above study have a history of asthma.
4/20/2021 Eshetu Ejeta, MPH, PhD, Ass't Prof. 3
Categorical Data…
• Suppose that 81 of a random sample of 1076 women from the above
study have a history of asthma.
• Proportion(p)=81/1076= 0.075.
• Using the Normal approximation to the Binomial distribution, we can
obtain the Standard error of the observed proportion to obtain a
confidence interval for the proportion in the population.
• Then p is approximately Normally distributed with an estimated mean
= p and an estimated standard error =

4/20/2021 Eshetu Ejeta, MPH, PhD, Ass't Prof. 4


Categorical Data…
• As the number of samples n increases, the standard error of p
decreases toward zero; that is, the sample proportion p tends to be
closer to the parameter/true value π(population proportion).
• The sampling distribution of p is approximately normal for large n.
• Therefore, the 95%CI for proportion P or π is

• The above confidence interval formula does not work well unless n
is very large

4/20/2021 Eshetu Ejeta, MPH, PhD, Ass't Prof. 5


Contingency Tables
• The main aim of contingency table is to assess an association between
two categorical variables.
• A table that cross classifies two variables is called a two-way
contingency table
• A table that cross classifies three variables is called a three-way
contingency table, and so forth.
• A two-way table with I-rows and J-columns is called an I × J (read I–
by–J ) table.

4/20/2021 Eshetu Ejeta, MPH, PhD, Ass't Prof. 6


Contingency Tables
• Example: cross classifies a sample of Americans according to their
gender and their opinion about an afterlife.
• Does an association exist between gender and belief in an afterlife?
• Is one gender more likely than the other to believe in an afterlife? or
• Is belief in an afterlife independent of gender?

We can answer the above question via hypothesis testing or calculating CI for P.

4/20/2021 Eshetu Ejeta, MPH, PhD, Ass't Prof. 7


2X2 Contingency Tables
• A table composed of two rows(r) cross-classified by two columns(c)
• Involve two dichotomous variables
• Can be generalized to accommodate rxc contingency table
• Classification of a sample of subjects with respect to exposure-
outcome relationship.

4/20/2021 Eshetu Ejeta, MPH, PhD, Ass't Prof. 8


Comparing proportions in two-by-two tables

• How to analyze a rxc contingency tables?

• By difference of proportions

• By relative risk

• By Odds ratio

4/20/2021 Eshetu Ejeta, MPH, PhD, Ass't Prof. 9


Chi-Squared Test Statistics
• A chi-square is a probability distribution used to make statistical
inferences about categorical data in which the numbers of categories
are two or more.
• Widely used in the analysis of count or frequency data using
contingency tables.
• The usual test of association is display the data in a 2 x 2 table.
• A non-parametric statistic, also called a distribution free test
• Chi-square is always skewed to the right and indexed by degree of
freedom.
• The skewness diminishes as n increases

4/20/2021 Eshetu Ejeta, MPH, PhD, Ass't Prof. 10


4/20/2021 Eshetu Ejeta, MPH, PhD, Ass't Prof. 11
4/20/2021 Eshetu Ejeta, MPH, PhD, Ass't Prof. 12
Assumption of chi-square test
• The data are frequency data (counts of the number of individuals
falling within each category).

• Adequate sample size (n ≥ 40)

• The value of the expected cell should be 5 or more in at least 80% of


the cells, and no cell should have an expected of less than one.

• Measures/observation is independent of each other

• No observed cell should be zero

4/20/2021 Eshetu Ejeta, MPH, PhD, Ass't Prof. 13


Types of Chi-Square Tests

• Tests of independence
• Tests of goodness-of-fit
• Tests of homogeneity
• Test of linear trend

4/20/2021 Eshetu Ejeta, MPH, PhD, Ass't Prof. 14


Chi-Squared Tests of independence
• To measure association between exposure and outcome (test of no
association).

• Chi-squared test compares observed to expected counts under the


assumption of no association (Ho is true).

• Enables us to determine the degree of deviation between observed and


expected count and to conclude whether the deviation in count is due
to chance or other factors.

4/20/2021 Eshetu Ejeta, MPH, PhD, Ass't Prof. 15


Chi-Squared Tests of independence…

4/20/2021 Eshetu Ejeta, MPH, PhD, Ass't Prof. 16


Chi-Squared Tests of independence…

4/20/2021 Eshetu Ejeta, MPH, PhD, Ass't Prof. 17


Chi-Squared Tests of independence…

• Oi is the observed frequency for the ith category of the variable of


interest
• Ei is the expected frequency (given that is true) for the ith category.
• The quantity X2 is a measure of the extent to which, in a given
situation, pairs of observed and expected frequencies agree.

4/20/2021 Eshetu Ejeta, MPH, PhD, Ass't Prof. 21


Chi-Squared Tests of independence…
• In the case of a 2x2 contingency table, X2 may be calculated by the
following shortcut formula.
• where a, b, c, and d are the observed cell frequencies
• When we apply the rule (r-1)(c-1) for finding degrees of freedom to a
table, the result is 1 degree of freedom.

4/20/2021 Eshetu Ejeta, MPH, PhD, Ass't Prof. 22


Calculation of expected values
• The expected frequency(Ei) in each cell is the product of the row totals
and column totals divided by the sum of all the observed frequencies
(i.e., sample size).

• The expected numbers must be computed for each cell.


• The sum of the corresponding observed and expected row and column
totals should be the same.

4/20/2021 Eshetu Ejeta, MPH, PhD, Ass't Prof. 23


Er1c1= 120x36/300 E12=? E21=? E22=?

4/20/2021 Eshetu Ejeta, MPH, PhD, Ass't Prof. 24


Example

X2calc with 2 df=9.09

X2tab with 2 df= 5.99


Statistical decision: We reject Ho since 9.09 > 5.99
Interpretation: There is statistical significant association between pre-
conceptional use of folic acid and race (X2 (df=2) = 9.09)
4/20/2021 Eshetu Ejeta, MPH, PhD, Ass't Prof. 25
Chi-Squared Tests of independence…
• What if your data do not meet all these assumptions?
• Use Fisher’s Exact Test or
• Use McNemar Test

• Fisher’s Exact Test


• If assumption of “adequate sample size—all expected cell counts
must be ≥ 5) cannot be met.
• It is called exact because, if desired, it permits us to calculate the
exact probability of obtaining the observed results

4/20/2021 Eshetu Ejeta, MPH, PhD, Ass't Prof. 26


Fisher’s Exact Test
• Criteria
• Both variables are dichotomous qualitative
• Sample size less than 20
• sample size 20 to <40 but one of the cell has expected value of <5

4/20/2021 Eshetu Ejeta, MPH, PhD, Ass't Prof. 27


McNemar Test
• If assumption of measures independent of each other cannot be met
• It is a test to compare before and after findings in the same
individual or to compare findings in a matched analysis (for
dichotomous variables)
• This is a variation on the chi-square test that can be used when two
dichotomous variables are non-independent, for example:
• Twin studies
• Pretest(yes/no) and posttest(yes/no) observations on the same
individuals
• Matched cases and controls
Analyze > Nonparametric Tests > Legacy Dialogs > 2 Related Samples
>McNemar
4/20/2021 Eshetu Ejeta, MPH, PhD, Ass't Prof. 28

You might also like