-
Notifications
You must be signed in to change notification settings - Fork 0
/
V_01.Rmd
138 lines (109 loc) · 6.28 KB
/
V_01.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
---
title: "Predict health utility from psychological measures (PHQ-9 and GAD-7)"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Predict health utility from psychological measures (PHQ-9 and GAD-7)}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
**This vignette article is abridged and modified version of [another article on predicting Quality Adjusted Life Years with youthu](https://ready4-dev.github.io/youthu/articles/Prediction_With_Mdls.html).**
## Motivation
This article illustrates how to make QALY predictions using a dataset in wide format with no health-utility measures but containing two psychological measures (GAD-7 and PHQ-9).
## Install youthu
If not already installed it will be necessary to install the `youthu` R library. As `youthu` is not yet available on CRAN, it will be necessary to install it directly from its GitHub repository using an R package like `remotes` or `devtools`.
```{r eval=FALSE}
# Uncomment and run if installation is required.
# utils::install.packages("devtools")
# devtools::install_github("ready4-dev/youthu")
```
## Load required packages
We now load the libraries we will be using in subsequent steps. Note, both the `ready4`, `ready4show` and `ready4use` [ready4 framework](https://www.ready4-dev.com/) libraries will have been installed automatically when `youthu` was installed. The `specific` readyforwhatsnext module library and `dplyr`, `purrr`, `stringr` and `tidyr` CRAN libraries will have been installed at the same time.
```{r message=FALSE}
library(ready4)
library(ready4show)
library(ready4use)
library(specific)
library(youthu)
```
## Specify data sources
We begin by specifying the sources for our data. In this example, our data sources are online repositories.
```{r}
X <- Ready4useRepos(dv_nm_1L_chr = "fakes", dv_ds_nm_1L_chr = "https://doi.org/10.7910/DVN/HJXYKQ",
dv_server_1L_chr = "dataverse.harvard.edu",
gh_repo_1L_chr = "ready4-dev/youthu", gh_tag_1L_chr = "v0.0.0.91125")
```
## Inspect dataset
We can now inspect the dataset we will be using to make predictions. As this is a demonstration article we are going to create a custom synthetic dataset. Our first step in doing so is to ingest a preexisting synthetic dataset (in long format) using the method explained in [another vignette article](https://ready4-dev.github.io/ready4use/articles/V_03.html)
```{r}
data_tb <- ingest(X, fls_to_ingest_chr = c("ymh_phq_gad_tb"), metadata_1L_lgl = F)
```
```{r echo=FALSE, eval = FALSE}
# Alternatively
# data_tb <- ingest(X, fls_to_ingest_chr = c("ymh_clinical_tb"), metadata_1L_lgl = F)
# data_tb <- data_tb %>% dplyr:: select(c("fkClientID", "round",
# "d_interview_date",
# "gad7_total", "phq9_total")) %>%
# tidyr::pivot_wider(names_from = c("round"),
# values_from = c("d_interview_date", "gad7_total", "phq9_total")) %>%
# dplyr::rename_with(~stringr::str_replace(.x,"_Baseline","_t1") %>%
# stringr::str_replace("_Follow-up","_t2") %>%
# stringr::str_replace("_total",""))
```
Our resulting dataset has unique IDs for each participant (character class), timestamps for each data collection timepoint (Date class variables) and GAD-7 and PHQ-9 scores for each timepoint (integer class).
```{r }
data_tb %>% head() %>% ready4show::print_table(caption_1L_chr = "Dataset", output_type_1L_chr = "HTML")
```
## Get mapping models
We retrieve details of relevant AQoL-6D mapping models for wither of the predictors we plan on using. How these models were derived is described in a [pre-print](https://doi.org/10.1101/2021.07.07.21260129) and details of model performance is included in catalogues available in an [open access data repository](https://doi.org/10.7910/DVN/DKDIB0).
```{r}
mdls_lup <- get_mdls_lup(ttu_dv_dss_tb = get_ttu_dv_dss("TTU"),
utility_type_chr = "AQoL-6D",
mdl_predrs_in_ds_chr = c("GAD7 total score", "PHQ9 total score"))
```
```{r }
mdls_lup[,c(1,2,5)] %>%
ready4show::print_table(caption_1L_chr = "Available models", output_type_1L_chr = "HTML")
```
We select our preferred model and retrieve summary data about the model's predictor variables.
```{r }
predictors_lup <- get_predictors_lup(mdls_lup = mdls_lup, mdl_nm_1L_chr = "GAD7_PHQ9_1_OLS_CLL")
```
```{r }
exhibit(predictors_lup)
```
## Transform prediction dataset
To be used with the mapping models available to us, our prediction dataset needs to be in long format. We perform the necessary transformation.
```{r}
data_tb <- transform_ds_to_long(data_tb, predictors_chr = c("gad7", "phq9"),
msrmnt_date_var_nm_1L_chr = "d_interview_date", round_var_nm_1L_chr = "When")
```
We drop records where we are missing data for either GAD7 or PHQ9 at either timepoint.
```{r}
data_tb <- transform_ds_to_drop_msng(data_tb, predictors_chr = c("gad7", "phq9"),
uid_var_nm_1L_chr = "fkClientID")
```
We now predict AQoL-6D health utility for each case with complete data.
```{r}
predn_ds_ls <- make_predn_metadata_ls(data_tb,
id_var_nm_1L_chr = "fkClientID",
msrmnt_date_var_nm_1L_chr = "d_interview_date",
predr_vars_nms_chr = c(GAD7 = "gad7", PHQ9 = "phq9"),
round_var_nm_1L_chr = "When",
round_bl_val_1L_chr = "t1",
utl_var_nm_1L_chr = "AQoL6D_HU",
mdls_lup = mdls_lup,
mdl_nm_1L_chr = "GAD7_PHQ9_1_OLS_CLL")
data_tb <- add_utl_predn(data_tb, new_data_is_1L_chr = "Predicted", predn_ds_ls = predn_ds_ls)
```
Finally, we derive QALY predictions from the health utility measures at both time-points.
```{r}
data_tb <- data_tb %>% add_qalys_to_ds(predn_ds_ls = predn_ds_ls, include_predrs_1L_lgl = F, reshape_1L_lgl = T)
```
```{r }
data_tb %>% head() %>%
ready4show::print_table(caption_1L_chr = "Final dataset", output_type_1L_chr = "HTML",
scroll_box_args_ls = list(width = "100%"))
```