1.Fit the discrete time hazard model to your outcome
a)You must form a person-period data set
b)Consider both the general model and other time specifications
c)Include all main effects in the model
d)Test for an interaction between at least two of the predictors e)Generate hazard plots for interesting cases highlighting the significant predictors in your analysis
Loading required package: carData
Attaching package: 'car'
The following object is masked from 'package:dplyr':
recode
The following object is masked from 'package:purrr':
some
library(survey)
Loading required package: grid
Loading required package: Matrix
Attaching package: 'Matrix'
The following objects are masked from 'package:tidyr':
expand, pack, unpack
Attaching package: 'survey'
The following object is masked from 'package:graphics':
dotchart
Use of data from IPUMS NHIS is subject to conditions including that users
should cite the data appropriately. Use command `ipums_conditions()` for more
details.
library(ggplot2)fin%>%dplyr::filter(edu =="bachelors")%>%dplyr::mutate(mod = dplyr::case_when(.$variable =="h0"~"Constant",.$variable =="h1"~"General",.$variable =="h2"~"Linear",.$variable =="h3"~"Polynomial - 2",.$variable =="h4"~"Spline"))%>%ggplot(aes(x = mort_5_yr*5, y=value ))+geom_line(aes(group=race, color=race) )+labs(title ="Hazard function for adult mortality",subtitle ="Alternative model specifications")+xlab("Age")+ylab("S(t)")+facet_wrap(~mod, scales="free_y")
Don't know how to automatically pick scale for object of type svystat. Defaulting to continuous.
When looking at adult mortality hazard based on education, specifically individuals with a Bachelor’s degree, the risk hazard is higher for the non-Hispanic Blacks compared to all alternative models .
Model Fits
AICc<-AIC(constant)
Warning in eval(family$initialize): non-integer #successes in a binomial glm!
AICg<-AIC(general)
Warning in eval(family$initialize): non-integer #successes in a binomial glm!
AICl<-AIC(linear)
Warning in eval(family$initialize): non-integer #successes in a binomial glm!
AICq<-AIC(quad)
Warning in eval(family$initialize): non-integer #successes in a binomial glm!
AICs<-AIC(spline)
Warning in eval(family$initialize): non-integer #successes in a binomial glm!
AICS$deltaAIC<-AICS$AIC - AICS$AIC[AICS$mod=="general"]knitr::kable(AICS[, c("mod", "AIC", "deltaAIC")],caption ="Relative AIC for alternative time specifications")
Relative AIC for alternative time specifications
mod
AIC
deltaAIC
const
283941.9
58666.495
general
225275.4
0.000
linear
229828.3
4552.898
poly 2
229739.2
4463.819
spline
229780.8
4505.426
None of the models are close to the AIC for the general model for this analysis.