View source: R/inference_api.R
fetch_predicted_hazard | R Documentation |
Fetch predicted hazard at regular intervals during the follow-up window.
fetch_predicted_hazard(
run_id,
level = c("study", "trial_arm", "subject", "overall"),
return = c("median", "quantiles", "intervals", "draws"),
type = c("posterior", "prior"),
subject_id = NULL,
individual_id = NULL,
trial_arm_name = NULL,
trial_name = NULL,
trial_id = NULL,
chains = NULL,
draws = NULL,
quantiles = NULL,
intervals = c(0.5, 0.8, 0.9),
project = NULL,
project_version_id = NULL
)
run_id |
[required] One or several model run_ids. See |
level |
The level at which to return predicted values. One of: subject, trial_arm, study, or overall. Default value is per study |
return |
The type of summary to return. One of: median, quantiles, intervals, or draws. Default: median |
type |
Whether to return posterior or prior predictions. Default: posterior |
subject_id |
If provided, limit results to this set of subject_id(s). This is a unique UUID identifying a subject in the Geco Database. See |
individual_id |
If provided, limit results to this set of individual_id(s). This typically corresponds to the patient identifier in the original database, which may not be unique across trials and projects. |
trial_arm_name |
If provided, limit results to this set of trial_arm_name(s). See |
trial_name |
If provided, limit results to this set of trial_name(s). See |
trial_id |
If provided, limit results to this set of trial_id(s). This is a unique UUID for each trial in the Geco Database. See |
chains |
If provided, limit returned draws to the set of chains listed. Note that chains are 0-indexed on the server. This filter only applies to the |
draws |
If provided, limit returned draws to the set of draw indices listed. Note that draws are 0-indexed on the server. This filter only applies to the |
quantiles |
If provided, limit returned quantiles to the set of values listed. Only some quantiles are pre-computed, and inputs requested which are not available will be ignored. This filter only applies to the |
intervals |
If provided, limit returned interval widths to the set of values listed. Only 0.5, 0.8, 0.9 widths are currently, and inputs requested which are not available will be ignored. This filter only applies to the |
project |
The name of the project to which the run_id belongs. |
project_version_id |
The specific project_version_id to which the run_id belongs. Defaults to the most recent project_version_id if none provided. |
Predicted hazard values can be provided at different levels of the hierarchical model:
Per subject: prediction for each subject, using subject-level parameters
Per trial_arm: summarized hazard over all subjects in a trial-arm, for each followup timepoint
Per study: summarized hazard over all subjects in a study, for each followup timepoint
Overall: summarized hazard over all subjects in the run, including simulated data comprising the background set
Use the level
argument to select the desired level at which to summarize predicted values.
Authentication (see login
) is required prior to using this function. This
function accesses information from the Generable API.
There are four slightly different return formats, depending on the return
argument provided. See notes for details.
A data.frame in tidy format, with one record per parameter, run_id, and summarized level. See notes for specific details about each return type.
The columns returned depends on the value of the 'return' argument. The default is to return median values for each level
and prediction time (biomarker_time
, in days).
All return formats share a set of columns containing meta-information about the predicted quantities:
.variable
Text label for the predicted quantity or variable. In this case, "predicted_hazard"
run_id
Text field containing the run_id from which each returned value was generated.
.type
Text field containing the type (prior or posterior) of predicted quantity or inferences summarized.
.level
Text field containing the level (subject, trial_arm, or overall) at which the predicted values were prepared.
survival_time
Numeric field containing the study time (days) at which the predicted value was prepared.
subject_id | trial_arm_id | trial_id
If returning predicted values at the subject, study, or trial-arm level, the ids corresponding to the subjects or trial-arms used in the prediction.
In addition, there will be a few columns to provide and describe the predicted quantities. The set of columns included here will depend on the 'return' argument:
if return == 'median'
, a pair of columns: .value
and .point
if return == 'quantiles'
, a pair of columns: .value
and quantile
if return == 'intervals'
, a set of columns: .value
, .width
, .lower
, and .upper
containing the median estimate (.value) along with the lower (.lower) and upper (.upper) bounds for the 50, 80, and 90 percent credible intervals (.width).
In addition, columns .point
and .interval
describe the type of point estimate ('median') and interval ('qi')
This data structure mimics that returned by median_qi
function in the tidybayes
package.
if return == 'draws'
, a set of columns: .value
, .chain
, .iteration
, and .draw
describing the predicted quantities for each draw, chain and iteration. This data structure mimics the draws_df
format from the posterior
package.
## Not run:
library(tidybayes)
library(tidyverse)
login()
# ---- Plot median predicted hazard over time ----
d <- fetch_predicted_hazard(run_id, level = 'overall')
ggplot(d, aes(x = survival_time, y = .value)) +
geom_line() +
scale_y_continuous('Predicted Hazard', labels = scales::comma)
# ---- Plot predicted hazard over time from intervals ----
d <- fetch_predicted_hazard(run_id, level = 'overall', return = 'intervals')
ggplot(d, aes(x = survival_time, y = .value, ymin = .lower, ymax = .upper, group = .width)) +
geom_lineribbon(alpha = 0.2) +
scale_y_continuous('Predicted Hazard', labels = scales::comma) +
scale_fill_brewer()
# ---- Plot predicted hazard by trial-arm over time ----
d <- fetch_predicted_hazard(run_id, level = 'trial_arm', return = 'intervals') %>%
inner_join(fetch_subjects() %>% distinct(trial_arm_id, trial_arm_name))
ggplot(d, aes(x = survival_time, y = .value, ymin = .lower, ymax = .upper, group = .width,
fill = trial_arm_name, colour = trial_arm_name)) +
geom_lineribbon(alpha = 0.2) +
scale_y_continuous('Predicted Hazard', labels = scales::comma) +
theme(legend.position = 'bottom') +
facet_wrap(~ trial_arm_name)
# ----Plot predicted hazard over time from draws ----
d <- fetch_predicted_hazard(run_id, level = 'overall', return = 'draws')
ggplot(d, aes(x = survival_time, y = .value)) +
stat_lineribbon(alpha = 0.4, .width = c(0.66, 0.99)) +
scale_y_continuous('Predicted Hazard', labels = scales::comma) +
scale_fill_brewer() +
theme_minimal()
# ---- summarize sampling quality ----
library(posterior)
d <- fetch_predicted_hazard(run_id, level = 'overall', return = 'draws')
d %>% spread(.variable, .value) %>%
group_by(.level, survival_time, .type, run_id) %>%
group_modify(~ summarise_draws(.x))
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.