Introduction¶
Logistic regression is used to model a target that reports the presence (often mapped to the value one) or absence (often mapped to the value zero) of a phenomena.
Data setup¶
Compared to multivariate linear regression, we assume an identical setup for the data except for one change. Assume that we collect observations with pieces of information and a target of interest . Then we may describe our dataset with observations as
The key difference between the data for linear regression and the data for logistic regression is that for linear regression the target variable is assumed to take any negative or positive values. However, for logistic regression we assume the only two options for are 0 or 1.
Modeling the target¶
Because the target takes the value 0 or 1 a natural choice to model this target is the Bernoulli distribution. That is, we start by assuming that the random variables that generate observations follow a Bernoulli distribution.
A function to constrain the parameter space¶
Undefined control sequence: \Bernoulli at position 32: … Y_{i} \sim \̲B̲e̲r̲n̲o̲u̲l̲l̲i̲( \theta(x_{i})…
\begin{aligned}
Y_{i} \sim \Bernoulli( \theta(x_{i}) ) \\
\theta(x_{i}) = \frac{ e^{ \beta_{0} + \sum_{k=1}^{p} \beta_{k}x_{i,k} } }{1 + e^{ \beta_{0} + \sum_{k=1}^{p} \beta_{k}x_{i,k}}
\end{aligned}The parameter determines the probability that we assign to a one (and so then also a zero). To allow covariates to change the probability that we can change from a constant, , to a function that depends on , .
A first choice for the function above may be the same as linear regression
However, because is the probability assigned to the function needs to be confined in the interval . The function above is not limited to the interval [0,1] and so we need to find a new function that guarantees that is between 0 and 1.
The full model¶
One unit change¶
Log odds and odds ratio¶
Decision boundaries¶
Homework¶
Consider the following logistic regression model $$\begin{aligned} Y_{i} & \sim Bern[\theta(x_{i})] \ \theta(x) &= e^{\beta_{0} + \beta_{1}x_{i}} \Big / (1+e^{\beta_{0} + \beta_{1}x_{i}})
\end{aligned}$kx$,
Suppose you find estimates and for the following logistic regression model $$\begin{aligned} Y_{i} & \sim Bern[\theta(x_{i})] \ \theta(x) &= e^{\beta_{0} + \beta_{1}x_{i}} \Big / (1+e^{\beta_{0} + \beta_{1}x_{i}})
\end{aligned}$$
What does the model assume is the probability of obtaining when (i.e. )?
What does the model assume is the probability of obtaining when (i.e. )?
What does the model assume is the probability of obtaining when (i.e. )?
What does the model assume is the probability of obtaining when (i.e. )?
Why is the change in the probability of a one from to ( i.e. ) different compared to the change in the probability of a one from to ( )?
Suppose the following model $$\begin{aligned} Y_{i} & \sim Bern[\theta(x_{i})] \ \theta(x) &= e^{\beta_{0} + \beta_{1}x_{i,1} +\beta_{2}x_{i,2} } \Big / (1+e^{\beta_{0} + \beta_{1}x_{i}})
\end{aligned}$$
Please write down the conditional expected value for ,
Please write down the conditional variance for ,
You are asked to build a model to summarize the association between diabetes type II status (the target) and three covariates: age, in years, sex (Male/Female), and fasting glucose level (mg/dL) for patients at a local hospital.
The dataset contains observations on 1000 patients. You build a model $$\begin{aligned} \log \left[\frac{\theta(x)}{\theta(1-x)}\right] = \beta_{0} + \beta_{1} x_{i,1} + \beta_{2}x_{i,2} + \beta_{3}x_{i,3}\end{aligned}$x_{i,1}x_{i,2}x_{i,3}$ is fasting glucose level.
When you estimate the parameters you find that
-0.5 1.2 -0.9 -0.75
Convert the above estimates to odds ratios
Please interpret a one unit change in age, sex, and fasting glucose level.
Write down the equation that describes a decision boundary if we assign a 1 when the probability of a 1 is greater than 0.50 and a 0 otherwise.