# \donttest{
require(magrittr)
require(data.table)
obs_data <- obs_data[MDV == 0]
sim_data <- sim_data[MDV == 0]
vpc <- observed(obs_data, y = DV, x = TIME) %>%
simulated(sim_data, y = DV) %>%
binless() %>%
vpcstats()
# Binless example with LOESS prediction correction
obs_data$PRED <- sim_data[REP == 1, PRED]
vpc <- observed(obs_data, y = DV, x = TIME) %>%
simulated(sim_data, y = DV) %>%
binless(optimize = TRUE) %>%
predcorrect(pred = PRED) %>%
vpcstats()
# Binless example with user specified lambda values stratified on
# "GENDER" with 2 levels ("M", "F"), 10%, 50%, 90% quantiles.
lambda_strat <- data.table(
GENDER_M = c(3,5,2),
GENDER_F = c(1,3,4)
)
vpc <- observed(obs_data, y = DV, x = TIME) %>%
simulated(sim_data, y = DV) %>%
stratify(~ GENDER) %>%
binless(optimize = FALSE, lambda = lambda_strat) %>%
vpcstats(qpred = c(0.1, 0.5, 0.9))
# Binless example for categorical DV with optimized smoothing
vpc <- observed(obs_cat_data, x = agemonths, yobs = zlencat) %>%
simulated(sim_cat_data, ysim = DV) %>%
stratify(~ Country_ID_code) %>%
binless() %>%
vpcstats(vpc.type = "cat", quantile.type = 6)
# Binless example for categorical DV with user specified sp values
user_sp <- list(
Country1_prob0 = 100,
Country1_prob1 = 3,
Country1_prob2 = 4,
Country2_prob0 = 90,
Country2_prob1 = 3,
Country2_prob2 = 4,
Country3_prob0 = 55,
Country3_prob1 = 3,
Country3_prob2 = 200)
vpc <- observed(obs_cat_data, x = agemonths, yobs = zlencat) %>%
simulated(sim_cat_data, ysim = DV) %>%
stratify(~ Country_ID_code) %>%
binless(optimize = FALSE, sp = user_sp) %>%
vpcstats(vpc.type = "categorical", conf.level = 0.9, quantile.type = 6)
# }
Run the code above in your browser using DataLab