-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathREADME.Rmd
More file actions
214 lines (148 loc) · 8.76 KB
/
README.Rmd
File metadata and controls
214 lines (148 loc) · 8.76 KB
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# accept
<!-- badges: start -->
[](https://github.com/resplab/accept/actions/workflows/R-CMD-check.yaml)
[](https://cran.r-project.org/package=accept) [](https://cran.r-project.org/package=accept) [](https://www.repostatus.org/#active)
<!-- badges: end -->
R package for the ACute COPD Exacerbation Prediction Tool (ACCEPT)
ACCEPT is a prediction model for predicting probability, rate, and severity of exacerbations (also known as lung attacks) in patients with Chronic Obstructive Pulmonary Disease.
ACCEPT has been developed by researchers at the University of British Columbia. Please refer to the published papers for more information:
Adibi A, Sin DD, Safari A, Jonhson KM, Aaron SD, FitzGerald JM, Sadatsafavi M. The Acute COPD Exacerbation Prediction Tool (ACCEPT): a modelling study. The Lancet Respiratory Medicine, Volume 8, Issue 10, 1013 - 1021; [doi:10.1016/S2213-2600(19)30397-2](https://doi.org/10.1016/S2213-2600(19)30397-2)
Safari, A., Adibi, A., Sin, D.D., Lee, T.Y., Ho, J.K., Sadatsafavi, M. and IMPACT study team, 2022. ACCEPT 2· 0: Recalibrating and externally validating the Acute COPD exacerbation prediction tool (ACCEPT). EClinicalMedicine, 51, p.101574. [doi:10.1016/j.eclinm.2022.101574](http://doi.org/10.1016/j.eclinm.2022.101574)
The following animation explains the `accept` model in 90 seconds:
[](https://www.youtube.com/watch?v=UuGLN128Z3Y)
## Installation
The latest stable version can be downloaded from CRAN:
`install.packages('accept')`
You can install the development version of accept from [GitHub](https://github.com/) with:
``` r
# install.packages("pak")
pak::pak("resplab/accept")
```
## Usage
The function `accept()` provides predictions from the latest version of the `accept` prediction model. `accept1()` provides predictions of exacerbations for COPD patients per original published manuscript. `accept2()` is an updated version of ACCEPT that is fine tuned for improved predictions in patients who do not have a prior history of exacerbations.
### Country-Specific Calibration in ACCEPT v3 (accept3)
ACCEPT v3 (exposed via `accept(..., version = "accept3")` or the default `accept()` when a `country` is specified) provides country-specific recalibrated predictions based on the NOVELTY study. Important notes:
- The `country` parameter is required for `accept3` and must be a three-letter ISO country code (for example, `"CAN"`, `"USA"`, `"GBR"`). For countries not in the supported list you should provide an observed moderate-to-severe risk via the `obs_modsev_risk` column in your input data.
- When `accept3` is called a message is printed to inform the user of the underlying method: `ACCEPT v3 is recalibrated using a Cox model`.
- `accept3` returns the same core prediction columns as `accept2`: `predicted_exac_probability`, `predicted_exac_rate`, `predicted_severe_exac_probability`, and `predicted_severe_exac_rate`.
- Rates are derived from the returned probabilities using the transformation `rate = -log(1 - p)`.
Example:
```{r}
# explicit country is required for accept3
library(accept)
accept(samplePatients, country = "CAN")
```
ACCEPT v3 manuscript is currently under review.
## Example
### Exacerbation Prediction
To get a prediction for exacerbation rate, you will need to pass in a patient vector. The accept package comes with a sample patient data tibble called `samplePatients`:
```{r}
library(accept)
accept(samplePatients, country="CAN") #accept uses the latest updated prediction model
```
Here's another example with a specific patient profile:
```{r}
# Create a patient tibble with specific properties
patient <- tibble::tibble(
ID = "10003",
age = 65,
male = 1,
BMI = 25.5,
smoker = 1, # 0=never, 1=former, 2=current
FEV1 = 45.0, # % predicted
SGRQ = 45.0,
oxygen = 0,
LastYrExacCount = 2,
LastYrSevExacCount = 1,
statin = 1,
LAMA = 1,
LABA = 1,
ICS = 1
)
# Get predictions for this patient
accept(patient, country="CAN")
```
**accept2()** and **accept1()** functions return a more detailed dataframe with the predictions for different treatment options with measures of uncertainty.
To visualize the data, there is a graphing function called **plotExacerbations()**, which creates a Plotly bar graph. You have the option of selecting **probability** or **rate** for which prediction you want to see, and either **CI** or **PI** to select the confidence interval or prediction interval respectively.
```{r, eval=FALSE}
results <- accept2(samplePatients[1,])
plotExacerbations(results, type="probability")
plotExacerbations(results, type="rate")
```


### Probability of N Exacerbations (Poisson)
You can also calculate the predicted number of exacerbations in a year:
```{r}
results <- accept2(samplePatients[1,])
exacerbationsMatrix <- predictCountProb(results, n = 10, shortened = TRUE)
print(exacerbationsMatrix)
```
The shortened parameter groups the probabilities from 3-10 exacerbations into one category, "3 or more exacerbations." To see all n exacerbation probabilities:
```{r}
exacerbationsMatrix <- predictCountProb(results, n = 10, shortened = FALSE)
print(exacerbationsMatrix)
```
To visualize the matrix as a heatmap, we can use the function **plotHeatMap**:
```{r, eval=FALSE}
plotHeatMap(results, shortened = FALSE)
```

## Web App for ACCEPT
ACCEPT is also available as web app, accessible at <http://resp.core.ubc.ca/ipress/accept>

## API using vetiver and plumber
You can use vetiver and plumber packages to create, deploy, and monitor an API for ACCEPT:
```{r}
library(vetiver)
v_accept <- vetiver_model(accept,
"accept-model")
```
To test to API locally, you can use
```{r, eval=FALSE}
library(plumber)
pr() |>
vetiver_api(v_accept) |>
pr_run()
```
## Cloud-based API Access through Peer Models Network
The [Peer Models Network](https://resp.core.ubc.ca/show/pmnintro) allows users to access ACCEPT through the cloud. A MACRO-enabled Excel-file can be used to interact with the model and see the results. To download the PRISM Excel template file for ACCEPT, please refer to the [Peer Models Network model repository](https://models.peermodelsnetwork.com).
#### Python
```
import json
import requests
url = 'https://prism.peermodelsnetwork.com/route/accept/run'
headers = {'x-prism-auth-user': YOUR_API_KEY}
model_run = requests.post(url, headers=headers,
json = {"func":["prism_model_run"],"model_input":[{"ID": "10001","male": 1,"age": 57,"smoker": 0,"oxygen": 0,"statin": 0,"LAMA": 1,"LABA": 1,"ICS": 1,"FEV1": 51,"BMI": 18,"SGRQ": 63,"LastYrExacCount": 2,"LastYrSevExacCount": 1,"randomized_azithromycin": 0,"randomized_statin": 0,"randomized_LAMA": 0,"randomized_LABA": 0,"randomized_ICS": 0, "random_sampling_N" : 100, "calculate_CIs" : "TRUE"}]})
print(model_run)
results = json.loads(model_run.text)
print(results)
```
#### Linux Bash
In Ubuntu, you can call the API with `curl`:
```
curl \
-X POST \
-H "x-prism-auth-user: REPLACE_WITH_API_KEY" \
-H "Content-Type: application/json" \
-d '{"func":["prism_model_run"],"model_input":[{"ID": "10001","male": 1,"age": 57,"smoker": 0,"oxygen": 0,"statin": 0,"LAMA": 1,"LABA": 1,"ICS": 1,"FEV1": 51,"BMI": 18,"SGRQ": 63,"LastYrExacCount": 2,"LastYrSevExacCount": 1,"randomized_azithromycin": 0,"randomized_statin": 0,"randomized_LAMA": 0,"randomized_LABA": 0,"randomized_ICS": 0, "random_sampling_N" : 100,
"calculate_CIs" : "TRUE"}]}' \
https://prism.peermodelsnetwork.com/route/accept/run
```
## Citation
Please cite:
Adibi A, Sin DD, Safari A, Jonhson KM, Aaron SD, FitzGerald JM, Sadatsafavi M. The Acute COPD Exacerbation Prediction Tool (ACCEPT): a modelling study. The Lancet Respiratory Medicine. Volume 8, Issue 10, 1013 - 1021 [doi:10.1016/S2213-2600(19)30397-2](https://doi.org/10.1016/S2213-2600(19)30397-2)
Safari, A., Adibi, A., Sin, D.D., Lee, T.Y., Ho, J.K., Sadatsafavi, M. and IMPACT study team, 2022. ACCEPT 2· 0: Recalibrating and externally validating the Acute COPD exacerbation prediction tool (ACCEPT). EClinicalMedicine, 51, p.101574. [doi:10.1016/j.eclinm.2022.101574](http://doi.org/10.1016/j.eclinm.2022.101574)