Regression Analyses�
Dr. Debasis Samanta
Associate Professor
Department of Computer Science & Engineering
This presentation includes…
DSamanta@IIT Kharagpur
2
Regression Analysis
Introduction
DSamanta@IIT Kharagpur
3
Regression Analysis
Hypothesis Testing Strategies
DSamanta@IIT Kharagpur
4
Regression Analysis
Types of tests of hypotheses
Also called
distribution-free test of hypotheses
Non-parametric tests
Also called
standard test of hypotheses
Parametric tests
Parametric Tests : Assumptions
DSamanta@IIT Kharagpur
5
Regression Analysis
Usually assume certain properties of the population from which we draw samples.
Hypothesis Testing: Non-Parametric Test
DSamanta@IIT Kharagpur
6
Regression Analysis
Non-parametric tests
Note:
Non-parametric tests need entire population (or sample of very large size)
Data for Relationship Analysis
DSamanta@IIT Kharagpur
7
Regression Analysis
Example:
Univariate population: The population consisting of only one variable.
Example:
| | | | | | | |
Here, statistical measures suffice to find a relationship.
Bivariate population: Here, the data happen to be with two variables.
.
| | | | |
| | | | |
Data for Relationship Analysis
DSamanta@IIT Kharagpur
8
Regression Analysis
Multivariate population: If the data happen to be one more than two variable.
.
Example:
? If we add another variable say viscosity in addition to Pressure, Volume or Temperature?
Measures of Relationship
DSamanta@IIT Kharagpur
9
Regression Analysis
Q1: Does there exist relation between two variables (in case of bivariate population) ?
Q2: Is there any relationship between one variable in one side and two or more variables on the other side (in case of multivariate population)?
In case of bivariate and multivariate populations, usually, we have to answer two types of questions:
Measures of Relationship
DSamanta@IIT Kharagpur
10
Regression Analysis
Q1: Does there exist relation between two variables (in case of bivariate population) ?
Q2: Is there any relationship between one variable in one side and two or more variables on the other side (in case of multivariate population)?
In case of bivariate and multivariate populations, usually, we have to answer two types of questions:
Solution
?
Measures of Relationship
DSamanta@IIT Kharagpur
11
Regression Analysis
Q1: Does there exist relation between two variables (in case of bivariate population) ?
Q2: Is there any relationship between one variable in one side and two or more variables on the other side (in case of multivariate population)?
To find solutions to the above questions, two approaches are known.
Correlation Analysis
Regression Analysis
In case of bivariate and multivariate populations, usually, we have to answer two types of questions:
Correlation Analyses
DSamanta@IIT Kharagpur
12
Regression Analysis
Correlation Analysis
DSamanta@IIT Kharagpur
13
Regression Analysis
Example: Weight is correlated with height
In statistics, the word correlation is used to denote some form of association between two variables.
Correlation Analysis
DSamanta@IIT Kharagpur
14
Regression Analysis
| | | | | | | |
| | | | | | | |
Do you find any correlation between X and Y as shown in the table?
Note
Look at the table given below
Correlation Analysis
DSamanta@IIT Kharagpur
15
Regression Analysis
| | | | | | | |
| | | | | | | |
When the values of attribute A varies at random with B and vice-versa.
Correlation
If the value of the attribute A increases with the increase in the value of the attribute B and vice-versa.
If the value of the attribute A decreases with the increase in the value of the attribute B and vice-versa.
Zero correlation
Positive correlation
Negative correlation
Correlation Analysis
DSamanta@IIT Kharagpur
16
Regression Analysis
Positive correlation
Negative correlation
Zero correlation
Form of Correlation
DSamanta@IIT Kharagpur
17
Regression Analysis
A correlation is linear when two variables
change at constant rate.
Concerning the form of a correlation, it could be linear, non-linear, or monotonic.
Linear Correlation
In this case, the relationship between
the variables graph as a curved pattern
parabola, hyperbola … etc).
Non-linear Correlation
Form of Correlation
DSamanta@IIT Kharagpur
18
Regression Analysis
Concerning the form of a correlation , it could be linear, non-linear, or monotonic.
Monotonicity of a function
Form of Correlation
DSamanta@IIT Kharagpur
19
Regression Analysis
Monotonic correlation: In a monotonic relationship, the variables tend to move in the same relative direction or opposite direction, but not necessarily at a constant rate.
Concerning the form of a correlation , it could be linear, non-linear, or monotonic :
Monotonic and non-monotonic relations
Correlation Analysis
DSamanta@IIT Kharagpur
20
Regression Analysis
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
We need to measure the degree of correlation between two attributes.
Exam score
Correlation Coefficient
DSamanta@IIT Kharagpur
21
Regression Analysis
Correlation Coefficient
DSamanta@IIT Kharagpur
22
Regression Analysis
Correlation Coefficient
DSamanta@IIT Kharagpur
23
Regression Analysis
Correlation Coefficient
DSamanta@IIT Kharagpur
24
Regression Analysis
Measuring Correlation Coefficients
DSamanta@IIT Kharagpur
25
Regression Analysis
Karl Pearson’s coefficient
Find correlation coefficient between two numerical attributes
Charles Spearman’s coefficient
Find correlation coefficient between two ordinal attributes
Chi-square coefficient of correlation
Find correlation coefficient between two nominal attributes
Three methods to measure the correlation coefficients
DSamanta@IIT Kharagpur
26
Regression Analysis
Pearson’s Correlation Analysis
Karl Pearson’s Correlation Analysis
DSamanta@IIT Kharagpur
27
Regression Analysis
Monalisa Sarma
IIT KHARAGPUR
This is also called Pearson’s Product Moment Correlation
Definition : Karl Pearson’s correlation coefficient
Karl Pearson’s Coefficient of Correlation
DSamanta@IIT Kharagpur
28
Regression Analysis
A small study is conducted involving 17 infants to investigate the association between gestational age at birth, measured in weeks, and birth weight, measured in grams.
Example : Correlation of Gestational Age and Birth Weight
Karl Pearson’s coefficient of Correlation
DSamanta@IIT Kharagpur
29
Regression Analysis
A small study is conducted involving 17 infants to investigate the association between gestational age at birth, measured in weeks, and birth weight, measured in grams.
Example : Correlation of Gestational Age and Birth Weight
Karl Pearson’s coefficient of Correlation
DSamanta@IIT Kharagpur
30
Regression Analysis
For the given data
Conclusion: The sample’s correlation coefficient indicates a strong positive correlation between Gestational Age and Birth Weight.
Significance Test
DSamanta@IIT Kharagpur
31
Regression Analysis
Definition : Karl Pearson’s correlation coefficient
Karl Pearson’s Coefficient of Correlation
DSamanta@IIT Kharagpur
32
Regression Analysis
Significance Test
DSamanta@IIT Kharagpur
33
Regression Analysis
Rank Correlation Analysis
Charles Spearman’s Correlation Coefficient
DSamanta@IIT Kharagpur
34
Regression Analysis
This correlation measurement is also called Rank correlation
Example
Rank assigned
Charles Spearman’s Correlation Coefficient
DSamanta@IIT Kharagpur
35
Regression Analysis
Definition 2: Charles Spearman’s correlation coefficient
Charles Spearman’s Coefficient of Correlation
Example 2: The hypothesis that the depth of a river does not progressively increase further from the bank.
A sample of size 10 is collected to test the hypothesis, using Spearman’s correlation coefficient.
DSamanta@IIT Kharagpur
36
Regression Analysis
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
Charles Spearman’s Coefficient of Correlation
Step 1: Assign rank to each data. It is customary to assign rank 1 to the largest data, and 2 to next largest and so on.
Note: If there are two or more samples with the same value, the mean rank should be used.
DSamanta@IIT Kharagpur
37
Regression Analysis
| | | | | |
| | | | | |
| | | | | |
Charles Spearman’s Coefficient of Correlation
Step 2: The contingency table will look like
DSamanta@IIT Kharagpur
38
Regression Analysis
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | |||||
Charles Spearman’s Coefficient of Correlation
DSamanta@IIT Kharagpur
39
Regression Analysis
Spearaman’s rank correlation coefficient
Charles Spearman’s Coefficient of Correlation
DSamanta@IIT Kharagpur
40
Regression Analysis
DSamanta@IIT Kharagpur
41
Regression Analysis
χ2 Correlation Analysis
Chi-Squared Test of Correlation
DSamanta@IIT Kharagpur
42
Regression Analysis
| | | | | | | |
| | | | | | | |
Contingency Table
Given a data set, it is customary to draw a contingency table, whose structure is given below.
DSamanta@IIT Kharagpur
43
Regression Analysis
Entry into Contingency Table: Observed Frequency
In contingency table, an entry Oij denotes the event that attribute A takes on value ai and attribute B takes on value bj (i.e., A = ai, B = bj).
DSamanta@IIT Kharagpur
44
Regression Analysis
| | | | | | | |
| | | | | | | |
Entry into Contingency Table: Expected Frequency
In contingency table, an entry eij denotes the expected frequency, which can be calculated as
DSamanta@IIT Kharagpur
45
Regression Analysis
A | B |
… | … |
ai | bj |
… | … |
ai | bj |
… | … |
… | … |
ai | bj |
… | … |
… | … |
… | … |
… | … |
DSamanta@IIT Kharagpur
46
Regression Analysis
Definition 3: χ2-Value
DSamanta@IIT Kharagpur
47
Regression Analysis
Example 3: Survey on Gender versus Hobby.
DSamanta@IIT Kharagpur
48
Regression Analysis
χ2 –Test
From the survey table, the observed frequency are counted and entered into the contingency table, which is shown below.
DSamanta@IIT Kharagpur
49
Regression Analysis
HOBBY | GENDER | |||
| Male | Female | Total | |
Book | | | | |
Computer | | | | |
Total | | | | |
Example : Survey on Gender versus Hobby.
Example 7.3: Survey on Gender versus Hobby.
DSamanta@IIT Kharagpur
50
Regression Analysis
HOBBY | GENDER | |||
| Male | Female | Total | |
Book | | | | |
Computer | | | | |
Total | | | | |
Example 3: Survey on Gender versus Hobby.
DSamanta@IIT Kharagpur
51
Regression Analysis
HOBBY | GENDER | |||
| Male | Female | Total | |
Book | | | | |
Computer | | | | |
Total | | | | |
DSamanta@IIT Kharagpur
52
Regression Analysis
Significance Test for 𝛘2 -Test
DSamanta@IIT Kharagpur
53
Regression Analysis
Cramer’s V Test
More on Correlation Analyses
DSamanta@IIT Kharagpur
54
Regression Analysis
55
56
CS 40003: Data Analytics
| | |
| | |
| | |
Tetrachoric correlation
57
| | |
| | |
| | |
Tetrachoric correlation: Example
58
| | |
| | |
| | |
Tetrachoric correlation: Example
59
CS 40003: Data Analytics
Cramer’s V correlation
60
CS 40003: Data Analytics
Cramer’s V correlation: Example
| Eye Color | ||
| Blue | Green | Brown |
East | | | |
North | | | |
west | | | |
61
CS 40003: Data Analytics
| Eye Color | | ||
| Blue | Green | Brown | Row Total |
East | | | | 19 |
North | | | | 13 |
west | | | | 18 |
Column Total | 14 | 19 | 17 | Grand total 50 |
Step 1:
Here all the frequencies are called observed frequency.
Add all values row wise and column wise.
Here
row totals are 19,13,18
column totals are 14, 19, 17
Grand Total is 50
Cramer’s V correlation: Example
62
CS 40003: Data Analytics
| Eye Color | | ||
| Blue | Green | Brown | Row Total |
East | | | | 19 |
North | | | | 13 |
west | | | | 18 |
Column Total | 14 | | 17 | Grand Total = 50 |
Cramer’s V correlation: Example
63
CS 40003: Data Analytics
Observed values | Eye Color | ||
| Blue | Green | Brown |
East | | | |
North | | | |
west | | | |
Expected values | Eye Color | ||
| Blue | Green | Brown |
East | 5.32 | | |
North | | | |
west | | | |
Cramer’s V correlation: Example
64
CS 40003: Data Analytics
Step 4:
The correlation between three different eye colors (blue, green and brown) and three regions (east, north and west) is 0.25
It means eye color is weakly associated with the regions.
Cramer’s V correlation: Example
65
CS 40003: Data Analytics
Point-biserial correlation is a measure of the association between a continuous valued and a binary valued
variable.
Point-biserial correlation
66
CS 40003: Data Analytics
Example:
Suppose we want to know whether or not gender is associated with weekly expenditure of the students, where we take a simple random sample of 7 students and survey on them.
| |
12 | 1 |
8 | 1 |
| |
| |
| |
| |
| |
Point-biserial correlation: Example
67
CS 40003: Data Analytics
| |
12 | 1 |
8 | 1 |
| |
| |
| |
| |
| |
Here, the coefficient of correlation between gender and weekly expenditure of the students is 0.85.
It means gender is strongly associated with weekly expenditure of the students.
Point-biserial correlation: Example
Regression Analysis
DSamanta@IIT Kharagpur
68
Regression Analysis
Learning Strategies
DSamanta@IIT Kharagpur
69
Regression Analysis
There are two types of learning concepts:
Learning
Learning population parameters
Statistical Learning
Learning models
Machine Learning
Statistical Learning
DSamanta@IIT Kharagpur
70
Regression Analysis
Usually assumes certain properties of the population from which we draw samples:
Machine Learning
DSamanta@IIT Kharagpur
71
Regression Analysis
This learning strategy needs a very large sample data
Important Point
y = f(x) = ax2 + bx + c
DSamanta@IIT Kharagpur
72
Regression Analysis
Relationship Analysis
Relationship Analysis
A large data regarding the wages for a group of employees from the eastern region of India is given.
In particular, we wish to understand the following relationships:
DSamanta@IIT Kharagpur
73
Regression Analysis
Relationship Analysis
DSamanta@IIT Kharagpur
74
Regression Analysis
How wages vary with ages?
?
Relationship Analysis
Interpretation: On the average, wage increases with age until about 60 years of age, at which point it begins to decline.
DSamanta@IIT Kharagpur
75
Regression Analysis
Relationship Analysis
DSamanta@IIT Kharagpur
76
Regression Analysis
How wages vary with time?
?
Relationship Analysis
Interpretation: There is a slow but steady increase in the average wage between 2010 and 2016.
.
DSamanta@IIT Kharagpur
77
Regression Analysis
Relationship Analysis
DSamanta@IIT Kharagpur
78
Regression Analysis
?
Whether wages are related with education?
Relationship Analysis
Interpretation: On the average, wage increases with the level of education.
DSamanta@IIT Kharagpur
79
Regression Analysis
Relationship Analysis
DSamanta@IIT Kharagpur
80
Regression Analysis
What more information can we get?
Given an employee’s wage can we predict his age?
Whether wage has any association with both year and education level?
... and what’s more?
DSamanta@IIT Kharagpur
81
Regression Analysis
Regression Analysis to Find Relationships
An Open Challenge!
DSamanta@IIT Kharagpur
82
Regression Analysis
Yahoo!
Just decide the values of a and b
(as if storing one point’s data only!)
Note: Here, tricks was to find a relationship among all the points.
DSamanta@IIT Kharagpur
83
Regression Analysis
Measures of Relationship
DSamanta@IIT Kharagpur
84
Regression Analysis
Univariate Population
| | | | | | | |
Bivariate Population
| | | | | | | |
Pressure | 1 | 1.5 | 1.05 | 0.96 | 1.2 | 2.5 | 2.8 |
Multivariate Population
| | | | | | | |
Pressure | 1 | 1.5 | 1.05 | 0.96 | 1.2 | 2.5 | 2.8 |
| | | | | | | |
Measures of Relationship
DSamanta@IIT Kharagpur
85
Regression Analysis
Relationship Analysis
Regression analysis
Linear Regression
Simple Linear Regression
Multiple Linear Regression
Non-linear Regression
Simple Non-linear Regression
Multiple Non-linear Regression
Auto-Regression Analysis
Logistic regression
Binary Logistic Regression
Multinomial Logistic Regression
Regression Analysis
DSamanta@IIT Kharagpur
86
Regression Analysis
The regression analysis is a statistical method to deal with the formulation of mathematical model depicting relationship amongst variables, which can be used for the purpose of prediction of the values of dependent variable, given the values of independent variable(s).
Definition
A Simple Example
DSamanta@IIT Kharagpur
87
Regression Analysis
How Exam Score is related to Hours of Study?
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
Regression Analyses
DSamanta@IIT Kharagpur
88
Regression Analysis
Regression Analysis
Linear Regression Models
Simple Linear Regression
Multiple Linear Regression
Non-linear Regression Models
DSamanta@IIT Kharagpur
89
Regression Analysis
Simple Linear Regression
Simple Linear Regression Model
DSamanta@IIT Kharagpur
90
Regression Analysis
In simple linear regression, we have only two variables:
Linear regression
Simple Linear Regression Model
DSamanta@IIT Kharagpur
91
Regression Analysis
In simple linear regression, we have only two variables:
Note
Regression Analysis
DSamanta@IIT Kharagpur
92
Regression Analysis
Regression Analysis
DSamanta@IIT Kharagpur
93
Regression Analysis
Note
True versus Fitted Regression Line
DSamanta@IIT Kharagpur
94
Regression Analysis
Least Square Method to estimate 𝛼 and 𝛽
DSamanta@IIT Kharagpur
95
Regression Analysis
Concept of Residuals
Least Square Method to estimate 𝛼 and 𝛽
DSamanta@IIT Kharagpur
96
Regression Analysis
Sum of Squares Error (SSE)
We need to minimize the value of SSE and hence to determine the parameters of a and b.
Least Square Method to estimate 𝛼 and 𝛽
DSamanta@IIT Kharagpur
97
Regression Analysis
Minimizing the Sum of Squares Error (SSE)
Least Square Method to estimate 𝛼 and 𝛽
DSamanta@IIT Kharagpur
98
Regression Analysis
Minimizing the Sum of Squares Error (SSE)
Least Square Method to estimate 𝛼 and 𝛽
DSamanta@IIT Kharagpur
99
Regression Analysis
Minimizing the Sum of Squares Error (SSE)
DSamanta@IIT Kharagpur
100
Regression Analysis
R2: Measure of Quality Fit
DSamanta@IIT Kharagpur
101
Regression Analysis
Coefficient of Determination
R2: Measure of Quality Fit
DSamanta@IIT Kharagpur
102
Regression Analysis
Coefficient of Determination
Note
DSamanta@IIT Kharagpur
103
Regression Analysis
Multiple Linear Regression
Regression Analyses
DSamanta@IIT Kharagpur
104
Regression Analysis
Regression Analysis
Linear Regression Models
Simple Linear Regression
Multiple Linear Regression
Non-linear Regression Models
Multiple Linear Regression
DSamanta@IIT Kharagpur
105
Regression Analysis
Definition:
Multiple Linear Regression
DSamanta@IIT Kharagpur
106
Regression Analysis
Formulation:
Multiple Linear Regression
DSamanta@IIT Kharagpur
107
Regression Analysis
Estimating the coefficients: The data points
Multiple Linear Regression
DSamanta@IIT Kharagpur
108
Regression Analysis
Estimating the coefficients: The model formulation
Multiple Linear Regression
DSamanta@IIT Kharagpur
109
Regression Analysis
Estimating the coefficients: Minimization of the SSE
Multiple Linear Regression
DSamanta@IIT Kharagpur
110
Regression Analysis
Estimating the coefficients: Minimization of the SSE
DSamanta@IIT Kharagpur
111
Regression Analysis
Non-Linear Regression Model
Regression Analyses
DSamanta@IIT Kharagpur
112
Regression Analysis
Regression Analysis
Linear Regression Models
Simple Linear Regression
Multiple Linear Regression
Non-linear Regression Models
Non-linear Regression Model
DSamanta@IIT Kharagpur
113
Regression Analysis
Definition and Formulation:
Solving for Polynomial Regression Model
DSamanta@IIT Kharagpur
114
Regression Analysis
Model formulation:
Solving for Polynomial Regression Model
DSamanta@IIT Kharagpur
115
Regression Analysis
Transformation to Linear Regression:
Linear versus Non-Linear Regression
DSamanta@IIT Kharagpur
116
Regression Analysis
Linear versus Non-Linear Regression
DSamanta@IIT Kharagpur
117
Regression Analysis
X | Y |
| |
| |
| |
| |
Multiple Non-Linear Regression
DSamanta@IIT Kharagpur
118
Regression Analysis
Issues with Multiple Non-Linear Regression
X | Y | Z |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Today’s Topics of Learning…
DSamanta@IIT Kharagpur
119
Regression Analysis
Auto-Regression Analysis
DSamanta@IIT Kharagpur
120
Regression Analysis
DSamanta@IIT Kharagpur
121
Regression Analysis
Introduction to
Time-Series Data
Time-series Data
DSamanta@IIT Kharagpur
122
Regression Analysis
Time-series data: The data collected on the same observational unit at multiple time periods
Example: Rate of price inflation
Time-series Data
Time-series Data
DSamanta@IIT Kharagpur
123
Regression Analysis
Examples of time-series data:
Use of Time-series Data
DSamanta@IIT Kharagpur
124
Regression Analysis
Use of time-series data
Modeling with Time-series Data
DSamanta@IIT Kharagpur
125
Regression Analysis
Modeling with Time-series Data: Example
DSamanta@IIT Kharagpur
126
Regression Analysis
Modeling with time-series data
DSamanta@IIT Kharagpur
127
Regression Analysis
Concept and Notations
Related Concepts and Notations
DSamanta@IIT Kharagpur
128
Regression Analysis
Related Concepts and Notations
DSamanta@IIT Kharagpur
129
Regression Analysis
Related Concepts and Notations
DSamanta@IIT Kharagpur
130
Regression Analysis
Autocorrelation coefficient
DSamanta@IIT Kharagpur
131
Regression Analysis
Autocorrelation
The correlation of a series with its own lagged values is called autocorrelation (also called serial correlation)
Covariance
DSamanta@IIT Kharagpur
132
Regression Analysis
Yt-j | . . . | Yt |
x1 |
| y1 |
x2 |
| y2 |
. . . |
| . . . |
xj |
| yj |
. |
| . |
. |
| . |
. |
| . |
xn |
| yn |
Example: Autocorrelation
DSamanta@IIT Kharagpur
133
Regression Analysis
Example
DSamanta@IIT Kharagpur
134
Regression Analysis
Auto-Regression Model
Auto-Regression Model
DSamanta@IIT Kharagpur
135
Regression Analysis
An autoregressive model (also called AR model) is used to model a future behavior for a time-ordered data, using data from past behaviors.
Definition
Auto-Regression Model for Forecasting
DSamanta@IIT Kharagpur
136
Regression Analysis
Definition
DSamanta@IIT Kharagpur
137
Regression Analysis
Computing AR Coefficients
DSamanta@IIT Kharagpur
138
Regression Analysis
Computing AR(p) model
Computing AR Coefficients
DSamanta@IIT Kharagpur
139
Regression Analysis
Computing AR (p): Yule-Walker Equations
Logistic Regression
DSamanta@IIT Kharagpur
140
Regression Analysis
DSamanta@IIT Kharagpur
141
Regression Analysis
Introduction
Regression Analysis and Logistic Regression
DSamanta@IIT Kharagpur
142
Regression Analysis
Regression Analysis and Logistic Regression
DSamanta@IIT Kharagpur
143
Regression Analysis
Note
Regression Analysis and Logistic Regression
DSamanta@IIT Kharagpur
144
Regression Analysis
A Regression model and Logistic Regression model
An Example
DSamanta@IIT Kharagpur
145
Regression Analysis
Hours (xi) | 0.50 | 0.75 | 1.00 | 1.25 | 1.50 | 1.75 | 1.75 | 2.00 | 2.25 | 2.50 | 2.75 | 3.00 | 3.25 | 3.50 | 4.00 | 4.25 | 4.50 | 4.75 | 5.00 | 5.50 |
Pass (yi) | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 1 | 1 | 1 | 1 | 1 |
Concept of Logistic Regression
DSamanta@IIT Kharagpur
146
Regression Analysis
Introduction
Concept of Logistic Regression
DSamanta@IIT Kharagpur
147
Regression Analysis
Introduction
1 0
Concept of Logistic Regression
DSamanta@IIT Kharagpur
148
Regression Analysis
What is logistic regression?
An Illustration
A sample is collected to examine the effect of toxic substance on tumor. A subject is examined for the toxic content in the body and then the presence (1) or absence (0) of tumors. The independent variable is the concentration of the toxic substance “Conc” . The number of subjects at each concentration (N) and the number having tumors “Tumor” is shown in the table.
Odds and ln(odds) are also included in the table.
DSamanta@IIT Kharagpur
149
Regression Analysis
Conc | N | Tumor | Odds | ln(odds) |
0.0 | 50 | 2 | 0.0417 | -3.18 |
2.1 | 54 | 5 | 0.1020 | -3.28 |
5.4 | 46 | 5 | 0.1220 | -2.10 |
8.0 | 51 | 10 | 0.2439 | -1.41 |
15.0 | 50 | 40 | 4.0000 | +1.39 |
19.5 | 52 | 42 | 4.2000 | +1.44 |
An Illustration
DSamanta@IIT Kharagpur
150
Regression Analysis
Conc | N | Tumor | Odds | ln(odds) |
0.0 | 50 | 2 | 0.0417 | -3.18 |
2.1 | 54 | 5 | 0.1020 | -3.28 |
5.4 | 46 | 5 | 0.1220 | -2.10 |
8.0 | 51 | 10 | 0.2439 | -1.41 |
15.0 | 50 | 40 | 4.0000 | +1.39 |
19.5 | 52 | 42 | 4.2000 | +1.44 |
An Illustration
DSamanta@IIT Kharagpur
151
Regression Analysis
Concept of Logistic Regression
DSamanta@IIT Kharagpur
152
Regression Analysis
Logit in Logistic Regression
Concept of Logistic Regression
DSamanta@IIT Kharagpur
153
Regression Analysis
Output of logistic function
Logistic Regression as Classifier
DSamanta@IIT Kharagpur
154
Regression Analysis
Logistic regression models the probabilities for classification problems with possible outcomes.
DSamanta@IIT Kharagpur
155
Regression Analysis
Logistic Regression Techniques
Types of Logistic Regression
DSamanta@IIT Kharagpur
156
Regression Analysis
Logistic regression
Binary logistic regression
One explanatory variable, two categories
Many explanatory variable, two categories
Multinomial logistic regression
Many explanatory variables, many categories
Types of Logistic Regression
DSamanta@IIT Kharagpur
157
Regression Analysis
X: Hours Study
Case 1: One explanatory variable, two categories
X1: Hours Study X2: 12th % Marks
Case 2: Many explanatory variable, two categories
X1: Hours Study X2: 12th % Marks X3: Age
Case 3: Many explanatory variable, many categories
Binary Logistic Regression
DSamanta@IIT Kharagpur
158
Regression Analysis
DSamanta@IIT Kharagpur
159
Regression Analysis
One explanatory variable,
two categories
One Explanatory Variable, Two Categories
DSamanta@IIT Kharagpur
160
Regression Analysis
A group of 20 students spends between 0 and 6 hours studying for an exam.
The table shows the number of hours each student spent studying, and whether they passed (1) or failed (0).
Hours (xi) | 0.50 | 0.75 | 1.00 | 1.25 | 1.50 | 1.75 | 1.75 | 2.00 | 2.25 | 2.50 | 2.75 | 3.00 | 3.25 | 3.50 | 4.00 | 4.25 | 4.50 | 4.75 | 5.00 | 5.50 |
Pass (yi) | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 1 | 1 | 1 | 1 | 1 |
How does the number of hours spent studying affect the probability of the student passing the exam?
One Explanatory Variable, Two Categories
DSamanta@IIT Kharagpur
161
Regression Analysis
Hours (xi) | 0.50 | 0.75 | 1.00 | 1.25 | 1.50 | 1.75 | 1.75 | 2.00 | 2.25 | 2.50 | 2.75 | 3.00 | 3.25 | 3.50 | 4.00 | 4.25 | 4.50 | 4.75 | 5.00 | 5.50 |
Pass (yi) | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 1 | 1 | 1 | 1 | 1 |
How does the number of hours spent studying affect the probability of the student passing the exam?
Note
One Explanatory Variable, Two Categories
DSamanta@IIT Kharagpur
162
Regression Analysis
Hours (xi) | 0.50 | 0.75 | 1.00 | 1.25 | 1.50 | 1.75 | 1.75 | 2.00 | 2.25 | 2.50 | 2.75 | 3.00 | 3.25 | 3.50 | 4.00 | 4.25 | 4.50 | 4.75 | 5.00 | 5.50 |
Pass (yi) | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 1 | 1 | 1 | 1 | 1 |
One Explanatory Variable, Two Categories
DSamanta@IIT Kharagpur
163
Regression Analysis
One Explanatory Variable, Two Categories
DSamanta@IIT Kharagpur
164
Regression Analysis
One Explanatory Variable, Two Categories
DSamanta@IIT Kharagpur
165
Regression Analysis
One Explanatory Variable, Two Categories
DSamanta@IIT Kharagpur
166
Regression Analysis
One Explanatory Variable, Two Categories
DSamanta@IIT Kharagpur
167
Regression Analysis
One Explanatory Variable, Two Categories
DSamanta@IIT Kharagpur
168
Regression Analysis
One Explanatory Variable, Two Categories
DSamanta@IIT Kharagpur
169
Regression Analysis
| Coefficient | Std. Error | z-value | p-value (Wald) |
Intercept (β0) | −4.0777 | 1.7610 | −2.316 | 0.0206 |
Slope (β1) | 1.5046 | 0.6287 | 2.393 | 0.0167 |
Hours (xi) | 0.50 | 0.75 | 1.00 | 1.25 | 1.50 | 1.75 | 1.75 | 2.00 | 2.25 | 2.50 | 2.75 | 3.00 | 3.25 | 3.50 | 4.00 | 4.25 | 4.50 | 4.75 | 5.00 | 5.50 |
Pass (yi) | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 1 | 1 | 1 | 1 | 1 |
One Explanatory Variable, Two Categories
DSamanta@IIT Kharagpur
170
Regression Analysis
| Coefficient | Std. Error | z-value | p-value (Wald) |
Intercept (β0) | −4.0777 | 1.7610 | −2.316 | 0.0206 |
Slope (β1) | 1.5046 | 0.6287 | 2.393 | 0.0167 |
One Explanatory Variable, Two Categories
DSamanta@IIT Kharagpur
171
Regression Analysis
Hours of study (x) | Passing exam | ||
Log-odds (t) | Odds (et) | Probability (p) | |
1 | −2.57 | 0.076 ≈ 1:13.1 | 0.07 |
2 | −1.07 | 0.34 ≈ 1:2.91 | 0.26 |
μ=2.71... | 0 | 1 | 0.5 |
3 | 0.44 | 1.55 | 0.61 |
4 | 1.94 | 6.96 | 0.87 |
5 | 3.45 | 31.4 | 0.97 |
One Explanatory Variable, Two Categories
DSamanta@IIT Kharagpur
172
Regression Analysis
DSamanta@IIT Kharagpur
173
Regression Analysis
Many explanatory variable,
two categories
Many Explanatory Variable, Two Categories
DSamanta@IIT Kharagpur
174
Regression Analysis
Many Explanatory Variable, Two Categories
DSamanta@IIT Kharagpur
175
Regression Analysis
Many Explanatory Variable, Two Categories
DSamanta@IIT Kharagpur
176
Regression Analysis
Many Explanatory Variable, Two Categories
DSamanta@IIT Kharagpur
177
Regression Analysis
Many Explanatory Variable, Two Categories
DSamanta@IIT Kharagpur
178
Regression Analysis
Many Explanatory Variable, Two Categories
DSamanta@IIT Kharagpur
179
Regression Analysis
DSamanta@IIT Kharagpur
180
Regression Analysis
Multinomial Logistic Regression
Multinomial Logistic Regression
DSamanta@IIT Kharagpur
181
Regression Analysis
Binary
logistic regression
One explanatory variable, two categories
Many explanatory variable, two categories
Multinomial
logistic regression
Logistic
Regression
Many explanatory variable, many categories
Many Explanatory Variable, Many Categories
DSamanta@IIT Kharagpur
182
Regression Analysis
Many Explanatory Variable, Many Categories
DSamanta@IIT Kharagpur
183
Regression Analysis
Many Explanatory Variable, Many Categories
DSamanta@IIT Kharagpur
184
Regression Analysis
Note :
Many Explanatory Variable, Many Categories
DSamanta@IIT Kharagpur
185
Regression Analysis
Many Explanatory Variable, Many Categories
DSamanta@IIT Kharagpur
186
Regression Analysis
Many Explanatory Variable, Many Categories
DSamanta@IIT Kharagpur
187
Regression Analysis
DSamanta@IIT Kharagpur
188
Regression Analysis
Applications of Logistic Regression
Applications of Logistic Regression
DSamanta@IIT Kharagpur
189
Regression Analysis
Applications of Logistic Regression
DSamanta@IIT Kharagpur
190
Regression Analysis
DSamanta@IIT Kharagpur
191
Regression Analysis
Problems to Ponder
Statement: In a study of urban planning in a country, a survey was taken of 50 cities; 24 used Happiness Index (HI) and 26 did not. One part of the study was to investigate the relationship between the presence or absence of HI and the median family income of the city(x). The data are given in Table 1, with median income in order of $1000s.
DSamanta@IIT Kharagpur
192
Regression Analysis
HI | x | HI | x | HI | x | HI | x |
0 | 9.2 | 0 | 10.5 | 1 | 9.6 | 1 | 12.5 |
0 | 9.2 | 0 | 10.5 | 1 | 10.1 | 1 | 12.6 |
0 | 9.3 | 0 | 10.9 | 1 | 10.3 | 1 | 12.6 |
0 | 9.4 | 0 | 11.0 | 1 | 10.9 | 1 | 12.6 |
0 | 9.5 | 0 | 11.2 | 1 | 10.9 | 1 | 12.9 |
0 | 9.5 | 0 | 11.2 | 1 | 11.1 | 1 | 12.9 |
0 | 9.5 | 0 | 11.5 | 1 | 11.1 | 1 | 12.9 |
0 | 9.6 | 0 | 11.7 | 1 | 11.1 | 1 | 12.9 |
0 | 9.7 | 0 | 11.8 | 1 | 11.5 | 1 | 13.1 |
0 | 9.7 | 0 | 12.1 | 1 | 11.8 | 1 | 13.2 |
0 | 9.8 | 0 | 12.3 | 1 | 11.9 | 1 | 13.5 |
0 | 9.8 | 0 | 12.5 | 1 | 12.1 | | |
0 | 9.9 | 0 | 12.9 | 1 | 12.2 | | |
Table 1: Data from Happiness Study
DSamanta@IIT Kharagpur
193
Regression Analysis
Statement: In a study of urban planning in Florida, a survey was taken of 50 cities; 24 used tax increment funding (TF) and 26 did not. One part of the study was to investigate the relationship between the presence or absence of TF and the median family income of the city(x). The data are given in the Table, with median income in order $1000s.
Income category | Income Category | Number of 0 | Number of 1 | Odds | ln(Odds)) |
| 9.5 | 13 | 1 | | -2.56395 |
| 10.5 | 3 | 4 | | 0.287432 |
| 11.5 | 6 | 6 | | 0 |
| 12.5 | 4 | 10 | | 0.916291 |
| 13.5 | 0 | 3 | | 1.386294 |
DSamanta@IIT Kharagpur
194
Regression Analysis
Income category | Mid-point of Income Category | NUMBER OF 0 | NUMBER OF 1 | ODDS | LN(ODDS) |
| 9.5 | 13 | 1 | | -2.56395 |
| 10.5 | 3 | 4 | | 0.287432 |
| 11.5 | 6 | 6 | | 0 |
| 12.5 | 4 | 10 | | 0.916291 |
| 13.5 | 0 | 3 | | 1.386294 |
DSamanta@IIT Kharagpur
195
Regression Analysis
Statement: Time Magazine (2006) used data from the USA to compare whites and blacks opinions of the death penalty. The data consisted of responses from 32,937 participants collected between 1972 and 1996. The outcome variable was whether the respondent did or did not support the death penalty. The survey provided a table of the percentage of whites and blacks each year that supported the death penalty.
DSamanta@IIT Kharagpur
196
Regression Analysis
Year | White (%) | Black (%) |
1972 | 57.4 | 28.8 |
1973 | 63.6 | 35.8 |
1974 | 66.3 | 36.3 |
1975 | 63.2 | 31.9 |
1976 | 67.5 | 41.1 |
1977 | 70 | 41.6 |
1978 | 69.4 | 43 |
1980 | 70.3 | 39.1 |
1982 | 76.9 | 48.4 |
1983 | 76.2 | 45 |
1984 | 74.5 | 43.5 |
1985 | 79 | 49.7 |
1986 | 75.3 | 42.7 |
Year | White (%) | Black (%) |
1987 | 73.7 | 42.9 |
1988 | 76 | 42.5 |
1989 | 76.5 | 56.1 |
1990 | 77.7 | 52.3 |
1991 | 71.4 | 42.7 |
1993 | 75.4 | 51.5 |
1994 | 78.3 | 50.7 |
1996 | 75.5 | 50.3 |
DSamanta@IIT Kharagpur
197
Regression Analysis
Year | White (%) | Black (%) |
1972 | 57.4 | 28.8 |
1973 | 63.6 | 35.8 |
1974 | 66.3 | 36.3 |
1975 | 63.2 | 31.9 |
1976 | 67.5 | 41.1 |
1977 | 70 | 41.6 |
1978 | 69.4 | 43 |
1980 | 70.3 | 39.1 |
1982 | 76.9 | 48.4 |
1983 | 76.2 | 45 |
1984 | 74.5 | 43.5 |
1985 | 79 | 49.7 |
1986 | 75.3 | 42.7 |
Year | White (%) | Black (%) |
1987 | 73.7 | 42.9 |
1988 | 76 | 42.5 |
1989 | 76.5 | 56.1 |
1990 | 77.7 | 52.3 |
1991 | 71.4 | 42.7 |
1993 | 75.4 | 51.5 |
1994 | 78.3 | 50.7 |
1996 | 75.5 | 50.3 |
Convert the percentages given in the table to the In(odds) within each race and year, and plot ln(odds) versus year. Comment on any patterns you see. If there is a trend in time, does it appear linear or quadratic?
DSamanta@IIT Kharagpur
198
Regression Analysis
Year | White (%) | Odds | ln(odds) |
1972 | 57.4 | 1.347418 | 0.29819005 |
1973 | 63.6 | 1.747253 | 0.558044696 |
1974 | 66.3 | 1.967359 | 0.67669206 |
1975 | 63.2 | 1.717391 | 0.540806456 |
1976 | 67.5 | 2.076923 | 0.730887509 |
1977 | 70 | 2.333333 | 0.84729786 |
1978 | 69.4 | 2.267974 | 0.818886859 |
1980 | 70.3 | 2.367003 | 0.861624753 |
1982 | 76.9 | 3.329004 | 1.202673259 |
1983 | 76.2 | 3.201681 | 1.163675882 |
1984 | 74.5 | 2.921569 | 1.072120673 |
1985 | 79 | 3.761905 | 1.324925415 |
1986 | 75.3 | 3.048583 | 1.114676891 |
Year | White (%) | Odds | ln(odds) |
1987 | 73.7 | 2.802281 | 1.03043386 |
1988 | 76 | 3.166667 | 1.15267951 |
1989 | 76.5 | 3.255319 | 1.18029032 |
1990 | 77.7 | 3.484305 | 1.248268579 |
1991 | 71.4 | 2.496503 | 0.914891152 |
1993 | 75.4 | 3.065041 | 1.120060832 |
1994 | 78.3 | 3.608295 | 1.283235342 |
1996 | 75.5 | 3.081633 | 1.125459539 |
DSamanta@IIT Kharagpur
199
Regression Analysis
DSamanta@IIT Kharagpur
200
Regression Analysis
Table
Year | Black (%) | Odds | ln(odds) |
1972 | 28.8 | 0.404494 | -0.90512 |
1973 | 35.8 | 0.557632 | -0.58406 |
1974 | 36.3 | 0.569859 | -0.56237 |
1975 | 31.9 | 0.468429 | -0.75837 |
1976 | 41.1 | 0.697793 | -0.35983 |
1977 | 41.6 | 0.712329 | -0.33922 |
1978 | 43 | 0.754386 | -0.28185 |
1980 | 39.1 | 0.642036 | -0.44311 |
1982 | 48.4 | 0.937984 | -0.06402 |
1983 | 45 | 0.818182 | -0.20067 |
1984 | 43.5 | 0.769912 | -0.26148 |
1985 | 49.7 | 0.988072 | -0.012 |
1986 | 42.7 | 0.745201 | -0.2941 |
Year | Black (%) | Odds | ln(odds) |
1987 | 42.9 | 0.751313 | -0.28593 |
1988 | 42.5 | 0.73913 | -0.30228 |
1989 | 56.1 | 1.277904 | 0.245221 |
1990 | 52.3 | 1.096436 | 0.092065 |
1991 | 42.7 | 0.745201 | -0.2941 |
1993 | 51.5 | 1.061856 | 0.060018 |
1994 | 50.7 | 1.028398 | 0.028002 |
1996 | 50.3 | 1.012072 | 0.012 |
DSamanta@IIT Kharagpur
201
Regression Analysis
DSamanta@IIT Kharagpur
202
Regression Analysis
REFERENCES
Reference
DSamanta@IIT Kharagpur
203
Regression Analysis
Web: https://en.wikipedia.org/wiki/Logistic_regression
Any question?
DSamanta@IIT Kharagpur
204
Regression Analysis
dsamanta@iitkgp.ac.in