% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/get_assay_table.R, R/get_risk_quantiles.R,
%   R/get_risk_sensitivity.R, R/get_risk_values.R
\name{get_assay_table}
\alias{get_assay_table}
\alias{get_risk_quantiles}
\alias{get_risk_sensitivity}
\alias{get_risk_values}
\title{Get risk metric results}
\usage{
get_assay_table(GT)

get_risk_quantiles(
  GT,
  metric = c("GCA.Eff", "IA.Eff", "GCA.HQ.10", "IA.HQ.10"),
  quantiles = c(0.1, 0.25, 0.5, 0.75, 0.9),
  table_name = "risk"
)

get_risk_sensitivity(
  GT,
  metric = c("GCA.Eff", "IA.Eff", "GCA.HQ.10", "IA.HQ.10"),
  assay = NULL
)

get_risk_values(
  GT,
  metric = c("GCA.Eff", "IA.Eff", "GCA.HQ.10", "IA.HQ.10"),
  assay = NULL,
  table_name = "risk"
)
}
\arguments{
\item{GT}{GeoTox object.}

\item{metric}{Risk metric to retrieve. One of "GCA.Eff", "IA.Eff",
"GCA.HQ.10", or "IA.HQ.10".}

\item{quantiles}{Numeric vector of quantiles to calculate.}

\item{table_name}{Name of the risk table to query (default "risk").}

\item{assay}{Named vector specifying an assay filter (default NULL).}
}
\value{
A data frame or vector.
}
\description{
Several functions used to fetch risk metric results from risk tables in a
GeoTox database. The outputs of these functions are useful for plotting or
further analysis.
}
\details{
Normally an 'assay' table is created when adding the Hill model
concentration-response fit parameters with \code{\link[=add_hill_params]{add_hill_params()}}. If no \code{assay}
input is specified in \code{\link[=fit_hill]{fit_hill()}}, then an 'assay' table will not be
created. For \code{\link[=get_risk_values]{get_risk_values()}}, the \code{assay} parameter can be used to filter
results based on assay details stored in the 'assay' table. This is useful
when multiple assays are available in the database. The \code{assay} input should
be a named vector specifying the column name and value to filter by, e.g.
\code{assay = c(endp = "mortality")}. For \code{\link[=get_risk_quantiles]{get_risk_quantiles()}}, if there is no
assay data in the GeoTox database, then the output "assay_id" column will be
filled with NA values. If there is assay data, use \code{\link[=get_assay_table]{get_assay_table()}} to
retrieve assay information and link the "assay_id" to assay details.

Use the \code{table_name} parameter to specify which risk table to query. There
can be several risk tables in a GeoTox database. The default table is named
"risk" and is created by either \code{\link[=calc_risk]{calc_risk()}} or the wrapper function
\code{\link[=calc_response]{calc_response()}}. Sensitivity analysis results created by either
\code{\link[=calc_sensitivity]{calc_sensitivity()}} or the wrapper function \code{\link[=sensitivity_analysis]{sensitivity_analysis()}} are
stored in other tables with names like "risk_sensitivity_age", etc. Refer to
\code{\link[=calc_sensitivity]{calc_sensitivity()}} to see which tables may be available.

\code{\link[=get_risk_sensitivity]{get_risk_sensitivity()}} is a wrapper function for \code{\link[=get_risk_values]{get_risk_values()}} around
all risk tables created by the original risk computation and subsequent
sensitivity analysis. The column names are "baseline" for the original risk
table, while the other column names correspond to the parameter varied in the
sensitivity analysis.
}
\examples{
# Example setup is shown below in \dontrun().
# Pre-generated results will be loaded instead to avoid long example runtime.

\dontrun{
# Setup required tables
sample_df <- tibble::tribble(
  ~FIPS, ~age, ~weight,
  10000, 25, "Normal",
  10000, 35,  "Obese",
  20000, 50, "Normal"
)
exposure_df <- tibble::tribble(
  ~FIPS, ~casn, ~route, ~mean, ~sd,
  10000, "00-00-1", "inhalation", 10, 1,
  10000, "00-00-2", "inhalation", 20, 1,
  20000, "00-00-1", "inhalation", 30, 1,
  20000, "00-00-2", "inhalation", 40, 1
)
css_df <- tibble::tribble(
  ~casn, ~age_lb, ~age_ub, ~weight, ~css,
  "00-00-1",  0, 49, "Normal", 21,
  "00-00-1", 50, 99, "Normal", 22,
  "00-00-1",  0, 49,  "Obese", 61,
  "00-00-1", 50, 99,  "Obese", 62,
  "00-00-2",  0, 49, "Normal", 11,
  "00-00-2", 50, 99, "Normal", 12,
  "00-00-2",  0, 49,  "Obese", 31,
  "00-00-2", 50, 99,  "Obese", 32
)
hill_df <- tibble::tribble(
  ~assay, ~model, ~casn, ~logc, ~resp,
  "a1", "human", "00-00-1",    0,  10,
  "a1", "human", "00-00-1",    1,  20,
  "a1", "human", "00-00-1",    2,  80,
  "a1", "human", "00-00-1",    3, 100,
  "a1", "human", "00-00-2", -0.5,   5,
  "a1", "human", "00-00-2",  0.5,  20,
  "a1", "human", "00-00-2",  1.5,  55,
  "a1", "human", "00-00-2",  2.5,  60,
  "a2",   "rat", "00-00-1",   -1,   0,
  "a2",   "rat", "00-00-1",    0,  10,
  "a2",   "rat", "00-00-1",    1,  30,
  "a2",   "rat", "00-00-1",    2,  40
)
set.seed(1234)
GT <- GeoTox() |>
  set_sample(sample_df) |>
  set_simulated_css(css_df) |>
  add_exposure_rate_params() |>
  add_hill_params(fit_hill(
    hill_df, assay = c(name = "assay", model = "model"), substance = "casn"
  )) |>
  simulate_population(exposure = exposure_df) |>
  calc_response() |>
  sensitivity_analysis()

}

# Load results from pre-generated database for this example
temp_dir <- tempdir()
zip::unzip(
  system.file("extdata", "sensitivity.duckdb.zip", package = "GeoTox"),
  junkpaths = TRUE,
  exdir = temp_dir
)
GT <- GeoTox(paste0(temp_dir, "/sensitivity.duckdb"))

# Look at 'assay' table contents
get_assay_table(GT)

# Get "GCA.HQ.10" values from 'risk' table for the "a1" assay
get_risk_values(GT, metric = "GCA.HQ.10", assay = c(name = "a1"))

# Get "IA.Eff" values from all risk tables for the "a2" assay
get_risk_sensitivity(GT, metric = "IA.Eff", assay = c(name = "a2"))

# Get "GCA.Eff" quantiles from 'risk' table
get_risk_quantiles(GT, metric = "GCA.Eff", quantiles = c(0.25, 0.5, 0.75))

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

# Look at the 'risk' table contents
dplyr::tbl(con, "risk") |> dplyr::collect()

# Clean up example
DBI::dbDisconnect(con)
file.remove(GT$db_info$dbdir)
}
\seealso{
\code{\link[=calc_risk]{calc_risk()}}, \code{\link[=calc_response]{calc_response()}}, \code{\link[=calc_sensitivity]{calc_sensitivity()}},
\code{\link[=sensitivity_analysis]{sensitivity_analysis()}}, \code{\link[=fit_hill]{fit_hill()}}, \code{\link[=add_hill_params]{add_hill_params()}}
}
