Description Format Construction Fields Methods Note See Also Examples
This is particularly useful for updating agents' attributes that can be modelled using a regression model.
By calling the constructor method of TransitionClassification this will initiate the following steps:
initialise(x, model, target, targeted_agents)
->
filter(.data)
: filter agents to apply the transition to.
mutate(.data)
: add variables to the data of the filtered agents.
simulate()
: simulate the transition outcome using the probabilistic model
postprocess(.sim_result)
: post-processing the simulation result.
Note that, the order of filter and mutate can be swap by overwriting the mutate_first
public field to TRUE
. This may be useful in cases where agent selection for
the transition depends on one or more derived variables.
To get the simulation result use $get_result()
.
R6::R6Class object inheriting from Trans
1 | TransitionRegression$new(x, model, targeted_agents = NULL)
|
x
:: R6::R6Class
A Agent class inheritance object.
model
:: any object
in SupportedTransitionModels
A model object to be used to simulate transition.
targeted_agent
:: integer()
(Default as NULL)
A integer vectors that contains ids of agents in x
to undergo the event.
mutate_first
:: logical(1)
Default as FALSE, this flag is used to indicate whether the attribute data from
the Agent in x
should be mutated ($mutate(.data)
) before filtered ($filter(.data)
).
filter(.data)
(data.table::data.table()
) -> [data.table::data.table()]
(By default, first of the preprocessing steps)
By default this method returns the input .data
. This method can be overwrite
to give the user the flexibility to 'filter' the data prior to making prediction
by the given model. Filtering for eligible agents for this transition can be done in this step.
mutate(.data)
(data.table::data.table()
) -> [data.table::data.table()]
(By default, second of the preprocessing steps)
By default this method returns the input .data
. This method can be overwrite
to give the user the flexibility to 'mutate' the data prior to making prediction
by the given model. Adding derived variables and historical life course of the agents
can be done in this step.
update_agents(attr)
(character(1)
)
Update the attribute data of the agents that undergo the transition event.
get_result(ids)
(integer()
) -> data.table::data.table
Returns the simulation result in a data.table::data.table format with two
columns id
and response
.
get_nrow_result()
Returns the number of rows in the simulation result.
get_decision_maker_ids(response_filter = NULL)
(character()
) -> (integer()
)
Returns ids of the agents that have their response equal to response_filter
.
TransitionRegression only returns a raw output of the simulation result. In a future update, there will be an option which allows the prediction result to be drawn from a distribution to add randomness to the result.
TransitionClassification and Trans.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | # load toy data
create_toy_population()
Ind <- pop$get("Individual")
# fit a OLS regression model
model_lm <- glm(age ~ sex + marital_status,
data = Ind$get_data(),
family = "gaussian"
)
summary(model_lm)
TransAge <- TransitionRegression$new(Ind, model = model_lm)
# see the simulation result
TransAge
# update the individual agents' 'age' field using their simulated age
TransAge$update_agents(attr = "age")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.