Building Response Models in R
Kathrin Gruber
Assistant Professor of Econometrics Erasmus University Rotterdam
summary(choice.data[c("FEAT.HOP","DISPL.HOP","FEATDISPL.HOP")])
FEAT.HOP DISPL.HOP FEATDISPL.HOP
Min. :0.00000 Min. :0.00000 Min. :0.000000
1st Qu.:0.00000 1st Qu.:0.00000 1st Qu.:0.000000
Median :0.00000 Median :0.00000 Median :0.000000
Mean :0.03645 Mean :0.03538 Mean :0.009292
3rd Qu.:0.00000 3rd Qu.:0.00000 3rd Qu.:0.000000
Max. :1.00000 Max. :1.00000 Max. :1.000000
extended.model <- glm(HOPPINESS ~ price.ratio +
DISPL.HOP + FEAT.HOP + FEATDISPL.HOP,
family = binomial, data = choice.data)
margins(extended.model)
price.ratio DISPL.HOP FEAT.HOP FEATDISPL.HOP
-0.4471 0.009486 0.04973 0.1086
extended.model <- glm(HOPPINESS ~ price.ratio +
DISPL.HOP + FEAT.HOP + FEATDISPL.HOP,
family = binomial, data = choice.data)
summary(extended.model)
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -3.6250 0.1447 -25.053 < 2e-16 ***
price.ratio -6.6663 0.4127 -16.154 < 2e-16 ***
DISPL.HOP 0.1415 0.2599 0.544 0.586204
FEAT.HOP 0.7415 0.3780 1.962 0.049806 *
FEATDISPL.HOP 1.6189 0.4789 3.381 0.000723 ***
Null deviance: 1820.0 on 2797 degrees of freedom
Residual deviance: 1275.8 on 2793 degrees of freedom
AIC: 1285.8
null.model <- glm(HOPPINESS ~ 1, family = binomial, data = choice.data)
anova(extended.model, null.model, test = "Chisq")
Analysis of Deviance Table
Model 1: HOPPINESS ~ 1
Model 2: HOPPINESS ~ price.ratio + DISPL.HOP + FEAT.HOP + FEATDISPL.HOP
Resid. Df Resid. Dev Df Deviance Pr(>Chi)
1 2797 1820.0
2 2793 1275.8 4 544.23 < 2.2e-16 ***
final.model <- stepAIC(extended.model, direction = "backward", trace = FALSE)
summary(final.model)
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -3.6268 0.1450 -25.018 < 2e-16 ***
price.ratio -6.7167 0.4033 -16.655 < 2e-16 ***
FEAT.HOP 0.7327 0.3780 1.938 0.052577 .
FEATDISPL.HOP 1.6041 0.4789 3.349 0.000811 ***
Null deviance: 1820.0 on 2797 degrees of freedom
Residual deviance: 1276.1 on 2794 degrees of freedom
AIC: 1284.1
Building Response Models in R