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:
- First, we examine the first six elements of
vs
withinmtcars
:> head(mtcars$vs) [1] 0 0 1 1 0 1
- We apply the
glm
function withbinomial
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.