View source: R/simulate_obesity.R
| simulate_obesity | R Documentation |
Simulate 'weight' category values to be stored in the 'sample' table of a GeoTox database.
simulate_obesity(
GT,
n = 1000,
overwrite = FALSE,
obes_prev = NULL,
obes_sd = NULL
)
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"). |
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.
The updated GeoTox object, invisibly.
add_obesity(), simulate_population()
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.