Simple Logistic Regression using R

 

Also using the modified mpg data file with new variable cyl_two, which is defined as = 1 if cyl >= 6 or = 0 if cyl < 6.

> # Define cyl_two variable
> mpg$cyl_two <- NA
> mpg[which(mpg$cyl >= 6), ]$cyl_two <- 1
> mpg[which(mpg$cyl < 6), ]$cyl_two <- 0
> attach(mpg)
> summary(glm(cyl_two ~ hwy, family = binomial))

Call:
glm(formula = cyl_two ~ hwy, family = binomial)

Deviance Residuals: 
 Min 1Q Median 3Q Max 
-2.5586 -0.5733 0.1252 0.4671 1.8883

Coefficients:
 Estimate Std. Error z value Pr(>|z|) 
(Intercept) 13.97529 2.04014 6.850 7.38e-12 ***
hwy -0.53703 0.07838 -6.852 7.28e-12 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 306.66 on 233 degrees of freedom
Residual deviance: 156.75 on 232 degrees of freedom
AIC: 160.75

Number of Fisher Scoring iterations: 6

 

 

See Also:

Do the same test in SAS

Leave a Reply

Your email address will not be published. Required fields are marked *