Description Format Construction Public Fields Active Fields (read-only) Public Methods
Create Individual class, extended Agent class.
R6::R6Class object inheriting from Agent<-Entity.
1 | Ind <- Individual$new(.data, id_col, hid_col)
|
.data
::data.table::data.table
Microdata of Individuals.
id_col
::character()
Names of the primary id colum and relation id colunns in .data
hid_col
::character(1)
Name of the id colum in .data
NULL
hid_col
::(character(1)
)
Household id variable name.
Inherits all fields and methods of Agent.
get_father(ids)
(integer()
) -> integer()
Get father ids of the corresponding individual ids.
get_mother(ids)
(integer()
) -> integer()
Get mother ids of the corresponding individual ids.
get_partner(ids)
(integer()
) -> integer()
Get partner ids of the corresponding individual ids.
get_children(ids)
(integer()
) -> list()
Returns a list of children that has the same length as ids
. NAs are returned
where individual agents have no children. Please note that only the number of children
that are alive will be returned. To get the number of children an individual ever have
during the simulation you may need to implement a function that look at the historical
records of the individual to determine that.
get_n_children(ids)
(integer()
) -> integer()
Returns the number of children each individual agent in the given ids has.
get_n_resident_children(ids)
(integer()
) -> integer()
Returns the number of children that live in the same household as the individuals
in ids
.
living_together
(integer()
, inteter()
) -> logical()
For checking if two agents are residing in the same household. If either of
the ids is NA the function will return NA for those indexes.
get_household_ids(ids)
(integer()
) -> integer()
Returns household ids of the individual in ids
arg.
get_ids_in_hids(hids = NULL)
-
(integer()
) -> integer()
Returns individual ids matches the input hids
.
get_hid_col()
() -> character(1)
Returns household id or hid
of the individual-object.
add_relationship(ids, target_ids, type)
(integer()
, integer()
, 'father'|'mother'|'partner'
)
Adds target_ids
to the relationship column in type
of the individual
agents in ids
. Note that, if type
is 'partner' then both agents with id in
ids
and target_ids
will add each other as 'partner'. Hence, no need for
you to call this function twice to assign partner relationship to all the couples.
remove_relationship(ids, type = "partner")
(integer()
, 'partner'
)
Note that, children and parents can't be removed. Only partner relationship can be removed.
have_relationship(ids = NULL, type)
(integer()
, character(1)
) -> logical()
Check if individuals in ids
have the relationship of type type
.
remove_household_id(ids)
(integer()
)
Remove household ids of individuals in ids
.
add_household_id(ids, hh_ids)
(integer()
, integer()
)
Replace household ids of individuals in ids
. ids
and hh_ids
must be
of the same length.
get_parent_hid(ids = NULL)
(integer()
) -> data.table::data.table()
Returns a data.table with three columns: pid, father_hid and mother_hid.
living_together(self_ids, target_ids)
(integer()
, integer()
) -> logical()
Check if two individuals are living together in the same household. Returns
logical vector.
have_resident_child(ids = NULL)
(integer()
) -> logical()
Returns a logical of length ids
if ids is not NULL else the length will be
equal to the number of rows of the data. Resident children are those children
who are living in the same household as their parents.
get_ids_from_id_cols(id_cols = NULL, na.rm = TRUE)
(character()
, logical(1)
) -> character()
Returns all unique ids in id_cols in a vector, excluding household ids.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.