For a binary dependent variable, one may apply a binomial model as the family object in the glm
function.
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.
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) Output: [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) Output: Call: glm(formula = vs ~ hp + mpg + gear, family = binomial, data = mtcars) Deviance Residuals: Min 1Q Median 3Q Max -1.68166 -0.23743 -0.00945 0.30884 1.55688 Coefficients...