library(MASS)
##
## Attaching package: 'MASS'
## The following object is masked from 'package:dplyr':
##
## select
# Specify a null model with no predictors
null_model <- glm(donated ~ 1, data = donors, family = "binomial")
# Specify the full model using all of the potential predictors
full_model <- glm(donated ~ . , data = donors, family = "binomial")
# Stepwise regression model
step_model <- step(null_model,
direction = "both",
scope = list(upper = full_model,
lower = null_model),
trace = 0)
## Warning in add1.glm(fit, scope$add, scale = scale, trace = trace, k = k, :
## using the 70916/93462 rows from a combined fit
## Warning in add1.glm(fit, scope$add, scale = scale, trace = trace, k = k, :
## using the 70916/93462 rows from a combined fit
## Warning in add1.glm(fit, scope$add, scale = scale, trace = trace, k = k, :
## using the 70916/93462 rows from a combined fit
## Warning in add1.glm(fit, scope$add, scale = scale, trace = trace, k = k, :
## using the 70916/93462 rows from a combined fit
## Warning in add1.glm(fit, scope$add, scale = scale, trace = trace, k = k, :
## using the 70916/93462 rows from a combined fit
## Warning in add1.glm(fit, scope$add, scale = scale, trace = trace, k = k, :
## using the 70916/93462 rows from a combined fit
summary(step_model)
##
## Call:
## glm(formula = donated ~ frequency + money + wealth_rating + has_children +
## pet_owner, family = "binomial", data = donors)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -0.4023 -0.3625 -0.2988 -0.2847 2.7328
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -3.05529 0.04556 -67.058 < 2e-16 ***
## frequencyINFREQUENT -0.49649 0.03100 -16.017 < 2e-16 ***
## moneyMEDIUM 0.36594 0.04301 8.508 < 2e-16 ***
## wealth_rating 0.03294 0.01238 2.660 0.007805 **
## has_children -0.15820 0.04707 -3.361 0.000777 ***
## pet_owner 0.11712 0.04096 2.860 0.004243 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 37330 on 93461 degrees of freedom
## Residual deviance: 36920 on 93456 degrees of freedom
## AIC: 36932
##
## Number of Fisher Scoring iterations: 6