TransitionRegression: Transition for regression model

Description Format Construction Fields Methods Note See Also Examples

Description

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:

  1. initialise(x, model, target, targeted_agents) ->

  2. filter(.data): filter agents to apply the transition to.

  3. mutate(.data): add variables to the data of the filtered agents.

  4. simulate(): simulate the transition outcome using the probabilistic model

  5. 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().

Format

R6::R6Class object inheriting from Trans

Construction

1
TransitionRegression$new(x, model, targeted_agents = NULL)

Fields

Methods

Note

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.

See Also

TransitionClassification and Trans.

Examples

 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")

dymium-org/dymiumCore documentation built on July 18, 2021, 5:10 p.m.