Learning a logistic regression model
We will now use logistic regression to identify factors related to higher than average student alcohol consumption. You will also attempt to learn to identify (predict) students who consume high amounts of alcohol using background variables and school performance.
Because logistic regression can be used to classify observations into one of two groups (by giving the group probability) it is a binary classification method. You will meet more classification methods in the next chapter.
This exercise is part of the course
Helsinki Open Data Science
Exercise instructions
- Use
glm()
to fit a logistic regression model withhigh_use
as the target variable andfailures
andabsences
as the predictors. - Print out a summary of the model
- Add another explanatory variable to the model after absences: 'sex'. Repeat the above.
- Use
coef()
on the model object to print out the coefficients of the model
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# alc is available
# find the model with glm()
m <- glm(high_use ~ failures + absences, data = alc, family = "binomial")
# print out a summary of the model
# print out the coefficients of the model