## ------------------------------------------------------------------- #
## Example 1: Moderated effect of education on poverty
##
## See the help of 'tvcglm'.
## ------------------------------------------------------------------- #
data(poverty)
poverty$EduHigh <- 1 * (poverty$Edu == "high")
## fit the model
model.Pov <-
tvcm(Poor ~ -1 + vc(CivStat) + vc(CivStat, by = EduHigh) + NChild,
family = binomial(), data = poverty, subset = 1:200,
control = tvcm_control(verbose = TRUE, papply = "lapply",
folds = folds_control(K = 1, type = "subsampling", seed = 7)))
## diagnosis
plot(model.Pov, "cv")
plot(model.Pov, "coef")
summary(model.Pov)
splitpath(model.Pov, steps = 1:3)
prunepath(model.Pov, steps = 1)
## ------------------------------------------------------------------- #
## Example 2: Moderated effect effect of unemployment
##
## See the help of 'tvcolmm'.
## ------------------------------------------------------------------- #
data(unemp)
## fit the model
model.UE <-
tvcm(GHQL ~ -1 +
vc(AGE, FISIT, GENDER, UEREGION, by = UNEMP, intercept = TRUE) +
re(1|PID),
data = unemp, control = tvcm_control(sctest = TRUE),
family = cumulative())
## diagnosis (no cross-validation was performed since 'sctest = TRUE')
plot(model.UE, "coef")
summary(model.UE)
splitpath(model.UE, steps = 1, details = TRUE)
Run the code above in your browser using DataLab