require(mosaic)
## Loading required package: mosaic
## Loading required package: lattice
## Loading required package: grid
## Loading required package: survival
## Loading required package: splines
## Loading required package: Hmisc
## Hmisc library by Frank E Harrell Jr
##
## Type library(help='Hmisc'), ?Overview, or ?Hmisc.Overview') to see overall
## documentation.
##
## NOTE:Hmisc no longer redefines [.factor to drop unused levels when
## subsetting. To get the old behavior of Hmisc type dropUnusedLevels().
## Attaching package: 'Hmisc'
## The following object(s) are masked from 'package:survival':
##
## untangle.specials
## The following object(s) are masked from 'package:base':
##
## format.pval, round.POSIXt, trunc.POSIXt, units
## Attaching package: 'mosaic'
## The following object(s) are masked from 'package:Hmisc':
##
## do
## The following object(s) are masked from 'package:stats':
##
## binom.test, D, median, prop.test, sd, var
## The following object(s) are masked from 'package:base':
##
## max, mean, min, print, sample
file1 = "Group-A Unemployment Updated.csv"
emp = read.csv(file1)
emp10 = subset(emp, Year == 2011)
emp11 = subset(emp, Year == 2010)
y = ifelse(emp11$Empstat == "employed", 1, 0)
mod1b = glm(y ~ Age + Educ, data = emp11, family = "binomial")
summary(mod1b)
##
## Call:
## glm(formula = y ~ Age + Educ, family = "binomial", data = emp11)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -3.228 0.237 0.312 0.402 0.771
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 1.85483 0.06417 28.91 < 2e-16 ***
## Age 0.03094 0.00106 29.14 < 2e-16 ***
## Educba 0.26593 0.06302 4.22 2.4e-05 ***
## Educcollege -0.24001 0.05861 -4.09 4.2e-05 ***
## Educdoctorate 1.33303 0.26439 5.04 4.6e-07 ***
## Educhsgrad -0.64698 0.05419 -11.94 < 2e-16 ***
## Educjrhigh -0.94833 0.10275 -9.23 < 2e-16 ***
## Educma 0.67828 0.09522 7.12 1.1e-12 ***
## Educnone -1.28831 0.22306 -5.78 7.7e-09 ***
## Educprimary -0.96123 0.09265 -10.37 < 2e-16 ***
## Educprof 0.87394 0.20788 4.20 2.6e-05 ***
## Educsomehs -1.05591 0.05994 -17.62 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 46602 on 98757 degrees of freedom
## Residual deviance: 43781 on 98746 degrees of freedom
## AIC: 43805
##
## Number of Fisher Scoring iterations: 7
anova(mod1b, test = "Chisq")
## Analysis of Deviance Table
##
## Model: binomial, link: logit
##
## Response: y
##
## Terms added sequentially (first to last)
##
##
## Df Deviance Resid. Df Resid. Dev Pr(>Chi)
## NULL 98757 46602
## Age 1 1456 98756 45146 <2e-16 ***
## Educ 10 1365 98746 43781 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
plotPoints(jitter(y) ~ Age, data = emp11, col = "gray")
fit.empstat = makeFun(mod1b)
plotFun(fit.empstat(Age = x, Educ = "none") ~ x, add = TRUE, col = "dark red")
plotFun(fit.empstat(Age = x, Educ = "primary") ~ x, add = TRUE, col = "red")
plotFun(fit.empstat(Age = x, Educ = "jrhigh") ~ x, add = TRUE, col = "orange")
plotFun(fit.empstat(Age = x, Educ = "somehs") ~ x, add = TRUE, col = "gold")
plotFun(fit.empstat(Age = x, Educ = "hsgrad") ~ x, add = TRUE, col = "yellow")
plotFun(fit.empstat(Age = x, Educ = "college") ~ x, add = TRUE, col = "light green")
plotFun(fit.empstat(Age = x, Educ = "prof") ~ x, add = TRUE, col = "dark green")
plotFun(fit.empstat(Age = x, Educ = "assoc") ~ x, add = TRUE, col = "light blue")
plotFun(fit.empstat(Age = x, Educ = "ba") ~ x, add = TRUE, col = "dark blue")
plotFun(fit.empstat(Age = x, Educ = "ma") ~ x, add = TRUE, col = "purple")
plotFun(fit.empstat(Age = x, Educ = "doctorate") ~ x, add = TRUE, col = "magenta")