0% found this document useful (0 votes)
0 views17 pages

Module 2 Notes (AutoRecovered)

This document discusses the association between two variables, focusing on bivariate analysis, including nominal, ordinal, and continuous variables. It explains the use of contingency tables to summarize relationships, joint and marginal frequency distributions, and graphical representations like bar charts and scatter plots. Additionally, it covers measures of association such as Chi-Squared, Cramer's V, and the Contingency Coefficient to evaluate the strength of relationships between variables.

Uploaded by

Arceus FF
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views17 pages

Module 2 Notes (AutoRecovered)

This document discusses the association between two variables, focusing on bivariate analysis, including nominal, ordinal, and continuous variables. It explains the use of contingency tables to summarize relationships, joint and marginal frequency distributions, and graphical representations like bar charts and scatter plots. Additionally, it covers measures of association such as Chi-Squared, Cramer's V, and the Contingency Coefficient to evaluate the strength of relationships between variables.

Uploaded by

Arceus FF
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

DATA ANALYTICS

Association of Two Variables-Summarizing the Distribution of Two Discrete Variables,


Contingency Tables for Discrete Data, Joint, Marginal, and Conditional Frequency
Distributions, Graphical Representation of Two Nominal or Ordinal Variables, Measures of
Association for Two Discrete Variables, Association Between Ordinal and Continuous
Variables, Visualization of Variables from Different Scales.

Association of Two Variables

1. Core Objective

While previous chapters focused on analyzing a single variable, this chapter focuses on bivariate
analysis—studying the interdependence, association, or relationship between two (or more) variables.
The goal is to measure the degree of this association using appropriate graphical summaries and
statistical measures based on the variables' scales.

2. Association Between Nominal / Binary Variables

When variables are categorical and have no inherent order (nominal) or only two categories (binary),
we analyze them using proportions and frequency measures (often structured in contingency tables).

 Example 1 (Gender vs. Subject Preference):

o Variables: Gender (Male/Female) and Subject (Math/Biology).

o Logic: If there is no association, an equal proportion of males and females should


choose Math (and Biology). A significant difference in proportions indicates a
preference/association.

 Example 2 (Gender vs. Salary Group):

o Variables: Gender (Male/Female) and Salary (Low/High group).

o Logic: If there is no discrimination (no association), the number of males and females
in the low- and high-salary groups should be approximately equal.

3. Association Between Ordinal Variables

When variables have a natural ordering or ranking, we look at how those ranks align.

 Example (Dance Competition Judging):

o Variables: Ranks given by Judge 1 and ranks given by Judge 2.


DATA ANALYTICS

o Logic: To check for fairness/agreement, we want to see if both judges give similar
ranks to the same candidates (high ranks to good performers, low ranks to poorer
performers).

4. Association Between Continuous Variables

When variables are numerical and measurable on a continuous scale, we look for directional trends.

 Example (Infant Growth):

o Variables: Age, Height, and Weight of infants.

o Logic: These variables typically increase together. As age increases, height and
weight increase. Height and weight also have a positive relationship with each other.

Summarizing Two Discrete Variables:

When dealing with two discrete variables (variables with a countable number of distinct values or
categories), we summarize their relationship by listing all possible combinations of their categories
and counting how often each combination occurs. Instead of looking at each variable separately, we
analyze their joint occurrence. This is typically structured in a grid or table format, known as a
cross-tabulation or contingency table. Using the binary example from the introduction, we can
break down the combinations as follows:

 Variable 1 (Gender): Categories are Female and Male.

 Variable 2 (Salary Group): Categories are Low and High.

Because both variables have 2 categories, there are exactly 4 possible combinations to count:

1. Female and Low-salary

2. Female and High-salary

3. Male and Low-salary

4. Male and High-salary

A complete description of the joint occur rence of these two variables can be given by counting,
for each combination, the number of units for which this combination is measured

Contingency Tables for Discrete Data

1. What is a Contingency Table?

A two-dimensional contingency table (or cross-tabulation) is a grid used to display the joint
frequency distribution of two discrete variables. It shows how often combinations of categories
occur together.
DATA ANALYTICS

2. Concrete Example: Airline Customer Satisfaction

 Variable X (Travel Class): 3 categories - Economy (E), Business (B), First (F)

 Variable Y (Satisfaction Rating): 4 categories - 1 (Poor), 2 (Fair), 3 (Good), 4 (Very Good)

