policy_def {polle} | R Documentation |
Define Policy
Description
policy_def
returns a function of class policy.
The function input is a policy_data object and it returns a data.table
with keys id
and stage
and action variable d
.
Usage
policy_def(policy_functions, full_history = FALSE, reuse = FALSE, name = NULL)
Arguments
policy_functions |
A single function/character string or a list of functions/character strings. The list must have the same length as the number of stages. |
full_history |
If TRUE, the full history at each stage is used as input to the policy functions. |
reuse |
If TRUE, the policy function is reused at every stage. |
name |
Character string. |
Value
Function of class "policy"
. The function takes a
policy_data object as input and returns a data.table
with keys id
and stage
and action variable d
.
See Also
get_history_names()
, get_history()
.
Examples
library("polle")
### Single stage"
d1 <- sim_single_stage(5e2, seed=1)
pd1 <- policy_data(d1, action="A", covariates=list("Z", "B", "L"), utility="U")
pd1
# defining a static policy (A=1):
p1_static <- policy_def(1)
# applying the policy:
p1_static(pd1)
# defining a dynamic policy:
p1_dynamic <- policy_def(
function(Z, L) ((3*Z + 1*L -2.5)>0)*1
)
p1_dynamic(pd1)
### Two stages:
d2 <- sim_two_stage(5e2, seed = 1)
pd2 <- policy_data(d2,
action = c("A_1", "A_2"),
covariates = list(L = c("L_1", "L_2"),
C = c("C_1", "C_2")),
utility = c("U_1", "U_2", "U_3"))
# defining a static policy (A=0):
p2_static <- policy_def(0,
reuse = TRUE)
p2_static(pd2)
# defining a reused dynamic policy:
p2_dynamic_reuse <- policy_def(
function(L) (L > 0)*1,
reuse = TRUE
)
p2_dynamic_reuse(pd2)
# defining a dynamic policy for each stage based on the full history:
# available variable names at each stage:
get_history_names(pd2, stage = 1)
get_history_names(pd2, stage = 2)
p2_dynamic <- policy_def(
policy_functions = list(
function(L_1) (L_1 > 0)*1,
function(L_1, L_2) (L_1 + L_2 > 0)*1
),
full_history = TRUE
)
p2_dynamic(pd2)
[Package polle version 1.4 Index]