R Logistic Regression - R Programming language

What is R Logistic Regression?

Logistic Regression in R is a regression model in which the response variable (dependent variable) has categorical values such as True/False or 0/1. It measures the probability of a binary response as the value of response variable based on the mathematical equation relating it with the predictor variables.

General mathematical equation for logistic regression is

Below is the description of the parameters used

  • y is the response variable.
  • x is the predictor variable.
  • a and b are the coefficients which are numeric constants.

glm() function is used for creating the regression model.

Syntax

Basic syntax for glm() function in logistic regression is

Below is the description of the parameters used

  • formula is the symbol which represents the relationship between the variables.
  • data is the data set which gives values of these variables.
  • family is R object used for specifying the details of the model. Its value is binomial for logistic regression.

Example

In-built data set "mtcars" will describe various models of a car with various engine specifications. In "mtcars" data set, transmission mode (automatic or manual) will be described by the column “am” which is a binary value (0 or 1). Logistic regression model can be created between the columns "am" and 3 other columns - hp, wt and cyl.

When above code is executed, it produces following result

Create Regression Model

glm() function is used for creating the regression model and get its summary for analysis.

When above code is executed, it produces following result

Conclusion

As p-value in the last column is more than 0.05 for the variables "cyl" and "hp", these will be considered to be insignificant in contributing to the value of the variable "am". Only weight (wt) impacts the "am" value in this regression model.

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

R Programming language Topics