View source: R/class_newborn_rule.R
| new_newborn_rule | R Documentation |
Builds the rule that decides which state a child occupies at birth. The rule defines which state variables the child takes from its mother and how the remaining ones are drawn.
new_newborn_rule(states, prob, inherit = integer(0))
states |
Character matrix of admissible newborn states. A data frame is accepted and converted. |
prob |
Numeric weights, one per row of |
inherit |
Integer column positions the newborn takes from its mother. When empty nothing is inherited. |
states is the table of states a newborn can take. It has one row per
possible combination and one column per state variable of the model.
The columns follow the model's state variables in order.
prob assigns a probability between 0 and 1 for each row to be selected.
inherit names the column positions the child takes from its mother.
At a birth the rule keeps only the rows that agree with the mother on every inherited position, and draws one of them with the corresponding probability. When nothing is inherited, it draws from the whole table to decide a newborn's state.
In the example from ?micSim, the state variables are sex,
nationality and parity. Nationality is inherited and sex is drawn with a
sex ratio that differs by nationality; parity
is "0".
states = rbind(c("m","DE","0"), c("f","DE","0"),
c("m","AT","0"), c("f","AT","0"),
c("m","IT","0"), c("f","IT","0"))
prob = c(0.515, 0.485, 0.515, 0.485, 0.515, 0.485)
inherit = 2
A child of an Austrian mother can only be row 3 or row 4, and those two weights sum to one. This is checked by the validation separately for each unique inherited attribute.
An object of class newborn_rule.
The weights within each inherited group must sum to one within
PROB_TOL. A table whose weights do not sum to one in some group returns
an error, because a mother in that group would otherwise have no
well-defined newborn distribution.
A state variable that is neither inherited nor allowed to vary in
states takes the single value it has in every row. Parity for example will
usually have every newborn starting at "0".
newborn_rule() for the per-variable form, fertility(),
assign_newborn_state(),
MicSim-concepts
rule <- new_newborn_rule(
states = rbind(c("m", "DE", "0"), c("f", "DE", "0"),
c("m", "AT", "0"), c("f", "AT", "0")),
prob = c(0.515, 0.485, 0.515, 0.485),
inherit = 2L
)
rule
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.