knitr::opts_chunk$set(echo = TRUE)
require(Sleuth3)
require(tigerstats)
Getting the data:
lines <-
"NEWCAR INCOME CAR.AGE
0 32 3
0 45 2
1 60 2
0 53 1
0 25 4
1 68 1
1 82 2
1 38 5
0 67 2
1 92 2
1 72 3
0 21 5
0 26 3
1 40 4
0 33 3
0 45 1
1 61 2
0 16 3
1 18 4
0 22 6
0 27 3
1 35 3
1 40 3
0 10 4
0 24 3
1 15 4
0 23 3
0 19 5
1 22 2
0 61 2
0 21 3
1 32 5
0 17 1"
con <- textConnection(lines)
newcars <- read.csv(con, sep="")
fit <- glm(NEWCAR ~ INCOME + CAR.AGE, family=binomial(link="logit"), data=newcars)
summary(fit)
##
## Call:
## glm(formula = NEWCAR ~ INCOME + CAR.AGE, family = binomial(link = "logit"),
## data = newcars)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -1.6189 -0.8949 -0.5880 0.9653 2.0846
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -4.73931 2.10195 -2.255 0.0242 *
## INCOME 0.06773 0.02806 2.414 0.0158 *
## CAR.AGE 0.59863 0.39007 1.535 0.1249
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 44.987 on 32 degrees of freedom
## Residual deviance: 36.690 on 30 degrees of freedom
## AIC: 42.69
##
## Number of Fisher Scoring iterations: 4
Coefficients:
exp(fit$coefficients)
## (Intercept) INCOME CAR.AGE
## 0.008744682 1.070079093 1.819627221