calculate_mme_df {mmequiv} | R Documentation |
Calculate MME for medication data in long format
Description
This function takes medication data in long format (multiple rows per patient
ID), calculates MME using the local calculation method
(calculate_mme_local()
), and adds prescription-level values as new columns.
It also returns two additional data frames with patient-level MME summaries
(one with buprenorphine included and one without).
Usage
calculate_mme_df(
data,
id_col = "patient_id",
medication_col = "medication_name",
dose_col = "dose",
doses_per_day_col = "doses_per_24_hours",
days_col = "days_of_medication",
therapy_days_col = "therapy_days",
observation_days_col = "observation_window_days",
therapy_days_without_col = NULL,
observation_days_without_col = NULL
)
Arguments
data |
A |
id_col |
Name of the column containing patient identifier; default is
|
medication_col |
Name of the column containing medication names; default
is |
dose_col |
Name of the column containing dose values; default is
|
doses_per_day_col |
Name of the column containing doses per 24 hours;
|
days_col |
Name of the column containing days of medication; default is
|
therapy_days_col |
Name of the column containing therapy days with
buprenorphine (up to one unique value per patient); default is
|
observation_days_col |
Name of the column containing observation window
days with buprenorphine (up to one unique value per patient); default is
|
therapy_days_without_col |
Name of the column containing therapy days
without buprenorphine (up to one unique value per patient). If |
observation_days_without_col |
Name of the column containing observation
window days without buprenorphine (up to one unique value per patient).
If |
Value
A list containing three elements:
-
medications
: The originaldata.frame
with added prescription-level MME columns -
patient_summary_with_buprenorphine
: Patient-level MME summary including buprenorphine -
patient_summary_without_buprenorphine
: Patient-level MME summary excluding buprenorphine
See Also
Examples
library(dplyr)
# Calculate MME using long-format data
# Subset of opioid_trial data used for speedier example
mme <- calculate_mme_df(
data = opioid_trial |> dplyr::filter(patient_id %in% sprintf("P%03d", 1:100)),
therapy_days_without_col = "therapy_days_without",
observation_days_without_col = "observation_window_days_without"
)
# ->
mme <- calculate_mme(
x = opioid_trial |> dplyr::filter(patient_id %in% sprintf("P%03d", 1:100)),
therapy_days_without_col = "therapy_days_without",
observation_days_without_col = "observation_window_days_without"
)
head(mme$medications)
head(mme$patient_summary_with_buprenorphine)
head(mme$patient_summary_without_buprenorphine)
# Cleanup
rm(mme)