Import the Data
library(haven)
ex8 <- read_sav("~/Downloads/BinaryLogistic(1)/BinarayLogistic_1.sav")
View(ex8)
summary(ex8)
## income age takeoffer Mortgage
## Min. : 29.0 Min. :23.00 Min. :0.0000 Min. :1500
## 1st Qu.: 47.0 1st Qu.:28.00 1st Qu.:0.0000 1st Qu.:1825
## Median : 66.5 Median :36.00 Median :1.0000 Median :2100
## Mean : 72.9 Mean :37.67 Mean :0.5333 Mean :2180
## 3rd Qu.: 95.0 3rd Qu.:46.00 3rd Qu.:1.0000 3rd Qu.:2400
## Max. :132.0 Max. :58.00 Max. :1.0000 Max. :3400
## Famsize
## Min. :1.000
## 1st Qu.:2.000
## Median :3.500
## Mean :3.533
## 3rd Qu.:4.750
## Max. :6.000
sapply(ex8,sd)
## income age takeoffer Mortgage Famsize
## 29.6803081 11.1613043 0.5074163 498.5496205 1.4076964
table(ex8$takeoffer)
##
## 0 1
## 14 16
Build Model
mylogit <- glm(takeoffer ~ income + age + Mortgage + Famsize, data = ex8, family = "binomial")
# Check the result of our model
summary(mylogit)
##
## Call:
## glm(formula = takeoffer ~ income + age + Mortgage + Famsize,
## family = "binomial", data = ex8)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -1.57085 -0.12621 0.00036 0.01230 1.68149
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -18.188144 12.929281 -1.407 0.160
## income 0.153373 0.160029 0.958 0.338
## age 0.290390 0.290690 0.999 0.318
## Mortgage -0.002944 0.005660 -0.520 0.603
## Famsize 1.386365 1.555548 0.891 0.373
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 41.455 on 29 degrees of freedom
## Residual deviance: 8.576 on 25 degrees of freedom
## AIC: 18.576
##
## Number of Fisher Scoring iterations: 9
exp(coef(mylogit))
## (Intercept) income age Mortgage Famsize
## 1.261797e-08 1.165759e+00 1.336949e+00 9.970607e-01 4.000284e+00
exp(cbind(OR = coef(mylogit), confint(mylogit)))
## Waiting for profiling to be done...
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## OR 2.5 % 97.5 %
## (Intercept) 1.261797e-08 1.216005e-31 0.2899164
## income 1.165759e+00 9.529639e-01 2.2434446
## age 1.336949e+00 8.009804e-01 3.4872683
## Mortgage 9.970607e-01 9.790670e-01 1.0071567
## Famsize 4.000284e+00 1.861503e-01 314.6465950
with(mylogit, null.deviance - deviance)
## [1] 32.87941
with(mylogit, df.null - df.residual)
## [1] 4
with(mylogit, pchisq(null.deviance - deviance, df.null - df.residual, lower.tail = FALSE))
## [1] 1.264347e-06