g_model {polle} | R Documentation |
g_model class object
Description
Use g_glm()
, g_empir()
,
g_glmnet()
, g_rf()
, g_sl()
, g_xgboost
to construct
an action probability model/g-model object.
The constructors are used as input for policy_eval()
and policy_learn()
.
Usage
g_empir(formula = ~1, ...)
g_glm(
formula = ~.,
family = "binomial",
model = FALSE,
na.action = na.pass,
...
)
g_glmnet(formula = ~., family = "binomial", alpha = 1, s = "lambda.min", ...)
g_rf(
formula = ~.,
num.trees = c(500),
mtry = NULL,
cv_args = list(nfolds = 5, rep = 1),
...
)
g_sl(
formula = ~.,
SL.library = c("SL.mean", "SL.glm"),
family = binomial(),
env = as.environment("package:SuperLearner"),
onlySL = TRUE,
...
)
g_xgboost(
formula = ~.,
objective = "binary:logistic",
params = list(),
nrounds,
max_depth = 6,
eta = 0.3,
nthread = 1,
cv_args = list(nfolds = 3, rep = 1)
)
Arguments
formula |
An object of class formula specifying the design matrix for
the propensity model/g-model. Use |
... |
Additional arguments passed to |
family |
A description of the error distribution and link function to be used in the model. |
model |
(Only used by |
na.action |
(Only used by |
alpha |
(Only used by |
s |
(Only used by |
num.trees |
(Only used by |
mtry |
(Only used by |
cv_args |
(Only used by |
SL.library |
(Only used by |
env |
(Only used by |
onlySL |
(Only used by |
objective |
(Only used by |
params |
(Only used by |
nrounds |
(Only used by |
max_depth |
(Only used by |
eta |
(Only used by |
nthread |
(Only used by |
Details
g_glm()
is a wrapper of glm()
(generalized linear model).
g_empir()
calculates the empirical probabilities within the groups
defined by the formula.
g_glmnet()
is a wrapper of glmnet::glmnet()
(generalized linear model via
penalized maximum likelihood).
g_rf()
is a wrapper of ranger::ranger()
(random forest).
When multiple hyper-parameters are given, the
model with the lowest cross-validation error is selected.
g_sl()
is a wrapper of SuperLearner::SuperLearner (ensemble model).
g_xgboost()
is a wrapper of xgboost::xgboost.
Value
g-model object: function with arguments 'A' (action vector), 'H' (history matrix) and 'action_set'.
See Also
get_history_names()
, get_g_functions()
.
Examples
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)