| Title: | Calculate Standardized Morphine Milligram Equivalent Doses |
|---|---|
| Description: | Calculate morphine milligram equivalents (MME) for opioid dose comparison using standardized methods. Can directly call the 'NIH HEAL MME Online Calculator' <https://research-mme.wakehealth.edu/api> API or replicate API calculations on the user's local machine from the comfort of 'R'. Creation of the 'NIH HEAL MME Online Calculator' and the MME calculations implemented in this package are described in Adams MCB, Sward KA, Perkins ML, Hurley RW (2025) <doi:10.1097/j.pain.0000000000003529>. |
| Authors: | Kenneth A. Taylor [aut, cre, cph] (ORCID: <https://orcid.org/0000-0002-3205-9280>) |
| Maintainer: | Kenneth A. Taylor <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 1.0.0.9000 |
| Built: | 2026-05-15 05:45:43 UTC |
| Source: | https://github.com/kennethataylor/mmequiv |
data.frame or tibbleCalculates the single-day MME and total MME for each individual prescription opioid medication submitted for calculation. Also calculates total MME, total days of supply, and four distinct Total MME/Day calculations from the NIH HEAL Online MME Calculator across all prescription medications for two different medication groupings: 1) opioids without buprenorphine and 2) opioids with buprenorphine.
## S3 method for class 'data.frame' calculate_mme( x, 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, use_api = FALSE, ... ) ## S3 method for class 'tbl_df' calculate_mme( x, 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, use_api = FALSE, ... )## S3 method for class 'data.frame' calculate_mme( x, 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, use_api = FALSE, ... ) ## S3 method for class 'tbl_df' calculate_mme( x, 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, use_api = FALSE, ... )
x |
( |
id_col |
( |
medication_col |
( |
dose_col |
( |
doses_per_day_col |
( |
days_col |
( |
therapy_days_col |
( |
observation_days_col |
( |
therapy_days_without_col |
( |
observation_days_without_col |
( |
use_api |
( |
... |
These dots are for future extensions and must be empty. |
The function will provide the same results regardless of whether the user has
specified they want calculation done using the API (use_api). Specifying
use_api == FALSE helps overcome the online calculator API rate limit of 50
(patient-level) requests per 15 minutes. In addition to returning
user-specified arguments, calculate_mme() also returns several other
variables mentioned in the Description section. Output variable
description details are below; see
Adams, et al. (2025)
for a comprehensive overview.
A list containing three data.frame elements:
medications: The original data 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
Conversion Factor for <medication_name> (factor): the conversion
factor used for calculating total MME/day.
MME for <medication_name> (mme): Morphine milligram equivalent
for the whole prescription specified in medication_name, calculated as
(dose) * (doses_per_24_hours) * (factor) * (days_of_medication).
24h MME for <medication_name> (single_day_mme): Morphine milligram
equivalent for the prescription specified in medication_name for a
single day, calculated as (dose) * (doses_per_24_hours) * (factor).
One day: Typically, the day with highest opioid exposure is entered, and the sum of 24-hour MME across the drugs that apply to this day is calculated. Highest MME in one day is definition 4.
On-therapy Days (therapy_days): The sum of prescription duration
(days_of_medication) for each medication, but with each calendar day
counted only ONCE. User-supplied; this is the denominator for MME/Day
definition 2.
If there is only one prescription, or if there is no calendar overlap (no days on which more than one prescription is active), this will be the same as the total days supply.
If there are overlapping prescriptions, this is the number of unique calendar days.
Total MME (total_mme): The MME for each medication, summed across all
prescriptions. This is the numerator for MME/Day definitions 1, 2, and 3.
Total Days Supply (total_days): The sum of the entered prescription
duration (days_of_medication) for each of the medications (Med 1
duration + med 2 duration...). Automatically calculated. This is the
denominator for MME/Day definition 1.
MME/Day is an aggregate measure, calculating the total MME divided by a specified time window (a number of days). The MME/Day definitions specify the number of days:
MME/Day Definition 1 (mme1): Total Days Supply
MME Definition 1 = Total MME / Total Days Supply time window (sum of entered prescription durations).
mme1 = total_mme / total_days
Note that the same calendar day may contribute multiple times, if overlapping prescriptions.
Reason to select this definition: This is the least complicated calculation; appears best suited when immediate-release opioids are prescribed for short discrete times.
Identified challenge with this definition: It consistently underestimated MME per day when overlapping prescriptions were present or when immediate-release and extended release opioids were prescribed concurrently.
MME/Day Definition 2 (mme2): On-therapy Days
MME Definition 2 = Total MME / On-therapy Days time window (sum of entered prescription durations except each calendar day is counted only ONCE).
mme2 = total_mme / therapy_days
Note - On-therapy Days unique calendar days.
Reason to select this definition: Provides a smoothed measure useful in studies of dose-dependent adverse effects, including opioid-induced constipation or overdose in patients with opioid tolerance or who have been stable on opioids.
Identified challenge with this definition: The metric is time-varying and affords the greatest flexibility to define medication gap periods and leftover/unused medications to improve pharmacoepidemiologic studies.
MME/Day Definition 3 (mme3): Fixed Observation Window
Uses the Total MME study-specified fixed observation window. MME Definition 3 = Total MME / Number of days in observation window:
mme3 = total_mme / observation_window_days
If this definition is selected, it is important to report on the duration of the fixed window.
Reason to select this definition: Most suitable for studies with a known or suspected duration of risk during which adverse events are expected to occur, such as incidence of opioid use disorder. This definition may be useful when prescriptions are filled at irregular time intervals on a as needed basis (pro re nata, PRN).
Identified challenge with this definition: The definition consistently had the lowest milligrams per day for immediate-release opioids. It is the most robust to misspecification, amenable to transformations, and has the least noise when constructing continuous functions. However, since it assumes uniform exposure/risk within a window, there is less scope for time-varying adjustment.
This is the definition recommended by the Department of Health and Human Services Office of the Inspector General.
MME/Day Definition 4 (mme4): Maximum Daily Dose
Uses the sum of 24-hour MME for the day with highest opioid exposure.
MME Definition 4 = Drug 1 (dose (mg) x # of doses per day) x conversion factor + Drug 2 (dose (mg) x # of doses per day) x conversion factor + ...
mme4 = sum(dose * doses_per_24_hours * factor)
Report the highest single-day exposure.
Reason to select this definition: A toxicological perspective may be appropriate for patients with no opioid tolerance and in the presence of comorbidities for respiratory depression. It appears to be best suited for immediate dose-dependent toxic effects, such as respiratory depression.
Identified challenged with this definition: This definition may have limited use if it includes opioids where fatal toxicity does not involve respiratory depression (e.g., tramadol) or have atypical mu-opioid receptor agonism (e.g., tapentadol, buprenorphine).
The definition assumes uniform risk of adverse outcomes regardless of time on-therapy. More so than the others, this definition is prone to influence from early refills, unused medication, and how the 90 MME threshold is operationalized.
This definition underlies the algorithm embedded in the CDC Opioid Guideline mobile app. There may be difficulty reconciling findings with studies using the other definitions because it returns a MME per day that is significantly higher.
This calculator sums the 24-hour MME for every prescription, without considering calendar dates.
library(dplyr) # Calculate MME using long-format data # Subset of opioid_trial data used for speedier example 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)library(dplyr) # Calculate MME using long-format data # Subset of opioid_trial data used for speedier example 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)
Calculates the single-day MME and total MME for each individual prescription opioid medication submitted for calculation. Also calculates total MME, total days of supply, and four distinct Total MME/Day calculations from the NIH HEAL Online MME Calculator across all prescription medications for two different medication groupings: 1) opioids without buprenorphine and 2) opioids with buprenorphine.
## S3 method for class 'list' calculate_mme(x, therapy_days, observation_window_days, use_api = TRUE, ...)## S3 method for class 'list' calculate_mme(x, therapy_days, observation_window_days, use_api = TRUE, ...)
x |
(
|
therapy_days |
(
|
observation_window_days |
( |
use_api |
( |
... |
These dots are for future extensions and must be empty. |
The function will provide the same results regardless of whether the user has
specified they want calculation done using the API (use_api). Specifying
use_api == FALSE helps overcome the online calculator API rate limit of 50
(patient-level) requests per 15 minutes. In addition to returning
user-specified arguments, calculate_mme() also returns several other
variables mentioned in the Description section. Output variable
description details are below; see
Adams, et al. (2025)
for a comprehensive overview.
A list of MME calculations. Will error if any medications are invalid or if
any numeric parameters are not positive numbers.
Conversion Factor for <medication_name> (factor): the conversion
factor used for calculating total MME/day.
MME for <medication_name> (mme): Morphine milligram equivalent
for the whole prescription specified in medication_name, calculated as
(dose) * (doses_per_24_hours) * (factor) * (days_of_medication).
24h MME for <medication_name> (single_day_mme): Morphine milligram
equivalent for the prescription specified in medication_name for a
single day, calculated as (dose) * (doses_per_24_hours) * (factor).
One day: Typically, the day with highest opioid exposure is entered, and the sum of 24-hour MME across the drugs that apply to this day is calculated. Highest MME in one day is definition 4.
On-therapy Days (therapy_days): The sum of prescription duration
(days_of_medication) for each medication, but with each calendar day
counted only ONCE. User-supplied; this is the denominator for MME/Day
definition 2.
If there is only one prescription, or if there is no calendar overlap (no days on which more than one prescription is active), this will be the same as the total days supply.
If there are overlapping prescriptions, this is the number of unique calendar days.
Total MME (total_mme): The MME for each medication, summed across all
prescriptions. This is the numerator for MME/Day definitions 1, 2, and 3.
Total Days Supply (total_days): The sum of the entered prescription
duration (days_of_medication) for each of the medications (Med 1
duration + med 2 duration...). Automatically calculated. This is the
denominator for MME/Day definition 1.
MME/Day is an aggregate measure, calculating the total MME divided by a specified time window (a number of days). The MME/Day definitions specify the number of days:
MME/Day Definition 1 (mme1): Total Days Supply
MME Definition 1 = Total MME / Total Days Supply time window (sum of entered prescription durations).
mme1 = total_mme / total_days
Note that the same calendar day may contribute multiple times, if overlapping prescriptions.
Reason to select this definition: This is the least complicated calculation; appears best suited when immediate-release opioids are prescribed for short discrete times.
Identified challenge with this definition: It consistently underestimated MME per day when overlapping prescriptions were present or when immediate-release and extended release opioids were prescribed concurrently.
MME/Day Definition 2 (mme2): On-therapy Days
MME Definition 2 = Total MME / On-therapy Days time window (sum of entered prescription durations except each calendar day is counted only ONCE).
mme2 = total_mme / therapy_days
Note - On-therapy Days unique calendar days.
Reason to select this definition: Provides a smoothed measure useful in studies of dose-dependent adverse effects, including opioid-induced constipation or overdose in patients with opioid tolerance or who have been stable on opioids.
Identified challenge with this definition: The metric is time-varying and affords the greatest flexibility to define medication gap periods and leftover/unused medications to improve pharmacoepidemiologic studies.
MME/Day Definition 3 (mme3): Fixed Observation Window
Uses the Total MME study-specified fixed observation window. MME Definition 3 = Total MME / Number of days in observation window:
mme3 = total_mme / observation_window_days
If this definition is selected, it is important to report on the duration of the fixed window.
Reason to select this definition: Most suitable for studies with a known or suspected duration of risk during which adverse events are expected to occur, such as incidence of opioid use disorder. This definition may be useful when prescriptions are filled at irregular time intervals on a as needed basis (pro re nata, PRN).
Identified challenge with this definition: The definition consistently had the lowest milligrams per day for immediate-release opioids. It is the most robust to misspecification, amenable to transformations, and has the least noise when constructing continuous functions. However, since it assumes uniform exposure/risk within a window, there is less scope for time-varying adjustment.
This is the definition recommended by the Department of Health and Human Services Office of the Inspector General.
MME/Day Definition 4 (mme4): Maximum Daily Dose
Uses the sum of 24-hour MME for the day with highest opioid exposure.
MME Definition 4 = Drug 1 (dose (mg) x # of doses per day) x conversion factor + Drug 2 (dose (mg) x # of doses per day) x conversion factor + ...
mme4 = sum(dose * doses_per_24_hours * factor)
Report the highest single-day exposure.
Reason to select this definition: A toxicological perspective may be appropriate for patients with no opioid tolerance and in the presence of comorbidities for respiratory depression. It appears to be best suited for immediate dose-dependent toxic effects, such as respiratory depression.
Identified challenged with this definition: This definition may have limited use if it includes opioids where fatal toxicity does not involve respiratory depression (e.g., tramadol) or have atypical mu-opioid receptor agonism (e.g., tapentadol, buprenorphine).
The definition assumes uniform risk of adverse outcomes regardless of time on-therapy. More so than the others, this definition is prone to influence from early refills, unused medication, and how the 90 MME threshold is operationalized.
This definition underlies the algorithm embedded in the CDC Opioid Guideline mobile app. There may be difficulty reconciling findings with studies using the other definitions because it returns a MME per day that is significantly higher.
This calculator sums the 24-hour MME for every prescription, without considering calendar dates.
# Recreating example from Adams MCB, et al. 2025 supplement # https://links.lww.com/PAIN/C213 meds_list <- list( list( medication_name = "Morphine (mg)", dose = 5, doses_per_24_hours = 4, days_of_medication = 7 ), list( medication_name = "Morphine (mg) LA", dose = 10, doses_per_24_hours = 3, days_of_medication = 30 ) ) # Using API calculate_mme(meds_list, 30, 90) # Not using API calculate_mme(meds_list, 30, 90, use_api = FALSE) # Clean up meds_list rm(meds_list)# Recreating example from Adams MCB, et al. 2025 supplement # https://links.lww.com/PAIN/C213 meds_list <- list( list( medication_name = "Morphine (mg)", dose = 5, doses_per_24_hours = 4, days_of_medication = 7 ), list( medication_name = "Morphine (mg) LA", dose = 10, doses_per_24_hours = 3, days_of_medication = 30 ) ) # Using API calculate_mme(meds_list, 30, 90) # Not using API calculate_mme(meds_list, 30, 90, use_api = FALSE) # Clean up meds_list rm(meds_list)
Retrieve full opioid medication list
get_med_list()get_med_list()
A data.frame with full list of opioid medication names (med_name) that are compatible with the MME calculator along with their conversion factors (cf).
get_med_list()get_med_list()
Example (synthetic) data provided as an example of long format data to use
with calculate_mme_df().
opioid_trialopioid_trial
opioid_trialA data frame with 2,371 rows and 9 columns:
Patient identifier; includes 1000 separate patients
Medication names of prescription opioids used by the patient
Dosage of the medication
Number of daily doses for the medication
Duration of medication in days
Sum of prescription duration (days) for across all of the patient's medications, but with each calendar day counted only ONCE
study-defined fixed observation window of time, applied to all of the patient's medications
Sum of prescription duration (days) for across all of the patient's medications (excluding buprenorphine), but with each calendar day counted only ONCE
study-defined fixed observation window of time, applied to all of the patient's medications (excluding buprenorphine)
Search opioid medication list
search_meds(med_name = NULL)search_meds(med_name = NULL)
med_name |
A single string specifying the medication name to search for. |
A data.frame containing medications matching the med_name argument and
their associated conversion factor(s) (cf).
search_meds("oxy")search_meds("oxy")