Model validation

Building Response Models in R

Kathrin Gruber

Assistant Professor of Econometrics Erasmus University Rotterdam

Subsetting

train.data <- subset(choice.data, subset = LASTPURCHASE == 0)
test.data <- subset(choice.data, subset = LASTPURCHASE == 1)
dim(train.data)
2498   14
dim(test.data)
300  14
Building Response Models in R

Model training

train.model <- glm(HOPPINESS ~ price.ratio + FEAT.HOP + FEATDISPL.HOP, 
                   family = binomial, data = train.data)
margins(train.model)
price.ratio FEAT.HOP FEATDISPL.HOP
    -0.4703  0.05769        0.1067

Comparing the results

coef(extended.mod)
 price.ratio DISPL.HOP FEAT.HOP FEATDISPL.HOP
    -0.4471  0.009486  0.04973        0.1086
Building Response Models in R

Out-of-sample testing

prob <- predict(train.model, test.data, type = "response")

predicted <- ifelse(prob >= 0.5, 1, 0) observed <- test.data$HOPPINESS
table(predicted, observed)/300
         observed
predicted        0        1
        0 0.923333 0.063333
        1 0.006667 0.006667
Building Response Models in R

Let's practice!

Building Response Models in R

Preparing Video For Download...