In order to build a logistic regression in R, we generally use the glm
function, which is nothing but a generalized linear model on the binary dependent variable. In the following section, you will learn to build the model to predict if the life expectancy for a country is more than 70 based on the other parameters, which we call the independent variables. These independent variables can either be continuous or categorical:
model<- glm(as.factor(life_expectancy_morethan_70)~., traindata, family=binomial(link = "logit"))
In the preceding glm
function, the first parameter that we pass is the dependent variable column that has to be predicted for the dataset. We will predict the life_expectancy_morethan_70
column and the dot followed by the ~
symbol represents that we are considering all the others variables present in the dataset as independent variables. The next parameter that we mentioned is the name of the dataset and, in this case, the traindata
data frame is the...