#' Using Valente's SNS data
data(valentesnsList)
# Creating the DEFM object
logit_0 <- new_defm(
id = valentesnsList$id,
X = valentesnsList$X,
Y = valentesnsList$Y[,1,drop=FALSE],
order = 0
)
# Building the model
term_defm_logit_intercept(logit_0)
term_defm_logit_intercept(logit_0, idx = "Hispanic")
term_defm_logit_intercept(
logit_0, idx = "exposure_smoke",
vname = "Smoke Exp"
)
term_defm_logit_intercept(logit_0, idx = "Grades")
init_defm(logit_0) # Needs to be initialized
# Fitting the model
res_0 <- defm_mle(logit_0)
# Refitting the model using GLM
res_glm <- with(
valentesnsList,
glm(Y[,1] ~ X[,1] + X[,3] + X[,7], family = binomial())
)
# Comparing results
summary_table(res_0)
summary(res_glm)
# Comparing the logodds
head(logodds(logit_0, par = coef(res_0), i = 0, j = 0))
Run the code above in your browser using DataLab