library(ready4) library(ready4use) library(youthu)
This vignette outlines a workflow for:
The practical value of implementing such a workflow is discussed in the economic analysis vignette and a scientific manuscript. Note, this example uses fake data - it should should not be used to inform decision making.
To identify datasets that contain transfer to utility models compatible with youthu (ie those developped with the TTU package), you can use the get_ttu_dv_dss
function. The function searches specified dataverses (in the below example, the TTU dataverse) for datasets containing output from the TTU package.
ttu_dv_dss_tb <- get_ttu_dv_dss("TTU")
The ttu_dv_dss_tb
table summarises some pertinent details about each dataset containing TTU models found by the preceding command. These details include a link to any scientific summary (the "Article" column) associated with a dataset.
ttu_dv_dss_tb[,c(1:3,5)] %>% ready4show::print_table(output_type_1L_chr = params$output_type_1L_chr, caption_1L_chr = knitr::opts_current$get("tab.cap"), use_lbls_as_col_nms_1L_lgl = T, mkdn_tbl_ref_1L_chr = paste0("tab:",knitr::opts_current$get("tab.id")), add_to_row_ls = NULL, scroll_box_args_ls = list(width = "100%"))
To identify models that predict a specified type of health utility from one or more of a specified subset of predictors, use:
mdls_lup <- get_mdls_lup(ttu_dv_dss_tb = ttu_dv_dss_tb, utility_type_chr = "AQoL-6D", mdl_predrs_in_ds_chr = c("PHQ9 total score", "SOFAS total score"))
The preceding command will produce a lookup table with information that includes the catalogue names of models, the predictors used in each model and the analysis that generated each one.
mdls_lup[,c(1,2,5)] %>% ready4use::add_labels_from_dictionary(dictionary_tb = tibble::tibble(var_nm_chr = names(mdls_lup)[c(1,2,5)], var_desc_chr = c("Catalogue reference", "Predictors", "Analysis"))) %>% ready4show::print_table(output_type_1L_chr = params$output_type_1L_chr, caption_1L_chr = knitr::opts_current$get("tab.cap"), use_lbls_as_col_nms_1L_lgl = T, mkdn_tbl_ref_1L_chr = paste0("tab:",knitr::opts_current$get("tab.id")), add_to_row_ls = NULL, scroll_box_args_ls = list(width = "100%"))
To review the summary information about the predictive performance of a specific model, use:
get_dv_mdl_smrys(mdls_lup, mdl_nms_chr = "PHQ9_SOFAS_1_OLS_CLL")
More information about a selected model can be found in the online model catalogue, the link to which can be obtained with the following command:
get_mdl_ctlg_url(mdls_lup, mdl_nm_1L_chr = "PHQ9_SOFAS_1_OLS_CLL")
You can now import and inspect the dataset you plan on using for prediction. In the below example we use fake data.
data_tb <- make_fake_ds_one()
data_tb %>% head() %>% ready4show::print_table(output_type_1L_chr = params$output_type_1L_chr, caption_1L_chr = knitr::opts_current$get("tab.cap"), mkdn_tbl_ref_1L_chr = paste0("tab:",knitr::opts_current$get("tab.id")), add_to_row_ls = NULL, scroll_box_args_ls = list(width = "100%"))
The prediction dataset must contain variables that correspond to all the predictors of the model you intend to apply. The allowable range and required class of each predictor variable are described in the min_val_dbl
, max_val_dbl
and class_chr
columns of the model predictors lookup table, which can be accessed with a call to the get_predictors_lup
function.
predictors_lup <- get_predictors_lup(mdls_lup = mdls_lup, mdl_nm_1L_chr = "PHQ9_SOFAS_1_OLS_CLL")
predictors_lup %>% ready4show::print_table(output_type_1L_chr = params$output_type_1L_chr, caption_1L_chr = knitr::opts_current$get("tab.cap"), mkdn_tbl_ref_1L_chr = paste0("tab:",knitr::opts_current$get("tab.id")), add_to_row_ls = NULL, scroll_box_args_ls = list(width = "100%"))
The prediction dataset must also include both a unique client identifier variable and a measurement time-point identifier variable (which must be a factor
{.R} with two levels). The dataset also needs to be in long format (ie where measures at different time-points for the same individual are stacked on top of each other in separate rows). We can confirm these conditions hold by creating a dataset metadata object using the make_predn_metadata_ls
function. In creating the metadata object, the function checks that the dataset can be used in conjunction with the model specified at the mdl_nm_1L_chr
argument. If the prediction dataset uses different variable names for the predictors to those specified in the predictors_lup
{.R} lookup table, a named vector detailing the correspondence between the two sets of variable names needs to be passed to the predr_vars_nms_chr
argument. Finally, if you wish to specify a preferred variable name to use for the predicted utility values when applying the model, you can do this by passing this name to the utl_var_nm_1L_chr
argument.
predn_ds_ls <- make_predn_metadata_ls(data_tb, id_var_nm_1L_chr = "UID", msrmnt_date_var_nm_1L_chr = "Date", predr_vars_nms_chr = c(PHQ9 = "PHQ_total",SOFAS = "SOFAS_total"), round_var_nm_1L_chr = "Timepoint", round_bl_val_1L_chr = "Baseline", utl_var_nm_1L_chr = "AQoL6D_HU", mdls_lup = mdls_lup, mdl_nm_1L_chr = "PHQ9_SOFAS_1_OLS_CLL")
To generate utility predictions we use the add_utl_predn
{.R} function. The function needs to be supplied with the prediction dataset (the value passed to argument data_tb
) and the validated prediction metadata object we created in the previous step.
data_tb <- add_utl_predn(data_tb, predn_ds_ls = predn_ds_ls)
By default the add_utl_predn
{.R} function samples model parameter values based on a table of model coefficients when making predictions and constrains predictions to an allowed range. You can override these defaults by adding additional arguments new_data_is_1L_chr = "Predicted"
(which uses mean parameter values), force_min_max_1L_lgl = F
(removes range constraint) and (if the source dataset makes available downloadable model objects) make_from_tbl_1L_lgl = F
. These settings will produce different predictions. It is strongly recommended that you consult the model catalogue (see above) to understand how such decisions may affect the validity of the predicted values that will be generated.
data_tb %>% head() %>% ready4show::print_table(output_type_1L_chr = params$output_type_1L_chr, caption_1L_chr = knitr::opts_current$get("tab.cap"), mkdn_tbl_ref_1L_chr = paste0("tab:",knitr::opts_current$get("tab.id")), add_to_row_ls = NULL, scroll_box_args_ls = list(width = "100%"))
Our health utility predictions are now available for use and are summarised below.
summary(data_tb$AQoL6D_HU)
The last step is to calculate Quality Adjusted Life Years, using a method assuming a linear rate of change between timepoints.
data_tb <- data_tb %>% add_qalys_to_ds(predn_ds_ls = predn_ds_ls, include_predrs_1L_lgl = F, reshape_1L_lgl = F)
data_tb %>% head() %>% ready4show::print_table(output_type_1L_chr = params$output_type_1L_chr, caption_1L_chr = knitr::opts_current$get("tab.cap"), mkdn_tbl_ref_1L_chr = paste0("tab:",knitr::opts_current$get("tab.id")), add_to_row_ls = NULL, scroll_box_args_ls = list(width = "100%"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.