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
library(haven)
library(tidyverse)
library(GJRM)
library(gt)
library(gtsummary)
library(labelled)
library(mice)
# loading main dhs dataset
MWIR7AFL <- read_dta("MW_2015-16_DHS_12242024_945_208869/MWIR7ADT/MWIR7AFL.DTA")
#attaching the dataset for variable easy access
attach(MWIR7AFL)
MWIR7AFL$v501
# Creating dataset for the analysis by extracting necessary variable from dhs dataset
mydata <- data.frame(age_at_marrige=v511, years_since_marriage=v512,
respondent_age=v012, marital_status= v501
)
# for the variable age at marriage, we replace with respondents age for unmarried
# the difference will be captured by the censoring indicator
mydata$age_at_marrige <- ifelse(is.na(mydata$age_at_marrige),
mydata$respondent_age,
mydata$age_at_marrige)
#generating time to first marriage censoring indicator using marital status
# 0 for unmarried and 1 for others
mydata$cenc1<- ifelse(mydata$marital_status==0,0,1)
# generating divorce cencoring indicator using marital status
mydata$cenc2<- ifelse(mydata$marital_status %in% c(4,5),1,0)
# for time since first marriage, we replace 0 for unmarried since they have never married
mydata$years_since_marriage <- ifelse(is.na(mydata$years_since_marriage),0, mydata$years_since_marriage)
# adding independent variables
# Assuming 'mydata' and 'MWIR7AFL' are already loaded data frames
mydata$place_of_residence <- MWIR7AFL$v025
mydata$region <- MWIR7AFL$v024
mydata$education <- MWIR7AFL$v106
mydata$religion <- MWIR7AFL$v130
mydata$ethnicity <- MWIR7AFL$v131
mydata$wealth_status <- MWIR7AFL$v190
# unlabelling the dataset
mydata <- unlabelled(mydata)
# generating equations for the two models
# time to first marriage and time to first marriage dissolution
eq1<- age_at_marrige ~ s(log(age_at_marrige), bs = "mpi")+ respondent_age +
place_of_residence+region+education+religion+ethnicity+wealth_status
eq2<- years_since_marriage ~ s(log(years_since_marriage), bs = "mpi")+ respondent_age +
place_of_residence+region+education+religion+ethnicity+wealth_status
#fitting bivariate copula model
out <- gjrm(list(eq1, eq2), data = mydata,
copula ="C0",
margins = c("-cloglog", "-probit"),
cens1= cenc1, cens2= cenc2, model ="B")

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!