3 Using the Package in R
3.1 Installation
If you do not have R installed on your computer, please go to Appendix 1. Once you have R installed, you can install this package in the R console:
3.2 ACCEPT Prediction Functions
Sample Data
To get started, there is an R data frame with the package of sample patient data. I have printed columns 1-13 and 14-19 separately because there isn’t enough space:
library(accept)
samplePatients = accept::samplePatients
print(samplePatients[,1:13])
> # A tibble: 2 x 13
> ID male age smoker oxygen statin LAMA LABA ICS FEV1 BMI
> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
> 1 10001 1 70 1 1 1 1 1 1 33 25
> 2 10002 0 42 0 1 0 1 1 0 40 35
> # … with 2 more variables: SGRQ <dbl>, LastYrExacCount <dbl>
print(samplePatients[,14:19])
> # A tibble: 2 x 6
> LastYrSevExacCo… randomized_azit… randomized_stat… randomized_LAMA
> <dbl> <dbl> <dbl> <dbl>
> 1 1 0 0 0
> 2 0 0 0 0
> # … with 2 more variables: randomized_LABA <dbl>, randomized_ICS <dbl>
Exacerbation Rate
To get a prediction for exacerbation rate, you will need to pass in a patient vector:
results <- predictACCEPT(samplePatients[1,])
print(t(results))
> [,1]
> ID "10001"
> male "1"
> age "70"
> smoker "1"
> oxygen "1"
> statin "1"
> LAMA "1"
> LABA "1"
> ICS "1"
> FEV1 "33"
> BMI "25"
> SGRQ "50"
> LastYrExacCount "2"
> LastYrSevExacCount "1"
> randomized_azithromycin "0"
> randomized_statin "0"
> randomized_LAMA "0"
> randomized_LABA "0"
> randomized_ICS "0"
> predicted_exac_probability "0.7799"
> predicted_exac_rate "1.813428"
> azithromycin_predicted_exac_probability "0.703674"
> azithromycin_predicted_exac_rate "1.406447"
> predicted_severe_exac_probability "0.4394301"
> predicted_severe_exac_rate "0.7688124"
> azithromycin_predicted_severe_exac_probability "0.425913"
> azithromycin_predicted_severe_exac_rate "0.577342"
> predicted_exac_probability_lower_PI "0.4425521"
> predicted_exac_probability_upper_PI "0.9806575"
> predicted_exac_rate_lower_PI "0.5843924"
> predicted_exac_rate_upper_PI "3.945464"
> azithromycin_predicted_exac_probability_lower_PI "0.3644317"
> azithromycin_predicted_exac_probability_upper_PI "0.9531118"
> azithromycin_predicted_exac_rate_lower_PI "0.4532394"
> azithromycin_predicted_exac_rate_upper_PI "3.059998"
> predicted_severe_exac_probability_lower_PI "0.06018855"
> predicted_severe_exac_probability_upper_PI "0.904737"
> predicted_severe_exac_rate_lower_PI "0.07760276"
> predicted_severe_exac_rate_upper_PI "2.254686"
> azithromycin_predicted_severe_exac_probability_lower_PI "0.05621219"
> azithromycin_predicted_severe_exac_probability_upper_PI "0.898296"
> azithromycin_predicted_severe_exac_rate_lower_PI "0.05628177"
> azithromycin_predicted_severe_exac_rate_upper_PI "1.701869"
> predicted_exac_probability_lower_CI "0.7705132"
> predicted_exac_probability_upper_CI "0.7892394"
> predicted_exac_rate_lower_CI "1.760126"
> predicted_exac_rate_upper_CI "1.868583"
> azithromycin_predicted_exac_probability_lower_CI "0.6931493"
> azithromycin_predicted_exac_probability_upper_CI "0.7142844"
> azithromycin_predicted_exac_rate_lower_CI "1.365329"
> azithromycin_predicted_exac_rate_upper_CI "1.447842"
> predicted_severe_exac_probability_lower_CI "0.4235962"
> predicted_severe_exac_probability_upper_CI "0.4542333"
> predicted_severe_exac_rate_lower_CI "0.7323719"
> predicted_severe_exac_rate_upper_CI "0.8092376"
> azithromycin_predicted_severe_exac_probability_lower_CI "0.4116278"
> azithromycin_predicted_severe_exac_probability_upper_CI "0.4400719"
> azithromycin_predicted_severe_exac_rate_lower_CI "0.5519708"
> azithromycin_predicted_severe_exac_rate_upper_CI "0.6030546"
The predictACCEPT() function returns a data frame with the original patient data, along with the predictions for different treatment options. Here is a summary of the results:
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.
Probability of N Exacerbations (Poisson)
We can also calculate the predicted number of exacerbations in a year:
patientResults = predictACCEPT(samplePatients[1,])
exacerbationsMatrix = predictCountProb(patientResults, n = 10, shortened = TRUE)
print(exacerbationsMatrix)
> none severe 1 severe 2 severe 3 or more severe
> no exacerbations 0.16312494 0.00000000 0.00000000 0.00000000
> 1 exacerbation 0.16160772 0.13417676 0.00000000 0.00000000
> 2 exacerbations 0.08005231 0.13292879 0.05518286 0.00000000
> 3 or more exacerbations 0.03452944 0.09424771 0.09342959 0.04074374
The shortened parameter groups the probabilities from 3-10 exacerbations into one category, “3 or more exacerbations.” To see all n exacerbation probabilities:
exacerbationsMatrix = predictCountProb(patientResults, n = 10, shortened = FALSE)
print(exacerbationsMatrix)
> 0 severe 1 severe 2 severe
> 0 exacerbation(s) 0.1631249390163 0.000000000000 0.00000000000
> 1 exacerbation(s) 0.1616077243627 0.134176756503 0.00000000000
> 2 exacerbation(s) 0.0800523106129 0.132928787049 0.05518286197
> 3 exacerbation(s) 0.0264359163925 0.065846212439 0.05466960969
> 4 exacerbation(s) 0.0065475094051 0.021744593672 0.02708056557
> 5 exacerbation(s) 0.0012973222875 0.005385587148 0.00894289698
> 6 exacerbation(s) 0.0002142093293 0.001067099229 0.00221492992
> 7 exacerbation(s) 0.0000303167117 0.000176195701 0.00043886580
> 8 exacerbation(s) 0.0000037543422 0.000024936702 0.00007246399
> 9 exacerbation(s) 0.0000004132693 0.000003088096 0.00001025572
> 3 severe 4 severe 5 severe 6 severe
> 0 exacerbation(s) 0.00000000000 0.00000000000 0.00000000000 0.00000000000
> 1 exacerbation(s) 0.00000000000 0.00000000000 0.00000000000 0.00000000000
> 2 exacerbation(s) 0.00000000000 0.00000000000 0.00000000000 0.00000000000
> 3 exacerbation(s) 0.01513003362 0.00000000000 0.00000000000 0.00000000000
> 4 exacerbation(s) 0.01498931014 0.00311126375 0.00000000000 0.00000000000
> 5 exacerbation(s) 0.00742494776 0.00308232608 0.00051182766 0.00000000000
> 6 exacerbation(s) 0.00245196293 0.00152682878 0.00050706718 0.00007016644
> 7 exacerbation(s) 0.00060728935 0.00050420928 0.00025117549 0.00006951382
> 8 exacerbation(s) 0.00012032820 0.00012487992 0.00008294644 0.00003443364
> 9 exacerbation(s) 0.00001986817 0.00002474368 0.00002054374 0.00001137113
> 7 severe 8 severe 9 severe
> 0 exacerbation(s) 0.000000000000 0.0000000000000 0.000000e+00
> 1 exacerbation(s) 0.000000000000 0.0000000000000 0.000000e+00
> 2 exacerbation(s) 0.000000000000 0.0000000000000 0.000000e+00
> 3 exacerbation(s) 0.000000000000 0.0000000000000 0.000000e+00
> 4 exacerbation(s) 0.000000000000 0.0000000000000 0.000000e+00
> 5 exacerbation(s) 0.000000000000 0.0000000000000 0.000000e+00
> 6 exacerbation(s) 0.000000000000 0.0000000000000 0.000000e+00
> 7 exacerbation(s) 0.000008244955 0.0000000000000 0.000000e+00
> 8 exacerbation(s) 0.000008168270 0.0000008477255 0.000000e+00
> 9 exacerbation(s) 0.000004046149 0.0000008398409 7.747644e-08
To visualize the matrix as a heatmap, we can use the function plotHeatMap: