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.
mort_5_yr sex edu marital variable value
1: 1 female lths married h0 0.02707522
2: 2 female lths married h0 0.02707522
3: 3 female lths married h0 0.02707522
4: 4 female lths married h0 0.02707522
5: 5 female lths married h0 0.02707522
6: 6 female lths married h0 0.02707522
7: 7 female lths married h0 0.02707522
8: 8 female lths married h0 0.02707522
9: 9 female lths married h0 0.02707522
10: 10 female lths married h0 0.02707522
11: 11 female lths married h0 0.02707522
12: 12 female lths married h0 0.02707522
13: 13 female lths married h0 0.02707522
14: 14 female lths married h0 0.02707522
15: 15 female lths married h0 0.02707522
16: 16 female lths married h0 0.02707522
17: 17 female lths married h0 0.02707522
18: 18 female lths married h0 0.02707522
19: 1 male lths married h0 0.03170243
20: 2 male lths married h0 0.03170243
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=marital, color=marital) )+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 level, specifically a bachelor’s degree and marital status, all Model Fits indicate that individuals who have never been married have a higher risk hazard for mortality when compared to individuals who have been married, divorced, widowed, or separated.
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
282974.3
60924.043
general
222050.3
0.000
linear
226581.4
4531.148
poly 2
226524.5
4474.211
spline
226558.8
4508.487
None of the models are close to the AIC for the general model for this analysis.