% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/simulate_age.R
\name{simulate_age}
\alias{simulate_age}
\title{Simulate age values}
\usage{
simulate_age(GT, n = 1000, overwrite = FALSE)
}
\arguments{
\item{GT}{GeoTox object.}

\item{n}{Number of individuals to simulate per location (default 1000).
Ignored if 'sample' table already exists.}

\item{overwrite}{Logical indicating whether to overwrite existing 'age'
values in the 'sample' table (default FALSE).}
}
\value{
The same GeoTox object, invisibly.
}
\description{
Simulate 'age' values to be stored in the 'sample' table of a GeoTox
database.
}
\details{
An 'age' table containing simulation data must already exist in the GeoTox
database, which is added using \code{\link[=add_age]{add_age()}}.
}
\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)
}
\seealso{
\code{\link[=add_age]{add_age()}}, \code{\link[=simulate_population]{simulate_population()}}
}