Instead of looking at a raw list of 12 passengers, the data is summarized into a 3 x 4 table:

4
1 2 3 (Ver Total
Travel
(Poor (Fair (Good y (Row
Class
) ) ) Good )
)

Econom
2 2 2 1 7
y

Business 0 1 2 1 4

First 0 0 0 1 1

Total
(Column 2 3 4 3 12
)

Joint Frequencies (Inside cells): 2 passengers flew Economy and rated it Poor. 0 passengers
flew Business and rated it Poor.

Marginal Frequencies (Totals): * The Row Totals show the distribution of X alone (7
Economy, 4 Business, 1 First).

 The Column Totals show the distribution of Y alone (2 Poor, 3 Fair, 4 Good, 3 Very Good).

 The bottom-right corner shows the grand total (n = 12).


DATA ANALYTICS

General Framework of a Contingency Table (k ×l Table)

A contingency table (also called a cross-tabulation table) is used to study the relationship
between two categorical variables.

Suppose:

 Variable X has k categories (or classes):

x 1 , x 2 ,… , x k

 Variable Y has l categories (or classes):

y 1 , y 2 , … , y lThen, the data can be arranged in a k ×l contingency table, where:

 Rows represent the categories of X .

 Columns represent the categories of Y .

 Each cell contains the frequency (count) of observations belonging to the


corresponding combination of categories.

General Structure

Variable X / Variable Y y 1 y 2 ... y l Row Total

x1 n11 n12 ... n1 l n1.

x2 n21 n22 ... n2 l n2.

⋮ ⋮ ⋮ … ⋮ ⋮

xk n k1 n k2 ... n kl n k.

Column Total n.1 n.2 ... n. l N

Notation

 nij : Number of observations in category x iand category y j.

 ni .: Total observations in row i .

 n. j : Total observations in column j .

 N : Grand total number of observations.


DATA ANALYTICS

k l
N=∑ ∑ nij
i=1 j =1

Frequency Distributions in a Contingency Table

When data on two variables are organized in a contingency table, we can study the relationship
between them using three important types of frequency distributions:

1. Joint Frequency Distribution

The joint frequency distribution shows how the values of both variables occur together.

 Each cell in the contingency table contains the number of observations corresponding to a
specific combination of categories of the two variables.

 It describes the simultaneous behavior of both variables.

Gender Pass Fail Total

Male 30 10 40

Female 25 15 40

Total 55 25 80

Here:

 30 = Number of Male students who passed

 15 = Number of Female students who failed

These cell frequencies constitute the joint frequency distribution.

2. Marginal Frequency Distribution

The marginal frequency distribution gives the distribution of one variable irrespective of the
other variable.

It is obtained by calculating the row totals or column totals of the contingency table.

From the above table

Gender Distribution
DATA ANALYTICS

Gender Frequency

Male 40

Female 40

Result Distribution

Result Frequency

Pass 55

Fail 25

These totals (margins of the table) form the marginal frequency distributions.

3. Conditional Frequency Distribution

The conditional frequency distribution describes the distribution of one variable when a particular
value/category of the other variable is fixed.

Example

If we consider only Male students, then:

Result Frequency

Pass 30

Fail 10

This is the conditional frequency distribution of Result given Gender = Male.

Similarly, for Female students:

Result Frequency

Pass 25

Fail 15

This is the conditional frequency distribution of Result given Gender = Female.

Relative Frequency Versions

If frequencies are converted into proportions or percentages, we obtain:


DATA ANALYTICS

Joint Relative Frequency Distribution

Cell Frequency
Joint Relative Frequency=
Grand Total

Example:

30
=0.375
80

Thus, 37.5% of all students are Male and Pass.

Marginal Relative Frequency Distribution

Row/Column Total
Marginal Relative Frequency =
Grand Total

Example:

40
=0.5
80

Thus, 50% of students are Male.

Conditional Relative Frequency Distribution

Cell Frequency
Conditional Relative Frequency =
Relevant Row or Column Total

Example:

Probability that a student passes given that the student is Male:

30
P(Pass ∣Male)= =0.75
40

Thus, 75% of male students passed.

Graphical Representation of Two Nominal or Ordinal Variables

When two categorical variables (nominal or ordinal) are studied together, their relationship can be
displayed using bar charts based on a contingency table.

