simulate_age: Simulate age values

View source: R/simulate_age.R

simulate_ageR Documentation

Simulate age values

Description

Simulate 'age' values to be stored in the 'sample' table of a GeoTox database.

Usage

simulate_age(GT, n = 1000, overwrite = FALSE)

Arguments

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).

Details

An 'age' table containing simulation data must already exist in the GeoTox database, which is added using add_age().

Value

The same GeoTox object, invisibly.

See Also

add_age(), simulate_population()

Examples

# 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)

GeoTox documentation built on May 20, 2026, 1:07 a.m.