TransitionClassification: Transition for a classification model

Description Arguments Value Construction Fields Methods Note See Also Examples

Description

TransitionClassification performs Monte Carlo simulation on a probabilistic model. In a simpler term, a psuedo random number generator is used to simulate the outcome based on the probability from the 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().

Create a TransitionClassification object.

Arguments

x

an Entity object

model

any objects of type in SupportedTransitionModels.

target

a named list where the names corresponds to the choices and the values are the number of agents to choose those choices. This imposes an alignment of the outcomes to an external constraint.

targeted_agents

a integer vector that contains ids of the entities in x to undergo this

model_by_id

see in the public field section.

Value

an R6::R6Class object

Construction

1
TransitionClassification$new(x, model, target = NULL, targeted_agents = NULL)

Fields

Methods

Note

target is used ensures that the aggregate outcome of the transition matches a macro-level outcome as defined in target. This is known as 'alignment' see, Li, J., & O'Donoghue, C. (2012). Evaluating binary alignment methods in microsimulation models. For example, in a transition where the probabilistic model predicts only two outcomes, a binary model, "yes" and "no". If the target is a list of yes = 10 and no = 20 (i.e.10 20'), this will ensure that there will be 10 decision makers whom select 'yes' and 20 decision makers that select 'no'. However, this doesn't mean that all decision makers have an equal odd of select 'yes' or 'no', the odd is still to be determined by the given probalistic model. See alignment for more detail.

See Also

TransitionRegression and Trans.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# create a Individual agent object
Ind <- Individual$new(.data = toy_individuals, id_col = "pid")

# create a probabilistic model
driver_status_rate <- data.table::data.table(
  sex = c("male", "female"),
  probs = list(c(0.3, 0.7), c(0.4, 0.6)),
  choices = list(c("can drive", "cannot drive"), c("can drive", "cannot drive"))
)

# create a Transition for driver status
TransitionCandrive <- R6::R6Class(
  classname = "TransitionCandrive",
  inherit = TransitionClassification
)

TransCanDrive <- TransitionCandrive$new(x = Ind, model = driver_status_rate)

barplot(
  table(TransCanDrive$get_result()[["response"]]),
  main = "Transition result: driver status",
  col = c("steelblue", "salmon")
)

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