A contingency table shows the frequencies of observations belonging to different combinations of


categories.

Bar Charts for Two Categorical Variables

Suppose:
DATA ANALYTICS

 Variable X = Travel Class (Economy, Business, First)

 Variable Y = Flight Quality Rating (Poor, Fair, Good, Very Good)

The categories of one variable are represented by bars, while the categories of the second variable are
shown within each bar.

Stacked Bar Chart

 Categories of Y are stacked on top of each other within a single bar for each category of X.

 Total height of the bar represents the total frequency for that category of X.

Advantages

 Shows overall totals and composition simultaneously.

 Requires less space than grouped bar charts.

Measures of Association for Two Discrete Variables

When two variables are not independent, they are said to be associated. Measures of association help
us determine how strongly two variables are related. Most association measures indicate the strength
of the relationship, but not necessarily its direction.

These measures are generally based on a contingency table, which is a special case of a k ×l
frequency table.

Contingency Table

For two discrete variables:


DATA ANALYTICS

 Variable X has categories x 1 , x 2

 Variable Y has categories y 1 , y 2

The 2 ×2contingency table is:

X/Y (y1) (y2) Total

(x1) a b a+b

(x2) c d c+d

Total a+c b+d n

Expected Frequency (~
n ij)

This is the theoretical count we expect to see in a specific cell of a contingency table if the two
variables are completely independent.

ni +¿⋅ n Row Total ×Column Total


~
n ij= +j
= ¿
n Grand Total

Key Characteristic:
While observed absolute frequencies (nij ) must be whole integers, expected frequencies can contain
decimals.

General Rule:
If the observed frequencies match or are very close to the expected frequencies, the variables are
independent or weakly associated. The larger the gap between observed and expected counts, the
stronger the association.

Example: Vaccination and Flu

Consider 200 individuals:

Vaccination Not Affected Affected Total

Vaccinated 90 10 100

Not Vaccinated 40 60 100

Total 130 70 200


DATA ANALYTICS

Here

a=90 , b=10 , c=40 , d=60Expected frequency of vaccinated and unaffected individuals:

¿ ¿Observed value = 90

Since 90 ≠ 65
the variables are not independent. This suggests that vaccination has a protective effect against
influenza.

To gain a better understanding about the strength of association between two variables, we need to
develop the concept of dependence and independence further. The following three subsections
illustrate this in more detail

1. Pearson's χ 2(Chi-Squared) Statistic

Pearson's χ 2statistic measures the total discrepancy between what we observe and what we expect
under the assumption of independence.

Formulas

For a general k ×l table:

( nij −~nij )
k l 2

χ =∑ ∑
2
~n
i=1 j =1 ij

Shortcut for a 2 ×2table (using cell notations a , b , c , d ):

2
χ =n ¿ ¿

Key Properties

Range: 0 ≤ χ 2 ≤ n(min ⁡(k ,l)−1)


where min ⁡(k , l) represents the smaller number of either rows (k ) or columns (l ).

Interpretation:
A value near 0 indicates a weak association; a value close to the maximum limit indicates a strong
association.

Standardized Measures of Association

The Chi-Square statistic ( χ 2) indicates whether an association exists between two categorical
variables. However, its value depends on the sample size (n ) and the size of the contingency table.
Therefore, standardized measures are used to express the strength of association on a scale from 0 to
1, making comparisons easier.
DATA ANALYTICS

2. Cramer's V Statistic

Purpose

Cramer's V measures the strength of association between two categorical variables and is suitable for
contingency tables of any size (k ×l ).

Formula


2
χ
V=
n(min ⁡(k , l)−1)

where:

2
 χ = Chi-Square statistic

 n = total sample size

 k = number of rows

 l = number of columns

 min ⁡(k , l)= smaller of k and l

Why divide by n(min ⁡(k ,l)−1)?

The maximum possible value of χ 2depends on the sample size and table dimensions. Dividing by
n(min ⁡(k ,l)−1)removes this dependence and scales the result between 0 and 1.

Interpretation

Cramer's V Strength of Association

0 No association

0.1 – 0.3 Weak association

0.3 – 0.5 Moderate association

> 0.5 Strong association

1 Perfect association

Example: V =0.54
indicates a moderately strong to strong association.

3. Contingency Coefficient C

