% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/simulate_obesity.R
\name{simulate_obesity}
\alias{simulate_obesity}
\title{Simulate obesity values}
\usage{
simulate_obesity(
  GT,
  n = 1000,
  overwrite = FALSE,
  obes_prev = NULL,
  obes_sd = NULL
)
}
\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 'weight'
values in the 'sample' table (default FALSE).}

\item{obes_prev}{Column name of obesity prevalence in the 'obesity' table
(default "OBESITY_CrudePrev").}

\item{obes_sd}{Column name of obesity standard deviation in the 'obesity'
table (default "OBESITY_SD").}
}
\value{
The updated GeoTox object, invisibly.
}
\description{
Simulate 'weight' category values to be stored in the 'sample' table of a
GeoTox database.
}
\details{
An 'obesity' table containing simulation data must already exist in the
GeoTox database, which is added using \code{\link[=add_obesity]{add_obesity()}}.

The inputs \code{obes_prev} and \code{obes_sd} will be assigned default values of
"OBESITY_CrudePrev" and "OBESITY_SD", respectively, if not provided and not
already set in the GeoTox object's parameters, \code{GT$par}. If not \code{NULL}, the
provided values will also be saved to \code{GT$par}.
}
\examples{
# Example obesity simulation data
obesity_df <- data.frame(
  FIPS = c(10000, 20000),
  OBESITY_CrudePrev = c(20, 80),
  OBESITY_SD = 5
)

# Simulate weight category values
GT <- GeoTox() |>
  add_obesity(obesity_df) |>
  simulate_obesity(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()

# Replace 'obesity' table with different column names
names(obesity_df)[2:3] <- c("prev", "sd")
DBI::dbRemoveTable(con, "obesity")
GT |> add_obesity(obesity_df)

# Overwrite 'weight' category values in existing 'sample' table
# Must specify new 'obesity' column names
# Notice how the column names are added to GT$par
str(GT$par)
GT <- GT |>
  simulate_obesity(obes_prev = "prev", obes_sd = "sd", overwrite = TRUE)
str(GT$par)

# 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_obesity]{add_obesity()}}, \code{\link[=simulate_population]{simulate_population()}}
}
