R/agent-to-aggregate.R
agents_to_aggregate.grouped_df.Rd
This function converts data on an agent-based level (1 row = 1 agent)
relative when an agent is in each state and aggregates it, so that the user
can know how many agents are in each state at a given time point (integer
based). This function takes grouped_df
data.frame
s (from
dplyr) and aggregates within grouping parameters and also
provides the columns associated with the grouping.
# S3 method for grouped_df agents_to_aggregate( agents, states, death = NULL, birth = NULL, min_max_time = c(0, NA), integer_time_expansion = TRUE )
agents | grouped data.frame with individual agent information |
---|---|
states | Name-variable pairs of the form
|
death | string for column with death time information (default
|
birth | string for column with birth time information (default
|
min_max_time | vector (length 2) of minimum and maximum integer time,
the second value can be |
integer_time_expansion | boolean if every integer time point in the
range of |
grouped dataset with aggregated information per group, We label
classes "X{i}
" for i in 0:(length(states))
.
note that all parameters related to name columns can also be in a
string format. More details can be found in agents_to_aggregate
's
documentation.
library(dplyr) max_time <- 100 agents_g <- hagelloch_raw %>% filter(SEX %in% c("female", "male")) %>% group_by(SEX) sir_group <- agents_to_aggregate(agents_g, states = c(tI, tR), min_max_time = c(0, max_time)) agents <- agents_g %>% filter(SEX == "female") %>% ungroup() sir_group1 <- agents_to_aggregate(agents, states = c(tI, tR), min_max_time = c(0, max_time)) sir_group_1 <- sir_group %>% filter(SEX == "female") assertthat::are_equal(sir_group1, sir_group_1 %>% ungroup %>% select(t, X0, X1, X2))#> [1] TRUE