MyNixOS website logo
Description

Estimate, Compare, and Visualize Healthcare Resource Utilization for Real-World Evidence.

Tools to estimate, compare, and visualize healthcare resource utilization using data derived from electronic health records or real-world evidence sources. The package supports pre index and post index analysis, patient cohort comparison, and customizable summaries and visualizations for clinical and health economics research. Methods implemented are based on Scott et al. (2022) <doi:10.1080/13696998.2022.2037917> and Xia et al. (2024) <doi:10.14309/ajg.0000000000002901>.

hcruR

R-CMD-check Codecov test coverage GitHub version License: MIT Lifecycle: experimental

hcruR is an R package to help health economists and RWE analysts estimate and compare healthcare resource utilization (HCRU) from observational healthcare data, such as claims or electronic health records.


๐Ÿš€ Features

  • Estimate patient-level HCRU by:
    • Domain (inpatient, outpatient, pharmacy, etc.)
    • Time relative to index date (pre/post)
  • Compare HCRU across cohorts
  • Visualize domain-wise HCRU statistics
  • Designed for flexible real-world evidence (RWE) workflows

๐Ÿ“ฅ Installation

You can install the development version of hcruR from GitHub with:

# Install from GitHub (after you upload the repo)
# install.packages("devtools")
devtools::install_github("mumbarkar/hcruR")

# install.packages("pak")
pak::pak("mumbarkar/hcruR")

๐Ÿงช Example Usage

This is a basic example which shows you how to solve a common problem:

This is a basic example which shows you how to solve a common problem:

# Load library
library(hcruR)

## Generate HCRU summary using dplyr (this can be used for create HCRU plots)

# Load sample data
data(hcru_sample_data)
data <- hcru_sample_data
head(hcru_sample_data)

# Estimate HCRU
hcru_summary <- estimate_hcru(data,
                          cohort_col = "cohort",
                          patient_id_col = "patient_id",
                          admit_col = "admission_date",
                          discharge_col = "discharge_date",
                          index_col = "index_date",
                          visit_col = "visit_date",
                          encounter_id_col = "encounter_id",
                          setting_col = "care_setting",
                          cost_col = "cost_usd",
                          readmission_col = "readmission",
                          time_window_col = "period",
                          los_col = "length_of_stay",
                          custom_var_list = NULL,
                          pre_days = 180,
                          post_days = 365,
                          readmission_days_rule = 30,
                          group_var_main = "cohort",
                          group_var_by = "care_setting",
                          test = NULL,
                          timeline = "Pre",
                          gt_output = FALSE)

hcru_summary

## Generate HCRU summary using gtsummary (a publication ready output) 

# Estimate HCRU
hcru_summary_gt <- estimate_hcru(data,
                          cohort_col = "cohort",
                          patient_id_col = "patient_id",
                          admit_col = "admission_date",
                          discharge_col = "discharge_date",
                          index_col = "index_date",
                          visit_col = "visit_date",
                          encounter_id_col = "encounter_id",
                          setting_col = "care_setting",
                          cost_col = "cost_usd",
                          readmission_col = "readmission",
                          time_window_col = "period",
                          los_col = "length_of_stay",
                          custom_var_list = NULL,
                          pre_days = 180,
                          post_days = 365,
                          readmission_days_rule = 30,
                          group_var_main = "cohort",
                          group_var_by = "care_setting",
                          test = NULL,
                          timeline = "Pre",
                          gt_output = TRUE)

hcru_summary_gt

## Generate the HCRU plot for average visits by cohort and time-line
# Calculate the average visits
sum_df1 <- hcru_summary$`Summary by settings using dplyr` |>
    dplyr::group_by(
      .data[["time_window"]], 
      .data[["cohort"]], 
      .data[["care_setting"]]) |>
    dplyr::summarise(
      AVG_VISIT = mean(.data[["Visits"]], na.rm = TRUE), .groups = "drop")

# Load the plot_hcru function
p1 <- plot_hcru(
  summary_df = sum_df1,
  x_var = "time_window",
  y_var = "AVG_VISIT",
  cohort_col = "cohort",
  facet_var = "care_setting",
  facet_var_n = 3,
  title = "Average visits by domain and cohort",
  x_label = "Healthcare Setting (Domain)",
  y_label = "Average visit",
  fill_label = "Cohort"
)

