Question: write a code in r that runs model diagnostics for the following gjrm model #loading libraries library ( haven ) library ( tidyverse ) library
write a code in r that runs model diagnostics for the following gjrm model
#loading libraries
libraryhaven
librarytidyverse
libraryGJRM
librarygt
librarygtsummary
librarylabelled
librarymice
# loading main dhs dataset
MWIRAFL readdtaMWDHSMWIRADTMWIRAFL.DTA"
#attaching the dataset for variable easy access
attachMWIRAFL
MWIRAFL$v
# Creating dataset for the analysis by extracting necessary variable from dhs dataset
mydata data.frameageatmarrigev yearssincemarriagev
respondentagev maritalstatus v
# for the variable age at marriage, we replace with respondents age for unmarried
# the difference will be captured by the censoring indicator
mydata$ageatmarrige ifelseisnamydata$ageatmarrige
mydata$respondentage,
mydata$ageatmarrige
#generating time to first marriage censoring indicator using marital status
# for unmarried and for others
mydata$cenc ifelsemydata$maritalstatus
# generating divorce cencoring indicator using marital status
mydata$cenc ifelsemydata$maritalstatus in c
# for time since first marriage, we replace for unmarried since they have never married
mydata$yearssincemarriage ifelseisnamydata$yearssincemarriage mydata$yearssincemarriage
# adding independent variables
# Assuming 'mydata' and 'MWIRAFL' are already loaded data frames
mydata$placeofresidence MWIRAFL$v
mydata$region MWIRAFL$v
mydata$education MWIRAFL$v
mydata$religion MWIRAFL$v
mydata$ethnicity MWIRAFL$v
mydata$wealthstatus MWIRAFL$v
# unlabelling the dataset
mydata unlabelledmydata
# generating equations for the two models
# time to first marriage and time to first marriage dissolution
eq ageatmarrige ~ slogageatmarrige bs "mpi" respondentage
placeofresidenceregioneducationreligionethnicitywealthstatus
eq yearssincemarriage ~ slogyearssincemarriage bs "mpi" respondentage
placeofresidenceregioneducationreligionethnicitywealthstatus
#fitting bivariate copula model
out gjrmlisteq eq data mydata,
copula C
margins ccloglog", probit"
cens cenc cens cenc model B
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
