Applying the Binomial model for generalized linear regression

For a binary dependent variable, one may apply a binomial model as the family object in the glm function.

Getting ready

The prerequisite of this task is to prepare a binary dependent variable. Here, we use the vs variable (V engine or straight engine) as the dependent variable.

How to do it...

Perform the following steps to fit a generalized linear regression model with the Binomial model:

  1. First, we examine the first six elements of vs within mtcars:
    > head(mtcars$vs)
    [1] 0 0 1 1 0 1
    
  2. We apply the glm function with binomial as the family object:
    > lm1 = glm(vs ~ hp+mpg+gear,data=mtcars, family=binomial)
    > summary(lm1)
    
    Call:
    glm(formula = vs ~ hp + mpg + gear, family = binomial, data = mtcars) ...

Get R: Recipes for Analysis, Visualization and Machine Learning now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.