p1


## Generate HCRU plot for average cost by cohort and timeline
# Calculate the total cost
df2 <- hcru_summary$`Summary by settings using dplyr` |>
    dplyr::group_by(
      .data[["time_window"]], 
      .data[["cohort"]], 
      .data[["care_setting"]]) |>
    dplyr::summarise(
      AVG_COST = sum(.data[["Cost"]], na.rm = TRUE), .groups = "drop")

p2 <- plot_hcru(
  summary_df = df2,
  x_var = "time_window",
  y_var = "AVG_COST",
  cohort_col = "cohort",
  facet_var = "care_setting",
  facet_var_n = 3,
  title = "Average cost by domain and cohort",
  x_label = "Healthcare Setting (Domain)",
  y_label = "Average cost",
  fill_label = "Cohort"
)

p2

๐Ÿงพ Function Reference

estimate_hcru() estimates of healthcare resource utilization (HCRU) from electronic health record data across various care settings (e.g., IP, OP, ED/ER). It provides descriptive summaries of patient counts, encounters, costs, length of stay, and readmission rates for pre- and post-index periods

Arguments

ArgumentTypeDescription
datadata.frameInput claims dataset
cohort_colcharacterColumn name for cohort group
patient_id_colcharacterColumn name for patient ID
admit_colcharacterAdmission/start date column
discharge_colcharacterDischarge/end date column
index_colcharacterIndex or anchor date for each patient
visit_colcharacterVisit or claim date
encounter_id_colcharacterEncounter or claim ID
setting_colcharacterSetting type (e.g., "IP", "OP", "ED")
cost_colcharacterColumn for cost data
readmission_colcharacterReadmission indicator column
time_window_colcharacter"Pre"/"Post" period column
los_colcharacterLength of stay column
custom_var_listcharacterAdditional user-defined metrics (optional)
pre_daysnumericDays before index date (default = 180)
post_daysnumericDays after index date (default = 365)
readmission_days_rulenumericMax days for qualifying readmission (default = 30)
group_var_maincharacterMain grouping variable (default = "cohort")
group_var_bycharacterSecondary grouping variable (e.g., "care_setting")
testlistNamed list of tests for continuous vars (e.g., list(cost = "wilcox.test"))
timelinecharacterTime window label (e.g., "Pre", "Post")
gt_outputlogicalWhether to return a formatted gtsummary output (default = TRUE)
......Additional arguments for gtsummary::tbl_summary() if gt_output = TRUE
return_typecharacterType of output to return: "dplyr" for dplyr summary, "gtsummary" for gtsummary output (default = "dplyr")

plot_hcru() provides the visualization of the events of the settings/domains grouped by cohort and time window.

Arguments:

ArgumentTypeDescription
summary_dfdataframeOutput from estimate_hcru() function.
x_varcharacterColumn name to plot on the x-axis (default "period").
y_varcharacterColumn name to plot on the y-axis (default "Cost").
cohort_colcharacterName of the column identifying cohorts (default "cohort").
facet_varcharacterColumn to generate subplots for (default "care_setting").
facet_var_nnumericNumber of columns in the facet grid (default 3).
titlecharacterTitle of the plot.
x_lablecharacterLabel for the x-axis.
y_lablecharacterLabel for the y-axis.
fill_lablecharacterLabel for the fill legend.

๐Ÿ“Š Sample Data

This package includes a demo datasets for easy testing:

  • hcru_sample_data: 200 patients across 2 cohorts
head(hcru_sample_data)

๐Ÿ“š Vignette

Run the following to access the full walkthrough:

vignette("hcru-analysis", package = "hcruR")

๐Ÿ”ฌ Use Cases

  • Cost burden studies before/after treatment
  • Resource comparison across patient populations
  • Outcome stratification based on utilization patterns

๐Ÿ› ๏ธ Development

To contribute:

git clone https://github.com/mumbarkar/hcruR.git
cd hcruR

๐Ÿ“œ License

This package is licensed under the MIT License.

Metadata

Version

1.0.0

License

Unknown

Platformsย (76)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-linux
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows