| simulate_age | R Documentation |
Simulate 'age' values to be stored in the 'sample' table of a GeoTox database.
simulate_age(GT, n = 1000, overwrite = FALSE)
GT |
GeoTox object. |
n |
Number of individuals to simulate per location (default 1000). Ignored if 'sample' table already exists. |
overwrite |
Logical indicating whether to overwrite existing 'age' values in the 'sample' table (default FALSE). |
An 'age' table containing simulation data must already exist in the GeoTox
database, which is added using add_age().
The same GeoTox object, invisibly.
add_age(), simulate_population()
# Example age simulation data
age_df <- data.frame(
FIPS = rep(c(10000, 20000), each = 19),
AGEGRP = rep(0:18, times = 2),
TOT_POP = 0
)
# FIPS 10000, populate age group 40-44
age_df$TOT_POP[c(1, 10)] = 100
# FIPS 20000, populate age groups 50-59
age_df$TOT_POP[c(1, 12, 13) + 19] = c(200, 100, 100)
# Simulate age values
GT <- GeoTox() |>
add_age(age_df) |>
simulate_age(n = 5)
# Open a connection to GeoTox database
con <- get_con(GT)
# Look at created tables
dplyr::tbl(con, "sample") |> dplyr::collect()
dplyr::tbl(con, "location") |> dplyr::collect()
# Overwrite existing age values
GT <- GT |> simulate_age(overwrite = TRUE)
# Look at updated 'sample' table
dplyr::tbl(con, "sample") |> dplyr::collect()
# Clean up example
DBI::dbDisconnect(con)
file.remove(GT$db_info$dbdir)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.