---
title: "Setup"
format: html
---
The code in this script imports libraries, initializes constants, and performs other such preparatory work for the main analysis.
```{r, include=FALSE}
#Ensures pipe works
library(tidyverse)
library(gt)
```
::: Rcode
### Source code
The full R script is available at:
- [ `R/setup.R` ](https://github.com/VagishHemmige/Cryptococcus-cost_analysis/blob/master/R/setup.R)
:::
## Libraries
The analysis relies on a set of open-source R packages for data management, cohort construction, visualization, and statistical modeling. These libraries were selected based on their stability, community support, and suitability for large-scale longitudinal health data.
```{r eval=FALSE}
# Libraries necessary for the analysis
#Data management libraries
library(tidyverse)
library(lubridate)
#Core library for the USRDS
library(usRds)
#Flowchart libraries
library(strobe)
library(flowchart)
#Table libraries
library(gt)
library(gtsummary)
#Plotting libraries
library(ggplot2)
library(ggbeeswarm)
library(patchwork)
#Statistical modeling libraries
library(glmmTMB)
library(emmeans)
library(geepack)
library(broom)
library(broom.mixed)
library(multcomp)
```
The table below lists the required packages along with links to their primary documentation.
```{r, echo=FALSE}
libraries_table <- tibble::tibble(
Category = c(
"Data management",
"Data management",
"USRDS-specific",
"Flowcharting",
"Flowcharting",
"Tables",
"Tables",
"Plotting",
"Plotting",
"Plotting",
"Statistical modeling",
"Statistical modeling",
"Statistical modeling",
"Statistical modeling",
"Statistical modeling",
"Statistical modeling"
),
Package = c(
"tidyverse",
"lubridate",
"usRds",
"strobe",
"flowchart",
"gt",
"gtsummary",
"ggplot2",
"ggbeeswarm",
"patchwork",
"glmmTMB",
"emmeans",
"geepack",
"broom",
"broom.mixed",
"multcomp"
),
Documentation = c(
"[tidyverse.org](https://www.tidyverse.org/)",
"[lubridate.tidyverse.org](https://lubridate.tidyverse.org/)",
"[GitHub – usRds](https://github.com/USRDS/usRds)",
"[GitHub – strobe](https://github.com/vagishhemmige/strobe)",
"[CRAN – flowchart](https://cran.r-project.org/package=flowchart)",
"[gt documentation](https://gt.rstudio.com/)",
"[gtsummary documentation](https://www.danieldsjoberg.com/gtsummary/)",
"[ggplot2.tidyverse.org](https://ggplot2.tidyverse.org/)",
"[CRAN – ggbeeswarm](https://cran.r-project.org/package=ggbeeswarm)",
"[patchwork documentation](https://patchwork.data-imaginist.com/)",
"[CRAN – glmmTMB](https://cran.r-project.org/package=glmmTMB)",
"[CRAN – emmeans](https://cran.r-project.org/package=emmeans)",
"[CRAN – geepack](https://cran.r-project.org/package=geepack)",
"[broom documentation](https://broom.tidymodels.org/)",
"[broom.mixed documentation](https://broom.tidymodels.org/)",
"[CRAN – multcomp](https://cran.r-project.org/package=multcomp)"
)
)
libraries_table |>
gt::gt() |>
gt::fmt_markdown(columns = "Documentation") |>
gt::cols_label(
Category = "Category",
Package = "R package",
Documentation = "Documentation"
) |>
gt::tab_header(
title = "Required R Packages",
subtitle = "Libraries used for data processing, visualization, and statistical modeling"
)|>
gt::tab_style(
style = gt::cell_text(font = "mono"),
locations = gt::cells_body(columns = Package)
)
```
## Constants
A number of analysis parameters are reused across cohort construction, matching, and cost modeling steps.
These constants are defined in the `R/setup.R` file.
```{r}
#Constants
censor_date<- as.Date ("2022-01-01" )
minimum_followup<- 1 #Minimum followup in days
maximum_followup<- 365 #Maximum followup in days
number_controls_per_case<- 2 #Number of controls per case
inflation_month<- "January"
inflation_year<- 2021
baseline_months_cost<- 3 #N
full_months <- - baseline_months_cost: 11 #Range of months for longitudinal analysis
```
For clarity, these constants are summarized below along with brief explanations of their role in the analysis.
```{r, echo=FALSE}
constants_table <- tibble::tibble(
Constant = c(
"censor_date",
"minimum_followup",
"maximum_followup",
"number_controls_per_case",
"inflation_month",
"inflation_year",
"baseline_months_cost",
"full_months"
),
Value = c(
as.character(censor_date),
as.character(minimum_followup),
as.character(maximum_followup),
as.character(number_controls_per_case),
inflation_month,
as.character(inflation_year),
as.character(baseline_months_cost),
paste(full_months, collapse = ", ")
),
Explanation = c(
"Administrative censoring date for follow-up",
"Minimum required follow-up time (days)",
"Maximum allowed follow-up time (days)",
"Number of matched controls per case",
"Reference month for cost inflation adjustment",
"Reference year for cost inflation adjustment",
"Number of months included in baseline cost window prior to index date",
"Month indices used for longitudinal cost analysis"
)
)
constants_table |>
gt::gt() |>
gt::tab_header(
title = "Analysis Constants",
subtitle = "Matching, follow-up, and cost-model parameters"
)
```
## Lists of ICD codes
Lists of ICD-9-CM and ICD-10-CM diagnosis codes were used to define cryptococcosis and relevant comorbid conditions. These code sets were curated prior to analysis and include both legacy ICD-9 codes and corresponding ICD-10 codes to allow consistent identification of conditions across the study period.
For appropriate references, see:
- [ https://cdn-links.lww.com/permalink/kn9/b/kn9_2025_06_05_roetker_1_sdc2.pdf ](https://cdn-links.lww.com/permalink/kn9/b/kn9_2025_06_05_roetker_1_sdc2.pdf)
```{r}
#Create list of ICD9 and ICD10 codes for cryptococcus
cryptococcus_ICD_list<- c ("1175" , "3210" , "B450" , "B451" , "B452" , "B453" , "B457" , "B458" , "B459" , "B45" )
comorbidity_ICD_list<- list ()
comorbidity_ICD_list[["cryptococcus" ]]<- c ("1175" , "3210" , "B450" , "B451" , "B452" , "B453" , "B457" , "B458" , "B459" , "B45" )
comorbidity_ICD_list[["HIV" ]]<- c ("042" ,
"07953" ,
"V08" ,
"79571" ,
"B20" ,
"Z21"
)
comorbidity_ICD_list[["Heart transplant" ]]<- c ("V421" , # ICD-9-CM: Heart transplant status
"Z941" ) # ICD-10-CM: Heart transplant status
comorbidity_ICD_list[["Heart-lung transplant" ]]<- c ("Z943" ) # ICD-10-CM: Heart and lungs transplant status
comorbidity_ICD_list[["Lung transplant" ]]<- c ("V426" , # ICD-9-CM: Lung transplant status
"Z942" ) # ICD-10-CM: Lung transplant status
comorbidity_ICD_list[["Pancreas transplant" ]]<- c ("V4283" , # ICD-9-CM: Pancreas transplant status
"Z9483" ) # ICD-10-CM: Pancreas transplant status
comorbidity_ICD_list[["Liver transplant" ]]<- c ("V427" , # ICD-9-CM: Liver transplant status
"Z944" ) # ICD-10-CM: Liver transplant status
comorbidity_ICD_list[["Intestinal transplant" ]]<- c ("V4284" , # ICD-9-CM: Intestinal transplant status
"Z9482" ) # ICD-10-CM: Intestinal transplant status
comorbidity_ICD_list[["cirrhosis" ]]<- c ("5712" , # Alcoholic cirrhosis of liver
"5715" , # Cirrhosis of liver without mention of alcohol
"5716" , # Biliary cirrhosis
"5722" , # Hepatic encephalopathy
"5723" , # Portal hypertension
"5724" , # Hepatorenal syndrome
"5728" , #Other sequelae of chronic liver disease#
"K7030" , # Alcoholic cirrhosis of liver with ascites
"K7031" , # Alcoholic cirrhosis of liver without ascites
"K7460" , # Unspecified cirrhosis of liver
"K7469" , # Other cirrhosis of liver
"K743" , # Primary biliary cirrhosis
"K744" , # Secondary biliary cirrhosis
"K745" , # Biliary cirrhosis, unspecified
"K7290" , # Hepatic failure, unspecified
"K7291" , # Acute and subacute hepatic failure with coma
"K766" , # Portal hypertension
"K767" ) # Hepatorenal syndrome
comorbidity_ICD_list[["CMV" ]] <- c (
"0785" , # Cytomegaloviral disease (ICD-9)
"B250" , # CMV pneumonitis
"B251" , # CMV hepatitis
"B252" , # CMV pancreatitis
"B258" , # Other CMV diseases
"B259" , # CMV disease, unspecified
"B2710" , # Cytomegaloviral mononucleosis without complication
"B2711" # Cytomegaloviral mononucleosis with complication
)
comorbidity_ICD_list[["Diabetes" ]]<- c ("25000" ,
"E0800" ,
"E0900" ,
"E1000" ,
"E1100" ,
"E1300" ,
"25001" ,
"E0801" ,
"E0901" ,
"E1001" ,
"E1101" ,
"E1301" ,
"25002" ,
"E0802" ,
"E0902" ,
"E1002" ,
"E1102" ,
"E1302" ,
"25003" ,
"E0803" ,
"E0903" ,
"E1003" ,
"E1103" ,
"E1303" ,
"25004" ,
"E0804" ,
"E0904" ,
"E1004" ,
"E1104" ,
"E1304" ,
"25005" ,
"E0805" ,
"E0905" ,
"E1005" ,
"E1105" ,
"E1305" ,
"25006" ,
"E0806" ,
"E0906" ,
"E1006" ,
"E1106" ,
"E1306" ,
"25007" ,
"E0807" ,
"E0907" ,
"E1007" ,
"E1107" ,
"E1307" ,
"25008" ,
"E0808" ,
"E0908" ,
"E1008" ,
"E1108" ,
"E1308" ,
"25009" ,
"E0809" ,
"E0909" ,
"E1009" ,
"E1109" ,
"E1309" ,
"25010" ,
"E0810" ,
"E0910" ,
"E1010" ,
"E1110" ,
"E1310" ,
"25011" ,
"E0811" ,
"E0911" ,
"E1011" ,
"E1111" ,
"E1311" ,
"25012" ,
"E0812" ,
"E0912" ,
"E1012" ,
"E1112" ,
"E1312" ,
"25013" ,
"E0813" ,
"E0913" ,
"E1013" ,
"E1113" ,
"E1313" ,
"25014" ,
"E0814" ,
"E0914" ,
"E1014" ,
"E1114" ,
"E1314" ,
"25015" ,
"E0815" ,
"E0915" ,
"E1015" ,
"E1115" ,
"E1315" ,
"25016" ,
"E0816" ,
"E0916" ,
"E1016" ,
"E1116" ,
"E1316" ,
"25017" ,
"E0817" ,
"E0917" ,
"E1017" ,
"E1117" ,
"E1317" ,
"25018" ,
"E0818" ,
"E0918" ,
"E1018" ,
"E1118" ,
"E1318" ,
"25019" ,
"E0819" ,
"E0919" ,
"E1019" ,
"E1119" ,
"E1319" ,
"25020" ,
"E0820" ,
"E0920" ,
"E1020" ,
"E1120" ,
"E1320" ,
"25021" ,
"E0821" ,
"E0921" ,
"E1021" ,
"E1121" ,
"E1321" ,
"25022" ,
"E0822" ,
"E0922" ,
"E1022" ,
"E1122" ,
"E1322" ,
"25023" ,
"E0823" ,
"E0923" ,
"E1023" ,
"E1123" ,
"E1323" ,
"25024" ,
"E0824" ,
"E0924" ,
"E1024" ,
"E1124" ,
"E1324" ,
"25025" ,
"E0825" ,
"E0925" ,
"E1025" ,
"E1125" ,
"E1325" ,
"25026" ,
"E0826" ,
"E0926" ,
"E1026" ,
"E1126" ,
"E1326" ,
"25027" ,
"E0827" ,
"E0927" ,
"E1027" ,
"E1127" ,
"E1327" ,
"25028" ,
"E0828" ,
"E0928" ,
"E1028" ,
"E1128" ,
"E1328" ,
"25029" ,
"E0829" ,
"E0929" ,
"E1029" ,
"E1129" ,
"E1329" ,
"25030" ,
"E0830" ,
"E0930" ,
"E1030" ,
"E1130" ,
"E1330" ,
"25031" ,
"E0831" ,
"E0931" ,
"E1031" ,
"E1131" ,
"E1331" ,
"25032" ,
"E0832" ,
"E0932" ,
"E1032" ,
"E1132" ,
"E1332" ,
"25033" ,
"E0833" ,
"E0933" ,
"E1033" ,
"E1133" ,
"E1333" ,
"25034" ,
"E0834" ,
"E0934" ,
"E1034" ,
"E1134" ,
"E1334" ,
"25035" ,
"E0835" ,
"E0935" ,
"E1035" ,
"E1135" ,
"E1335" ,
"25036" ,
"E0836" ,
"E0936" ,
"E1036" ,
"E1136" ,
"E1336" ,
"25037" ,
"E0837" ,
"E0937" ,
"E1037" ,
"E1137" ,
"E1337" ,
"25038" ,
"E0838" ,
"E0938" ,
"E1038" ,
"E1138" ,
"E1338" ,
"25039" ,
"E0839" ,
"E0939" ,
"E1039" ,
"E1139" ,
"E1339" ,
"25040" ,
"E0840" ,
"E0940" ,
"E1040" ,
"E1140" ,
"E1340" ,
"25041" ,
"E0841" ,
"E0941" ,
"E1041" ,
"E1141" ,
"E1341" ,
"25042" ,
"E0842" ,
"E0942" ,
"E1042" ,
"E1142" ,
"E1342" ,
"25043" ,
"E0843" ,
"E0943" ,
"E1043" ,
"E1143" ,
"E1343" ,
"25044" ,
"E0844" ,
"E0944" ,
"E1044" ,
"E1144" ,
"E1344" ,
"25045" ,
"E0845" ,
"E0945" ,
"E1045" ,
"E1145" ,
"E1345" ,
"25046" ,
"E0846" ,
"E0946" ,
"E1046" ,
"E1146" ,
"E1346" ,
"25047" ,
"E0847" ,
"E0947" ,
"E1047" ,
"E1147" ,
"E1347" ,
"25048" ,
"E0848" ,
"E0948" ,
"E1048" ,
"E1148" ,
"E1348" ,
"25049" ,
"E0849" ,
"E0949" ,
"E1049" ,
"E1149" ,
"E1349" ,
"25050" ,
"E0850" ,
"E0950" ,
"E1050" ,
"E1150" ,
"E1350" ,
"25051" ,
"E0851" ,
"E0951" ,
"E1051" ,
"E1151" ,
"E1351" ,
"25052" ,
"E0852" ,
"E0952" ,
"E1052" ,
"E1152" ,
"E1352" ,
"25053" ,
"E0853" ,
"E0953" ,
"E1053" ,
"E1153" ,
"E1353" ,
"25054" ,
"E0854" ,
"E0954" ,
"E1054" ,
"E1154" ,
"E1354" ,
"25055" ,
"E0855" ,
"E0955" ,
"E1055" ,
"E1155" ,
"E1355" ,
"25056" ,
"E0856" ,
"E0956" ,
"E1056" ,
"E1156" ,
"E1356" ,
"25057" ,
"E0857" ,
"E0957" ,
"E1057" ,
"E1157" ,
"E1357" ,
"25058" ,
"E0858" ,
"E0958" ,
"E1058" ,
"E1158" ,
"E1358" ,
"25059" ,
"E0859" ,
"E0959" ,
"E1059" ,
"E1159" ,
"E1359" ,
"25060" ,
"E0860" ,
"E0960" ,
"E1060" ,
"E1160" ,
"E1360" ,
"25061" ,
"E0861" ,
"E0961" ,
"E1061" ,
"E1161" ,
"E1361" ,
"25062" ,
"E0862" ,
"E0962" ,
"E1062" ,
"E1162" ,
"E1362" ,
"25063" ,
"E0863" ,
"E0963" ,
"E1063" ,
"E1163" ,
"E1363" ,
"25064" ,
"E0864" ,
"E0964" ,
"E1064" ,
"E1164" ,
"E1364" ,
"25065" ,
"E0865" ,
"E0965" ,
"E1065" ,
"E1165" ,
"E1365" ,
"25066" ,
"E0866" ,
"E0966" ,
"E1066" ,
"E1166" ,
"E1366" ,
"25067" ,
"E0867" ,
"E0967" ,
"E1067" ,
"E1167" ,
"E1367" ,
"25068" ,
"E0868" ,
"E0968" ,
"E1068" ,
"E1168" ,
"E1368" ,
"25069" ,
"E0869" ,
"E0969" ,
"E1069" ,
"E1169" ,
"E1369" ,
"25070" ,
"E0870" ,
"E0970" ,
"E1070" ,
"E1170" ,
"E1370" ,
"25071" ,
"E0871" ,
"E0971" ,
"E1071" ,
"E1171" ,
"E1371" ,
"25072" ,
"E0872" ,
"E0972" ,
"E1072" ,
"E1172" ,
"E1372" ,
"25073" ,
"E0873" ,
"E0973" ,
"E1073" ,
"E1173" ,
"E1373" ,
"25074" ,
"E0874" ,
"E0974" ,
"E1074" ,
"E1174" ,
"E1374" ,
"25075" ,
"E0875" ,
"E0975" ,
"E1075" ,
"E1175" ,
"E1375" ,
"25076" ,
"E0876" ,
"E0976" ,
"E1076" ,
"E1176" ,
"E1376" ,
"25077" ,
"E0877" ,
"E0977" ,
"E1077" ,
"E1177" ,
"E1377" ,
"25078" ,
"E0878" ,
"E0978" ,
"E1078" ,
"E1178" ,
"E1378" ,
"25079" ,
"E0879" ,
"E0979" ,
"E1079" ,
"E1179" ,
"E1379" ,
"25080" ,
"E0880" ,
"E0980" ,
"E1080" ,
"E1180" ,
"E1380" ,
"25081" ,
"E0881" ,
"E0981" ,
"E1081" ,
"E1181" ,
"E1381" ,
"25082" ,
"E0882" ,
"E0982" ,
"E1082" ,
"E1182" ,
"E1382" ,
"25083" ,
"E0883" ,
"E0983" ,
"E1083" ,
"E1183" ,
"E1383" ,
"25084" ,
"E0884" ,
"E0984" ,
"E1084" ,
"E1184" ,
"E1384" ,
"25085" ,
"E0885" ,
"E0985" ,
"E1085" ,
"E1185" ,
"E1385" ,
"25086" ,
"E0886" ,
"E0986" ,
"E1086" ,
"E1186" ,
"E1386" ,
"25087" ,
"E0887" ,
"E0987" ,
"E1087" ,
"E1187" ,
"E1387" ,
"25088" ,
"E0888" ,
"E0988" ,
"E1088" ,
"E1188" ,
"E1388" ,
"25089" ,
"E0889" ,
"E0989" ,
"E1089" ,
"E1189" ,
"E1389" ,
"25090" ,
"E0890" ,
"E0990" ,
"E1090" ,
"E1190" ,
"E1390" ,
"25091" ,
"E0891" ,
"E0991" ,
"E1091" ,
"E1191" ,
"E1391" ,
"25092" ,
"E0892" ,
"E0992" ,
"E1092" ,
"E1192" ,
"E1392" ,
"25093" ,
"E0893" ,
"E0993" ,
"E1093" ,
"E1193" ,
"E1393" ,
"25094" ,
"E0894" ,
"E0994" ,
"E1094" ,
"E1194" ,
"E1394" ,
"25095" ,
"E0895" ,
"E0995" ,
"E1095" ,
"E1195" ,
"E1395" ,
"25096" ,
"E0896" ,
"E0996" ,
"E1096" ,
"E1196" ,
"E1396" ,
"25097" ,
"E0897" ,
"E0997" ,
"E1097" ,
"E1197" ,
"E1397" ,
"25098" ,
"E0898" ,
"E0998" ,
"E1098" ,
"E1198" ,
"E1398" ,
"25099" ,
"E0899" ,
"E0999" ,
"E1099" ,
"E1199" ,
"E1399" ,
"250" ,
"E08" ,
"E09" ,
"E10" ,
"E11" ,
"E13" ,
"3572" ,
"36202" ,
"3620" ,
"36641" ,
"E08" ,
"E09" ,
"E10" ,
"E11" ,
"E13" ,
"2500" ,
"2501" ,
"2502" ,
"2503" ,
"2504" ,
"2505" ,
"2506" ,
"2507" ,
"2508" ,
"2509" ,
"E080" ,
"E081" ,
"E082" ,
"E083" ,
"E084" ,
"E085" ,
"E086" ,
"E087" ,
"E088" ,
"E089" ,
"E090" ,
"E091" ,
"E092" ,
"E093" ,
"E094" ,
"E095" ,
"E096" ,
"E097" ,
"E098" ,
"E099" ,
"E100" ,
"E101" ,
"E102" ,
"E103" ,
"E104" ,
"E105" ,
"E106" ,
"E107" ,
"E108" ,
"E109" ,
"E110" ,
"E111" ,
"E112" ,
"E113" ,
"E114" ,
"E115" ,
"E116" ,
"E117" ,
"E118" ,
"E119" ,
"E130" ,
"E131" ,
"E132" ,
"E133" ,
"E134" ,
"E135" ,
"E136" ,
"E137" ,
"E138" ,
"E139" )
```
```{r echo=FALSE}
comorbidity_ICD_list%>%
imap_dfr(.,
~tibble(
comorbidity = .y,
icd_codes_raw = paste(.x, collapse = ", ")
)
)%>%
gt() %>%
cols_label(
comorbidity = "Comorbidity",
icd_codes_raw = "ICD Codes"
) %>%
cols_width(
comorbidity ~ px(220),
icd_codes_raw ~ px(500)
) %>%
tab_options(
table.font.size = px(12)
)%>%
tab_header(
title = "ICD-9 and ICD-10 Codes Used to Define Comorbidities",
subtitle = "Codes grouped by clinical condition"
)
```
## Other portions of the analysis
- [ **Functions** ](functions.qmd) : Reusable helper functions for cohort construction, matching, costing, and modeling.
- [ **Create cohort** ](create_cohort.qmd) : Constructs the initial time-varying cohort of kidney transplant recipients, defining cohort entry, follow-up structure, and case/control eligibility prior to matching.
- [ **Execute matching** ](execute_matching.qmd) : Implements risk-set–based greedy matching without replacement to construct the analytic cohort.
- [ **Post-match processing** ](postmatch_processing.qmd) : Derives analytic variables, time-aligned cost windows, and follow-up structure after matching.
- [ **Modeling** ](modeling.qmd) : Fits prespecified cost and outcome models using the matched cohort.
- [ **Tables** ](tables.qmd) : Summary tables and regression outputs generated from the final models.
- [ **Figures** ](figures.qmd) :Visualizations of costs, risks, and model-based estimates.
- [ **About** ](about.qmd) : methods, assumptions, and disclosures