library("polle")
### Two stages:
d <- sim_two_stage(2e2, seed=1)
pd <- policy_data(d,
action = c("A_1", "A_2"),
baseline = c("B"),
covariates = list(L = c("L_1", "L_2"),
C = c("C_1", "C_2")),
utility = c("U_1", "U_2", "U_3"))
pd
# available state history variable names:
get_history_names(pd)
# defining a g-model:
g_model <- g_glm(formula = ~B+C)
# evaluating the static policy (A=1) using inverse propensity weighting
# based on a state glm model across all stages:
pe <- policy_eval(type = "ipw",
policy_data = pd,
policy = policy_def(1, reuse = TRUE),
g_models = g_model)
# inspecting the fitted g-model:
get_g_functions(pe)
# available full history variable names at each stage:
get_history_names(pd, stage = 1)
get_history_names(pd, stage = 2)
# evaluating the same policy based on a full history
# glm model for each stage:
pe <- policy_eval(type = "ipw",
policy_data = pd,
policy = policy_def(1, reuse = TRUE),
g_models = list(g_glm(~ L_1 + B),
g_glm(~ A_1 + L_2 + B)),
g_full_history = TRUE)
# inspecting the fitted g-models:
get_g_functions(pe)
Run the code above in your browser using DataLab