I am trying to build a binomial logistic regression model. I firstly build the equation, then applied stepwise method to choose the best variables. In the end I am trying to use the function logistic.display to get the coefficients and odds ratio because I want to demonstrate to effect of the variables on the model. when I run the logistic.display function I get error "$ operator is invalid for atomic vectors". Can anyone help? Thank you
model <- glm(decision ~., data = train.data,family = "binomial")
step.model <- stepAIC(model, direction = "both",
trace = FALSE)
logistic.display(step.model)
summary(step.model)
Call:
glm(formula = decision ~ Exposure + VehAge + BonusMalus, family = "binomial",
data = train.data)
Deviance Residuals:
Min 1Q Median 3Q Max
-0.6911 -0.3210 -0.2710 -0.2261 2.9227
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -4.66465 0.81457 -5.727 1.03e-08 ***
Exposure 1.16920 0.54048 2.163 0.0305 *
VehAge -0.05930 0.03710 -1.599 0.1099
BonusMalus 0.01961 0.01008 1.946 0.0517 .
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
(Dispersion parameter for binomial family taken to be 1)
Null deviance: 275.12 on 800 degrees of freedom
Residual deviance: 267.24 on 797 degrees of freedom
AIC: 275.24
Number of Fisher Scoring iterations: 6
class(step.model)
[1] "glm" "lm"
This is a sample of my train.data
structure(list(id = c(1, 3, 5, 10, 11, 13, 15, 17, 18, 21),
var1 = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), var2 = c(0.1,
0.77, 0.75, 0.09, 0.84, 0.52, 0.45, 0.27, 0.71, 0.15), var3 = c("D",
"D", "B", "B", "B", "E", "E", "C", "C", "B"), var4 = c(5L,
5L, 6L, 7L, 7L, 6L, 6L, 7L, 7L, 7L), var5 = c(0L, 0L, 2L,
0L, 0L, 2L, 2L, 0L, 0L, 0L), var6 = c(55L, 55L, 52L, 46L,
46L, 38L, 38L, 33L, 33L, 41L), var7 = c(50L, 50L, 50L,
50L, 50L, 50L, 50L, 68L, 68L, 50L), var8 = c("B12", "B12",
"B12", "B12", "B12", "B12", "B12", "B12", "B12", "B12"),
var9 = c("Regular", "Regular", "Diesel", "Diesel", "Diesel",
"Regular", "Regular", "Diesel", "Diesel", "Diesel"), var10 = c(1217L,
1217L, 54L, 76L, 76L, 3003L, 3003L, 137L, 137L, 60L), var11 = c("R82",
"R82", "R22", "R72", "R72", "R31", "R31", "R91", "R91", "R52"
), decision = c(1, 1, 1, 1, 0, 1, 1, 0, 1, 1)), row.names = c(NA,
10L), class = "data.frame")