add_obesity: Add obesity simulation data

View source: R/add_tables.R

add_obesityR Documentation

Add obesity simulation data

Description

Create or add to the 'obesity' table in a GeoTox database.

Usage

add_obesity(GT, df, location = "FIPS")

Arguments

GT

GeoTox object.

df

Data frame with obesity simulation data.

location

Column name(s) in df that contain location identifier(s) (default "FIPS").

Details

The simulation data must contain columns for obesity prevalence and standard deviation (default "OBESITY_CrudePrev" and "OBESITY_SD", respectfully) and at least one column containing location information (default "FIPS"). The obesity data is used by simulate_obesity() to generate weight category samples for each location.

The location input can be a named vector to specify multiple identifier columns in df. For example, location = c(FIPS = "FIPS", state = "ST") would indicate that df contains both FIPS codes and state identifiers for locations. The state = "ST" part would rename the "ST" column in df to "state" in the 'location' table.

Value

The same GeoTox object, invisibly.

See Also

simulate_obesity()

Examples

# Example obesity simulation data
obesity_df <- data.frame(
  FIPS = c(10000, 20000),
  OBESITY_CrudePrev = c(20, 80),
  OBESITY_SD = 5
)

# Add obesity simulation data to GeoTox database
GT <- GeoTox() |> add_obesity(obesity_df)

# Open a connection to GeoTox database
con <- get_con(GT)

# Look at created tables

dplyr::tbl(con, "obesity") |> dplyr::collect()

dplyr::tbl(con, "location") |> dplyr::collect()

# Add another location with additional information
obesity_df <- data.frame(
 FIPS = 30000,
 ST = "State3",
 OBESITY_CrudePrev = 50,
 OBESITY_SD = 10
)
GT |> add_obesity(obesity_df, location = c(FIPS = "FIPS", state = "ST"))

# Look at updated tables

dplyr::tbl(con, "obesity") |> dplyr::collect()

dplyr::tbl(con, "location") |> 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.