Warning: package 'tidyr' was built under R version 4.2.3
Warning: package 'readr' was built under R version 4.2.3
Warning: package 'dplyr' was built under R version 4.2.3
Warning: package 'stringr' was built under R version 4.2.3
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.5
✔ forcats 1.0.0 ✔ stringr 1.5.1
✔ ggplot2 3.5.2 ✔ tibble 3.2.1
✔ lubridate 1.9.4 ✔ tidyr 1.3.1
✔ purrr 1.0.2
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(lubridate)library(brms)
Warning: package 'brms' was built under R version 4.2.3
Loading required package: Rcpp
Loading 'brms' package (version 2.21.0). Useful instructions
can be found by typing help('brms'). A more detailed introduction
to the package is available through vignette('brms_overview').
Attaching package: 'brms'
The following object is masked from 'package:stats':
ar
Warning: package 'bayestestR' was built under R version 4.2.3
library(marginaleffects)
Warning: package 'marginaleffects' was built under R version 4.2.3
library(rstan)
Warning: package 'rstan' was built under R version 4.2.3
Loading required package: StanHeaders
rstan version 2.32.6 (Stan version 2.32.2)
For execution on a local, multicore CPU with excess RAM we recommend calling
options(mc.cores = parallel::detectCores()).
To avoid recompilation of unchanged Stan programs, we recommend calling
rstan_options(auto_write = TRUE)
For within-chain threading using `reduce_sum()` or `map_rect()` Stan functions,
change `threads_per_chain` option:
rstan_options(threads_per_chain = 1)
Attaching package: 'rstan'
The following object is masked from 'package:tidyr':
extract
New names:
Rows: 109107 Columns: 127
── Column specification
──────────────────────────────────────────────────────── Delimiter: ";" chr
(18): DX_GROUP, hospital_name_receiving, sir_icu_name, sir_hospital_typ... dbl
(91): ...1, VtfId_LopNr, TERTIARY_HADM_ID, LopNr, SIR_PAR_OFFSET, SIR_P... lgl
(8): daylight, hems_minima_sending, hems_minima_window, daylight_recei... dttm
(9): sir_adm_time, sir_dsc_time, sir_adm_time_UTC, sir_dsc_time_UTC, w... date
(1): DODSDAT_ROUND_UP
ℹ Use `spec()` to retrieve the full column specification for this data. ℹ
Specify the column types or set `show_col_types = FALSE` to quiet this message.
• `` -> `...1`
# Prune datad_pruned <- d %>%filter(sir_dsc_time >="2019-10-01"& sir_dsc_time <="2024-05-15") %>%# 2019-10-01 -- 2024-05-15filter(!is.na(TERTIARY_HADM_ID)) %>%# Keep only rows with a tertiary HADM matchfilter(sir_total_time <=720) %>%# Keep only rows with a primary ICU stay 12 hours or shorterfilter(SIR_PAR_OFFSET_TIGHT %in% (c(-1,0,1))) %>%# Keep only rows with a recent PAR admitfilter(road_distance >=45) %>%# Keep only rows with transfers 45 km or longerfilter(DX_GROUP %in%c("ASAH", "ICH", "AIS", "TBI")) %>%#Keep only admits with ASAH, ICH, AIS or TBIfilter(min_rank(DX_RANK) ==1, .by = VtfId_LopNr) %>%# Within each unique VtfId_LopNr, keep only the lowest ranking diagnostic PAR admitslice_max(sir_dsc_time, by = LopNr, n =1, with_ties =FALSE) # This gives the latest date by default (if ties, may give more than one)heavy_users <- d_pruned %>%group_by(formatted_icu_name) %>%summarise(proportion_hems_ift =mean(hems_ift ==TRUE, na.rm =TRUE),n =n() ) %>%filter(proportion_hems_ift >=0.1) %>%select(formatted_icu_name) %>%unique()light_users <- d_pruned %>%group_by(formatted_icu_name) %>%summarise(proportion_hems_ift =mean(hems_ift ==TRUE, na.rm =TRUE),n =n() ) %>%filter(proportion_hems_ift <0.05) %>%select(formatted_icu_name) %>%unique()
In [2]:
# Load dependencies library(tidyverse)library(lubridate)library(brms)library(DBI)library(RSQLite)library(flowchart)library(gtsummary)library(ggplot2)library(bayestestR)library(marginaleffects)library(rstan)library(flowchart)library("devtools")library(rcmswe)library(NatParksPalettes)library(showtext)font_add_google("Noto Sans", "Noto Sans") # Downloads from Google Fontsshowtext_auto()# Set gtsummart themetheme_gtsummary_compact()