View source: R/calc_hosp_days.R
calc_hosp_days | R Documentation |
Calculates the total number of hospitalization days ('hosp_days_all') and the number of hospitalization days that started during the drug exposure ('hosp_days_exp') for each purchase period. The calculation is based on overlapping time windows between purchase events and hospitalization periods, taking into account the discharge date (which is not included in the hospital stay).
calc_hosp_days(
pre_id,
pre_atc,
curr_purc_start,
exp_end,
next_start,
hosp_id,
hosp_in,
hosp_out
)
pre_id |
Integer or character vector. Person identifier in drug purchases data. |
pre_atc |
Character vector. ATC codes for each purchase. |
curr_purc_start |
Integer or Date vector. Start date of the drug purchase period. |
exp_end |
Integer or Date vector. End date of the drug exposure period. |
next_start |
Integer or Date vector. Start date of the next purchase period (may be NA for the last purchase). |
hosp_id |
Integer or character vector. IDs for each hospitalization (should match 'pre_id'). |
hosp_in |
Integer or Date vector. Admission date for each hospitalization. |
hosp_out |
Integer or Date vector. Discharge date for each hospitalization. |
The function merges drug purchase and hospitalization data by person ID, then calculates the overlap between purchase periods and hospitalizations. Hospital discharge date is not included in the total stay. Hospitalization days are summed for each purchase period.
A data.table with two columns:
Total number of hospitalization days between purchase and next purchase (not including discharge date).
Number of hospitalization days that started during drug exposure.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.