simulate_obesity: Simulate obesity values

View source: R/simulate_obesity.R

simulate_obesityR Documentation

Simulate obesity values

Description

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

Usage

simulate_obesity(
  GT,
  n = 1000,
  overwrite = FALSE,
  obes_prev = NULL,
  obes_sd = NULL
)

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 'weight' values in the 'sample' table (default FALSE).

obes_prev

Column name of obesity prevalence in the 'obesity' table (default "OBESITY_CrudePrev").

obes_sd

Column name of obesity standard deviation in the 'obesity' table (default "OBESITY_SD").

Details

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

The inputs obes_prev and 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, GT$par. If not NULL, the provided values will also be saved to GT$par.

Value

The updated GeoTox object, invisibly.

See Also

add_obesity(), simulate_population()

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)

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