After performing a Chi-Square ( χ 2) Test of Independence, we often want to know:


DATA ANALYTICS

 How strong is the association between two categorical variables?

 Is the relationship weak, moderate, or strong?

The Contingency Coefficient C is a measure of the strength of association between two nominal
variables.

The coefficient is defined as: C=


√ χ2
2
χ +n

Where χ 2= Chi-square statistic , n = Total sample size

. Maximum Possible Value of C

The maximum value is C max=


√ min ⁡( k ,l)−1
min ⁡(k ,l)

Where k = Number of columns , l = Number of rows , min ⁡(k , l)= Smaller of the two dimensions

To standardize the coefficient so that it ranges between 0 and 1:

C
C corr=
Cmax

Equivalent formula:

C corr=
√ min ⁡(k , l)
min ⁡(k ,l)−1 √ χ2
2
χ +n

Eg: given χ 2 = 57.95064

A value closer to 1 indicates a stronger association between the two categorical variables.

Association Between Ordinal and Continuous Variables

1. Graphical Representation of Two Continuous Variables :A simple way to graphically


summarize the association between two continuous variables is to plot the paired observations of the
DATA ANALYTICS

two variables in a two-dimensional coordinate system. If n paired observations for two continuous
variables X and Y are available as (xi, yi),i = 1,2,...,n, then all such observations can be plotted in a
single graph. This graph is called a scatter plot.

Positive Association

 As the values of X increase, the values of Y also increase.

 Points move upward from left to right.

Negative Association

 As the values of X increase, the values of Y decrease.

 Points move downward from left to right.

Strong Association

 Points are closely clustered around an imaginary straight line.

 Indicates a strong relationship.

Weak Association

 Points are widely scattered but still show an increasing or decreasing trend.

No Association

 Points are randomly scattered. No visible pattern or trend.


DATA ANALYTICS

2. Correlation Coefficient

Suppose two variables X and Y are measured on a continuous scale and are linearly related like
Y = a + bX where a and b are constant values. The correlation coef ficient r(X,Y) = r measures the
degree of linear relationship between X and Y using

 The correlation coefficient is independent of the units of measurement of X and Y . For


example, if someone measures the height and weight in metres and kilograms respectively
DATA ANALYTICS

and another person measures them in centimetres and grams, respec tively, then the
correlation coefficient between the two sets of data will be the same.
 The correlation coefficient is symmetric, i.e. r(X,Y) = r(Y, X).
 The limits of r are −1 ≤ r ≤1.
o If all the points in a scatter plot lie exactly on a straight line, then the linear
relationship between X and Y is perfect and |r|=1
o If the relationship between X and Y is (i) perfectly linear and increasing, then r
=+1 and (ii) perfectly linear and decreasing, then r =−1.
o The signs of r thus determine the direction of the association.
o Ifr is close to zero, then it indicates that the variables are independent or the
relationship is not linear.

Example : In a decathlon competition, a group of athletes are competing with each other in 10
different track and field events. Suppose we are interested in how the results of the 100-m race relate
to the results of the long jump competition. The correlation coefficient for the 100-m race (X, in
seconds) and the long jump event (Y, in metres) for 5 athletes participating in the 2004 Olympic
Games (see also Appendix A.4) are listed in Table4.7. To calculate the correlation coefficient, we
need the following summary statistics
DATA ANALYTICS

3. Spearman’s Rank Correlation Coefficient

When one variable is ordinal or when data are ranked, Spearman's Rank Correlation
Coefficient (R or ρ) is used.

Why Spearman Correlation?

Pearson correlation requires numerical continuous data.

Spearman correlation works with:

 Ordinal variables

 Ranked data

 Continuous data converted into ranks

Hence, it is ideal for studying association between ordinal and continuous variables.

2
6 ∑ di
Formula R=1− 2
n(n −1)

where: d i= difference between ranks , n = number of observations

Range

+1 Perfect Agreement

0 No Association

-1 Perfect Disagreement

Example : calculate Spearman’s rank correlation coefficient for the first five observations of the
decathlon data. Again we list the results of the 100-m race (X) and the results of the long jump
competition (Y). In addition, we assign ranks to both X and Y. For example, the shortest time receives
rank 1, whereas the longest time receives rank 5. Similarly, the shortest long jump result receives rank
1, the longest long jump result receives rank 5
DATA ANALYTICS

You might also like