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 get_history_names() to view the available variable names.

...

Additional arguments passed to glm(), glmnet::glmnet, ranger::ranger or SuperLearner::SuperLearner.

family

A description of the error distribution and link function to be used in the model.

model

(Only used by g_glm) If FALSE model frame will not be saved.

na.action

(Only used by g_glm) A function which indicates what should happen when the data contain NAs, see na.pass.

alpha

(Only used by g_glmnet) The elastic net mixing parameter between 0 and 1. alpha equal to 1 is the lasso penalty, and alpha equal to 0 the ridge penalty.

s

(Only used by g_glmnet) Value(s) of the penalty parameter lambda at which predictions are required, see glmnet::predict.glmnet().

num.trees

(Only used by g_rf) Number of trees.

mtry

(Only used by g_rf) Number of variables to possibly split at in each node.

cv_args

(Only used by g_rf and g_xgboost) Cross-validation parameters. Only used if multiple hyper-parameters are given. K is the number of folds and rep is the number of replications.

SL.library

(Only used by g_sl) Either a character vector of prediction algorithms or a list containing character vectors, see SuperLearner::SuperLearner.

env

(Only used by g_sl) Environment containing the learner functions. Defaults to the calling environment.

onlySL

(Only used by g_sl) Logical. If TRUE, only saves and computes predictions for algorithms with non-zero coefficients in the super learner object.

objective

(Only used by g_xgboost) specify the learning task and the corresponding learning objective, see xgboost::xgboost.

params

(Only used by g_xgboost) list of parameters.

nrounds

(Only used by g_xgboost) max number of boosting iterations.

max_depth

(Only used by g_xgboost) maximum depth of a tree.

eta

(Only used by g_xgboost) learning rate.

nthread

(Only used by g_xgboost) number of threads.

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)

[Package polle version 1.4 Index]