Hi there!
We have discussed about Linear and Multiple linear regressions in the previous post. Today we will discuss about the Logistic regression.
The Logistic Regression is a regression model in which the response variable (dependent variable) has categorical values such as
The general mathematical equation for logistic regression is:
y is the response variable.
x is the predictor variable.
a and b are the coefficients which are numeric constants.
We use the glm() function to create the regression model and get its summary for analysis.
Here is the syntax of the glm() function.
We have discussed about Linear and Multiple linear regressions in the previous post. Today we will discuss about the Logistic regression.
The Logistic Regression is a regression model in which the response variable (dependent variable) has categorical values such as
True/False
or 0/1
. It actually measures the probability of a binary response as the
value of response variable based on the mathematical equation relating
it with the predictor variables.The general mathematical equation for logistic regression is:
y = 1/(1+e^-(a+b1x1+b2x2+b3x3+...))
y is the response variable.
x is the predictor variable.
a and b are the coefficients which are numeric constants.
We use the glm() function to create the regression model and get its summary for analysis.
Here is the syntax of the glm() function.
glm(formula,data,family)
Let us consider one example. Here, we will use an rStudio inbuilt data set called as mtcars.
input <- mtcars[,c("am","cyl","hp","wt")] am.data = glm(formula = am ~ cyl + hp + wt, data = input, family = binomial) print(summary(am.data))
Output:
Call:
glm(formula = am ~ cyl + hp + wt, family = binomial, data = input)
Deviance Residuals:
Min 1Q Median 3Q Max
-2.17272 -0.14907 -0.01464 0.14116 1.27641
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 19.70288 8.11637 2.428 0.0152 *
cyl 0.48760 1.07162 0.455 0.6491
hp 0.03259 0.01886 1.728 0.0840 .
wt -9.14947 4.15332 -2.203 0.0276 *
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
(Dispersion parameter for binomial family taken to be 1)
Null deviance: 43.2297 on 31 degrees of freedom
Residual deviance: 9.8415 on 28 degrees of freedom
AIC: 17.841
Number of Fisher Scoring iterations: 8
Let us analyze the output:
- Call section reminds us the formula we used.
- Deviance residuals are a measure of model fit. This part of output shows the distribution of the deviance residuals for individual cases used in the model.
- The next part of the output shows the coefficients, their standard errors, the z-statistic (sometimes called a Wald z-statistic), and the associated p-values.
- The Akaike information criterion (AIC) is a measure of the relative
quality of a statistical model for a given set of data. As such, AIC
provides a means for model selection.
AIC deals with the trade-off between the goodness of fit of the model and the complexity of the model. It is founded on information theory: it offers a relative estimate of the information lost when a given model is used to represent the process that generates the data. - Null deviance shows how well the response variable is predicted by a model that includes only the intercept.
- Residual deviance shows the degree of freedom after the addition of independent variables.
- Fisher scoring iterations has to do with how the model was estimated. A linear model can be fit by solving closed form equations. Unfortunately, that cannot be done with logistic regression. Instead, an iterative approach (the Newton-Raphson algorithm by default) is used. Loosely, the model is fit based on a guess about what the estimates might be. The algorithm then looks around to see if the fit would be improved by using different estimates instead. If so, it moves in that direction (say, using a higher value for the estimate) and then fits the model again. The algorithm stops when it doesn't perceive that moving again would yield much additional improvement. This line tells you how many iterations there were before the process stopped and output the results.
This is great, thanks for the share. Also, check this out if you are looking for professional website or logo design services:
ReplyDeleteBuy Logo