Title: | Interpreting Glucose Data from Continuous Glucose Monitors |
---|---|
Description: | Implements a wide range of metrics for measuring glucose control and glucose variability based on continuous glucose monitoring data. The list of implemented metrics is summarized in Rodbard (2009) <doi:10.1089/dia.2009.0015>. Additional visualization tools include time-series plots, lasagna plots and ambulatory glucose profile report. |
Authors: | Elizabeth Chun [aut], Steve Broll [aut], David Buchanan [aut], John Muschelli [aut] , Nathaniel Fernandes [aut] , Jung Hoon Seo [ctb], Johnathan Shih [ctb], Jacek Urbanek [ctb], John Schwenck [ctb], Marielle Hicban [ctb], Mary Martin [ctb], Pratik Patel [ctb], Meyappan Ashok [ctb], Nhan Nguyen [ctb], Irina Gaynanova [aut, cre] |
Maintainer: | Irina Gaynanova <[email protected]> |
License: | GPL-2 |
Version: | 4.2.1 |
Built: | 2024-11-25 19:22:54 UTC |
Source: | https://github.com/irinagain/iglu |
The function above_percent
produces a tibble object with values equal to
the percentage of glucose measurements above target values. The output columns
correspond to the subject id followed by the target values, and the
output rows correspond to the subjects. The values will be between 0
(no measurements) and 100 (all measurements).
above_percent(data, targets_above = c(140, 180, 250))
above_percent(data, targets_above = c(140, 180, 250))
data |
DataFrame object with column names "id", "time", and "gl", or numeric vector of glucose values. |
targets_above |
Default: (140, 180, 250). Numeric vector of glucose thresholds. Glucose values from data argument will be compared to each value in the targets_above vector. |
A tibble object with 1 row for each subject, a column for subject id and column for each target value is returned. NA's will be omitted from the glucose values in calculation of percent.
If a DataFrame object is passed, then a tibble object with a column for subject id and then a column for each target value is returned. If a vector of glucose values is passed, then a tibble object without the subject id is returned. Wrap 'as.numeric()' around the latter to output a numeric vector.
Rodbard (2009) Interpretation of continuous glucose monitoring data: glycemic variability and quality of glycemic control, Diabetes Technology and Therapeutics 11 .55-67, doi:10.1089/dia.2008.0132.
plot_ranges()
data(example_data_1_subject) above_percent(example_data_1_subject) above_percent(example_data_1_subject, targets_above = c(100, 150, 180)) data(example_data_5_subject) above_percent(example_data_5_subject) above_percent(example_data_5_subject, targets_above = c(70, 170))
data(example_data_1_subject) above_percent(example_data_1_subject) above_percent(example_data_1_subject, targets_above = c(100, 150, 180)) data(example_data_5_subject) above_percent(example_data_5_subject) above_percent(example_data_5_subject, targets_above = c(70, 170))
The function 'active_percent' produces the
active_percent(data, dt0 = NULL, tz = "", range_type = "automatic", ndays = 14, end_date = NULL)
active_percent(data, dt0 = NULL, tz = "", range_type = "automatic", ndays = 14, end_date = NULL)
data |
DataFrame object with column names "id", "time", and "gl". |
dt0 |
The time frequency for interpolated aligned grid in minutes, the default will match the CGM meter's frequency (e.g. 5 min for Dexcom). |
tz |
tz = "". A character string specifying the time zone to be used. System-specific (see |
range_type |
range_type = "automatic". A character string indicating the type of range ('automatic' or 'manual'). |
ndays |
ndays = 14. An integer specifying the number of days to consider in the calculation. |
end_date |
end_date = NULL. A Date object or NULL indicating the end date for the calculation. |
The function 'active_percent' produces a tibble object with values equal to the percentage of time the CGM was active, the total number of observed days, the start date, and the end date. For example, if a CGM's (5 min frequency) times were 0, 5, 10, 15 and glucose values were missing at time 5, then percentage of time the CGM was active is 75 The output columns correspond to the subject id, the percentage of time for which the CGM was active, the number of days of measurements, the start date and the end date of measurements. The output rows correspond to the subjects. The values of 'active_percent' are always between 0
A tibble object with five columns: subject id, corresponding active_percent value, duration of measurement period in days, start date, and end date.
Pratik Patel, Irina Gaynanova
Danne et al. (2017) International Consensus on Use of Continuous Glucose Monitoring Diabetes Care 40 .1631-1640, doi:10.2337/dc17-1600.
data(example_data_1_subject) active_percent(example_data_1_subject) data(example_data_5_subject) active_percent(example_data_5_subject) active_percent(example_data_5_subject, dt0 = 5, tz = 'GMT')
data(example_data_1_subject) active_percent(example_data_1_subject) data(example_data_5_subject) active_percent(example_data_5_subject) active_percent(example_data_5_subject, dt0 = 5, tz = 'GMT')
The function 'adrr' produces ADRR values in a tibble object.
adrr(data)
adrr(data)
data |
DataFrame object with column names "id", "time", and "gl". |
A tibble object with 1 row for each subject, a column for subject id and a column for ADRR values is returned. 'NA' glucose values are omitted from the calculation of the ADRR values.
ADRR is the average sum of HBGI corresponding to the highest glucose value and LBGI corresponding to the lowest glucose value for each day, with the average taken over the daily sums. If there are no high glucose or no low glucose values, then 0 will be substituted for the HBGI value or the LBGI value, respectively, for that day.
A tibble object with two columns: subject id and corresponding ADRR value.
Kovatchev et al. (2006) Evaluation of a New Measure of Blood Glucose Variability in, Diabetes Diabetes care 29 .2433-2438, doi:10.2337/dc06-1085.
data(example_data_1_subject) adrr(example_data_1_subject) data(example_data_5_subject) adrr(example_data_5_subject)
data(example_data_1_subject) adrr(example_data_1_subject) data(example_data_5_subject) adrr(example_data_5_subject)
Display Ambulatory Glucose Profile (AGP) statistics for selected subject
agp(data, maxd = 14, inter_gap = 45, dt0 = NULL, tz = "", daily = TRUE)
agp(data, maxd = 14, inter_gap = 45, dt0 = NULL, tz = "", daily = TRUE)
data |
DataFrame object with column names "id", "time", and "gl". Should only be data for 1 subject. In case multiple subject ids are detected, a warning is produced and only 1st subject is used. |
maxd |
Default: 14. Number of days to plot. If less than 'maxd' days of data are available, all days are plotted. |
inter_gap |
The maximum allowable gap (in minutes) for interpolation. The values will not be interpolated between the glucose measurements that are more than inter_gap minutes apart. The default value is 45 min. |
dt0 |
The time frequency for interpolation in minutes, the default will match the CGM meter's frequency (e.g. 5 min for Dexcom). |
tz |
A character string specifying the time zone to be used. System-specific (see |
daily |
Default: TRUE. Logical indicator whether AGP should include separate daily plots. |
A plot displaying glucose measurements range, selected glucose statistics (average glucose, Glucose Management Indicator,
Johnson et al. (2019) Utilizing the Ambulatory Glucose Profile to Standardize and Implement Continuous Glucose Monitoring in Clinical Practice, Diabetes Technology and Therapeutics 21:S2 S2-17-S2-25, doi:10.1089/dia.2019.0034.
data(example_data_1_subject) agp(example_data_1_subject, daily = FALSE)
data(example_data_1_subject) agp(example_data_1_subject, daily = FALSE)
The function 'agp_metrics' runs the following functions and combines them into a tibble object: 'active_percent', 'mean_glu', 'gmi', 'cv_glu', 'below_percent', 'in_range_percent', 'above_percent'.
agp_metrics(data, shinyformat = FALSE, tz = '')
agp_metrics(data, shinyformat = FALSE, tz = '')
data |
DataFrame object with column names "id", "time", and "gl". |
shinyformat |
Default: FALSE. Boolean indicating whether the output should be formatted for the single subject AGP page in shiny. |
tz |
Default: "". A character string specifying the time zone to be used. System-specific (see |
The function uses recommended cutoffs of 54, 70, 180, and 250 mg/dL for calculation.
If 'shinyformat == FALSE' (default), returns a tibble object with 1 row for each subject, and 12 columns: a column for subject id ('id'), a column for start date ('start_date'), a column for end date ('end_date'), a column for number of days ('ndays'), a column for active percent ('active_percent'), a column for mean value ('mean'), a column for GMI value ('GMI'), a column for CV value ('CV'), a column for a column for a column for a column for a column for
If 'shinyformat == TRUE', a tibble with 2 columns: metric and value, is returned. This output is used when generating the single subject AGP shiny page.
By default, a tibble object with 1 row for each subject, and 13 columns is returned: a column for subject id, a column for start date, a column for end date, a column for number of days, a column for active_percent, a column for Mean value, a column for gmi value, a column for cv value, a column for below_54 value, a column for below_70 value, a column for in_range_70_180 value, a column for above_180 value, a column for above_250 value,
Johnson et al. (2019) Utilizing the Ambulatory Glucose Profile to Standardize and Implement Continuous Glucose Monitoring in Clinical Practice, Diabetes Technology and Therapeutics 21:S2 S2-17-S2-25, doi:10.1089/dia.2019.0034.
data(example_data_1_subject) agp_metrics(example_data_1_subject)
data(example_data_1_subject) agp_metrics(example_data_1_subject)
The function all_metrics runs all of the iglu metrics, and returns the results with one column per metric.
all_metrics( data, dt0 = NULL, inter_gap = 45, tz = "", timelag = 15, lag = 1, metrics_to_include = c("all", "consensus_only") )
all_metrics( data, dt0 = NULL, inter_gap = 45, tz = "", timelag = 15, lag = 1, metrics_to_include = c("all", "consensus_only") )
data |
DataFrame object with column names "id", "time", and "gl". |
dt0 |
The time frequency for interpolation in minutes, the default will match the CGM meter's frequency (e.g. 5 min for Dexcom). |
inter_gap |
The maximum allowable gap (in minutes) for interpolation. The values will not be interpolated between the glucose measurements that are more than inter_gap minutes apart. The default value is 45 min. |
tz |
A character string specifying the time zone to be used. System-specific (see |
timelag |
Integer indicating the time period (# minutes) over which rate of change is calculated. Default is 15, e.g. rate of change is the change in glucose over the past 15 minutes divided by 15. |
lag |
Integer indicating which lag (# days) to use. Default is 1. |
metrics_to_include |
Returns all metrics computed by iglu or all on the consensus list (Battelino 2023) |
All iglu functions are calculated within the all_metrics function, and the resulting tibble is returned with one row per subject and a column for each metric. Time dependent functions are calculated together using the function optimized_iglu_functions with two exceptions: PGS and episodes are calculated within all_metrics because their structure does not align with optimized_iglu_functions. Note that episodes related outputs included in all_metrics are only average episodes per day. To get the average duration and glucose, please use the standalone episodes function
For metric specific information, please see the corresponding function documentation.
A tibble object with 1 row per subject and one column per metric is returned.
Battelino T, Alexander CM, Amiel SA, et al. Continuous glucose monitoring and metrics for clinical trials: an international consensus statement. Lancet Diabetes Endocrinol. 2023;11(1):42-57. doi:10.1016/S2213-8587(22)00319-9.
# Specify the meter frequency and change the interpolation gap to 30 min all_metrics(example_data_1_subject, dt0 = 5, inter_gap = 30)
data(example_data_1_subject) all_metrics(example_data_1_subject)
data(example_data_1_subject) all_metrics(example_data_1_subject)
The function auc produces hourly average AUC for each subject.
auc(data, tz="")
auc(data, tz="")
data |
DataFrame object with column names "id", "time", and "gl", or numeric vector of glucose values. |
tz |
String value of time zone. |
A tibble object with 1 row for each subject, a column for subject id and a column for hourly average AUC values is returned. NA glucose values are omitted from the calculation of the AUC.
AUC is calculated using the formula: (dt0/60) * ((gl[2:length(gl)] + gl[1:(length(gl)-1)])/2), where dt0/60 is the frequency of the cgm measurements in hours and gl are the glucose values.
This formula is based off the Trapezoidal Rule: (time[2]-time[1] * ((glucose[1]+glucose[2])/2)).
If a data.frame object is passed, then a tibble object with two columns: subject id and corresponding hourly average AUC value is returned.
AUC is calculated for every hour using the trapezoidal rule, then hourly average AUC is calculated for each 24 hour period, then the mean of hourly average AUC across all 24 hour periods is returned as overall hourly average AUC.
Danne et al. (2017) International Consensus on Use of Continuous Glucose Monitoring, Diabetes Care 40 .1631-1640, doi:10.2337/dc17-1600.
data(example_data_1_subject) auc(example_data_1_subject)
data(example_data_1_subject) auc(example_data_1_subject)
The function below_percent produces a tibble object with values equal to the percentage of glucose measurements below target values. The output columns correspond to the subject id followed by the target values and the output rows correspond to the subjects. The values will be between 0 (no measurements) and 100 (all measurements).
below_percent(data, targets_below = c(54, 70))
below_percent(data, targets_below = c(54, 70))
data |
DataFrame with column names ("id", "time", and "gl"), or numeric vector of glucose values. |
targets_below |
Numeric vector of glucose thresholds. Glucose values from data argument will be compared to each value in the targets_below vector. Default list is (54, 70). |
A tibble object with 1 row for each subject, a column for subject id and column for each target value is returned. NA's will be omitted from the glucose values in calculation of percent.
If a data.frame object is passed, then a tibble object with a column for subject id and then a column for each target value is returned. If a vector of glucose values is passed, then a tibble object without the subject id is returned. as.numeric() can be wrapped around the latter to output a numeric vector.
Rodbard (2009) Interpretation of continuous glucose monitoring data: glycemic variability and quality of glycemic control, Diabetes Technology and Therapeutics 11 .55-67, doi:10.1089/dia.2008.0132.
plot_ranges()
data(example_data_1_subject) below_percent(example_data_1_subject) below_percent(example_data_1_subject, targets_below = c(50, 100, 180)) data(example_data_5_subject) below_percent(example_data_5_subject) below_percent(example_data_5_subject, targets_below = c(80, 180))
data(example_data_1_subject) below_percent(example_data_1_subject) below_percent(example_data_1_subject, targets_below = c(50, 100, 180)) data(example_data_5_subject) below_percent(example_data_5_subject) below_percent(example_data_5_subject, targets_below = c(80, 180))
This function applies a given function to a subset of data filtered by time of day.
calculate_sleep_wake( data, FUN, sleep_start = 0, sleep_end = 6, calculate = c("sleep", "wake", "both"), ... )
calculate_sleep_wake( data, FUN, sleep_start = 0, sleep_end = 6, calculate = c("sleep", "wake", "both"), ... )
data |
DataFrame object with column names "id", "time", and "gl". |
FUN |
Function to be applied to the filtered data. |
sleep_start |
Numeric between 0-24 signifying the hour at which the time range should start. |
sleep_end |
Numeric between 0-24 signifying the hour at which the time range should end. |
calculate |
String determining whether FUN should be applied to values inside or outside the time range. Both separately is an option |
... |
Optional arguments which will be passed to FUN |
An object of the same return type as FUN, with the same column names as FUN will be returned. If calculate = "both", there will be columns for FUN applied to both inside and outside values, with either "in range" or "out of range" append to signify whether the statistic was calculated on values which were inside the time range or outside the range.
FUN is found by a call to match.fun and typically is either a function or a character string specifying a function to be searched for from the environment of the call to apply. Arguments in ... cannot have the same name as any of the other arguments, and care may be needed to avoid partial matching to FUN. FUN is applied to the data after the data is filtered based on whether its hour falls within the given range. If sleep_start is an integer, all times within that hour will be included in the range, but if sleep_end is an integer only times up to that hour will be included in the range. If sleep_start is after sleep_end, the data will be filtered to include all hours after sleep_start and all times before sleep_end.
An object of the same return type as FUN, with columns corresponding to the values returned by FUN. Separated for values inside or outside the time range, if calculate = both.
data(example_data_1_subject) calculate_sleep_wake(example_data_1_subject, sd_glu, calculate = "sleep") data(example_data_5_subject) calculate_sleep_wake(example_data_5_subject, cogi, targets = c(80, 150), weights = c(.3,.2,.5), calculate = "wake") calculate_sleep_wake(example_data_5_subject, sd_measures, sleep_start = 2, sleep_end = 8, calculate = "both")
data(example_data_1_subject) calculate_sleep_wake(example_data_1_subject, sd_glu, calculate = "sleep") data(example_data_5_subject) calculate_sleep_wake(example_data_5_subject, cogi, targets = c(80, 150), weights = c(.3,.2,.5), calculate = "wake") calculate_sleep_wake(example_data_5_subject, sd_measures, sleep_start = 2, sleep_end = 8, calculate = "both")
Interpolate glucose value on an equally spaced grid from day to day
CGMS2DayByDay(data, dt0 = NULL, inter_gap = 45, tz = "")
CGMS2DayByDay(data, dt0 = NULL, inter_gap = 45, tz = "")
data |
DataFrame object with column names "id", "time", and "gl". Should only be data for 1 subject. In case multiple subject ids are detected, a warning is produced and only 1st subject is used. |
dt0 |
The time frequency for interpolation in minutes, the default will match the CGM meter's frequency (e.g. 5 min for Dexcom). |
inter_gap |
The maximum allowable gap (in minutes) for interpolation. The values will not be interpolated between the glucose measurements that are more than inter_gap minutes apart. The default value is 45 min. |
tz |
A character string specifying the time zone to be used. System-specific (see |
A list with
gd2d |
A matrix of glucose values with each row corresponding to a new day, and each column corresponding to time |
actual_dates |
A vector of dates corresponding to the rows of |
dt0 |
Time frequency of the resulting grid, in minutes |
CGMS2DayByDay(example_data_1_subject)
CGMS2DayByDay(example_data_1_subject)
The function COGI produces cogi values in a tibble object.
cogi(data, targets = c(70, 180), weights = c(.5,.35,.15))
cogi(data, targets = c(70, 180), weights = c(.5,.35,.15))
data |
DataFrame with column names ("id", "time", and "gl"), or numeric vector of glucose values. |
targets |
Numeric vector of two glucose values for threshold. Glucose values from data argument will be compared to each value in the targets vector to determine the time in range and time below range for COGI. The lower value will be used for determining time below range. Default list is (70, 180). |
weights |
Numeric vector of three weights to be applied to time in range, time below range and glucose variability, respectively. The default list is (.5,.35,.15) |
A tibble object with 1 row for each subject, a column for subject id and column for each target value is returned. NA's will be omitted from the glucose values in calculation of cogi.
If a data.frame object is passed, then a tibble object with a column for subject id and then a column for each target value is returned. If a vector of glucose values is passed, then a tibble object without the subject id is returned. as.numeric() can be wrapped around the latter to output a numeric vector.
Leelarathna (2020) Evaluating Glucose Control With a Novel Composite Continuous Glucose Monitoring Index, Diabetes Technology and Therapeutics 14(2) 277-284, doi:10.1177/1932296819838525.
data(example_data_1_subject) cogi(example_data_1_subject) cogi(example_data_1_subject, targets = c(50, 140), weights = c(.3,.6,.1)) data(example_data_5_subject) cogi(example_data_5_subject) cogi(example_data_5_subject, targets = c(80, 180), weights = c(.2,.4,.4))
data(example_data_1_subject) cogi(example_data_1_subject) cogi(example_data_1_subject, targets = c(50, 140), weights = c(.3,.6,.1)) data(example_data_5_subject) cogi(example_data_5_subject) cogi(example_data_5_subject, targets = c(80, 180), weights = c(.2,.4,.4))
The function conga produces CONGA values a tibble object for any n hours apart.
conga(data, n = 24, tz = "")
conga(data, n = 24, tz = "")
data |
DataFrame object with column names "id", "time", and "gl". |
n |
An integer specifying how many hours prior to an observation should be used in the CONGA calculation. The default value is set to n = 24 hours |
tz |
A character string specifying the time zone to be used. System-specific (see |
A tibble object with 1 row for each subject, a column for subject id and a column for the CONGA values is returned.
Missing values will be linearly interpolated when close enough to non-missing values.
CONGA is the standard deviation of the difference between glucose values that are exactly n hours apart. CONGA is computed by taking the standard deviation of differences in measurements separated by n hours.
A tibble object with two columns: subject id and corresponding CONGA value.
McDonnell et al. (2005) : A novel approach to continuous glucose analysis utilizing glycemic variation Diabetes Technology and Therapeutics 7 .253-263, doi:10.1089/dia.2005.7.253.
data(example_data_1_subject) conga(example_data_1_subject) data(example_data_5_subject) conga(example_data_5_subject)
data(example_data_1_subject) conga(example_data_1_subject) data(example_data_5_subject) conga(example_data_5_subject)
The function cv_glu produces CV values in a tibble object.
cv_glu(data)
cv_glu(data)
data |
DataFrame object with column names "id", "time", and "gl", or numeric vector of glucose values. |
A tibble object with 1 row for each subject, a column for subject id and a column for CV values is returned. NA glucose values are omitted from the calculation of the CV.
CV (Coefficient of Variation) is calculated by
Where G is the list of all Glucose measurements for a subject.
If a data.frame object is passed, then a tibble object with two columns: subject id and corresponding CV value is returned. If a vector of glucose values is passed, then a tibble object with just the CV value is returned. as.numeric() can be wrapped around the latter to output just a numeric value.
Rodbard (2009) Interpretation of continuous glucose monitoring data: glycemic variability and quality of glycemic control, Diabetes Technology and Therapeutics 11 .55-67, doi:10.1089/dia.2008.0132.
data(example_data_1_subject) cv_glu(example_data_1_subject) data(example_data_5_subject) cv_glu(example_data_5_subject)
data(example_data_1_subject) cv_glu(example_data_1_subject) data(example_data_5_subject) cv_glu(example_data_5_subject)
The function cv_measures produces CV subtype values in a tibble object.
cv_measures(data, dt0 = NULL, inter_gap = 45, tz = "" )
cv_measures(data, dt0 = NULL, inter_gap = 45, tz = "" )
data |
DataFrame object with column names "id", "time", and "gl". Should only be data for 1 subject. In case multiple subject ids are detected, a warning is produced and only 1st subject is used. |
dt0 |
The time frequency for interpolation in minutes, the default will match the CGM meter's frequency (e.g. 5 min for Dexcom). |
inter_gap |
The maximum allowable gap (in minutes) for interpolation. The values will not be interpolated between the glucose measurements that are more than inter_gap minutes apart. The default value is 45 min. |
tz |
A character string specifying the time zone to be used. System-specific (see |
A tibble object with 1 row for each subject, a column for subject id and a column for each cv subtype values is returned.
Missing values will be linearly interpolated when close enough to non-missing values.
CVmean:
Calculated by first taking the coefficient of variation of each day's glucose measurements,
then taking the mean of all the coefficient of variation. That is, for x
days we compute cv_1 ... cv_x daily coefficient of variations and calculate
CVsd:
Calculated by first taking the coefficient of variation of each day's glucose measurements, then taking the standard deviation of all the coefficient of variations. That is, for d days we compute cv_1 ... cv_d daily coefficient of variations and calculate SD([cv_1, cv_2, ... cv_d])
When a data.frame object is passed, then a tibble object with three columns: subject id and corresponding CV subtype values is returned.
Umpierrez, et.al. (2018) Glycemic Variability: How to Measure and Its Clinical Implication for Type 2 Diabetes The American Journal of Medical Sciences 356 .518-527, doi:10.1016/j.amjms.2018.09.010.
data(example_data_1_subject) cv_measures(example_data_1_subject) data(example_data_5_subject) cv_measures(example_data_5_subject)
data(example_data_1_subject) cv_measures(example_data_1_subject) data(example_data_5_subject) cv_measures(example_data_5_subject)
The function ea1c produces eA1C values in a tibble object.
ea1c(data)
ea1c(data)
data |
DataFrame object with column names "id", "time", and "gl", or numeric vector of glucose values. |
A tibble object with 1 row for each subject, a column for subject id and a column for eA1C values is returned. NA glucose values are omitted from the calculation of the eA1C.
eA1C score is calculated by
where G is the vector of Glucose Measurements (mg/dL).
If a data.frame object is passed, then a tibble object with two columns: subject id and corresponding eA1C is returned. If a vector of glucose values is passed, then a tibble object with just the eA1C value is returned. as.numeric() can be wrapped around the latter to output just a numeric value.
Marielle Hicban
Nathan (2008) Translating the A1C assay into estimated average glucose values Hormone and Metabolic Research 31 .1473-1478, doi:10.2337/dc08-0545.
data(example_data_1_subject) ea1c(example_data_1_subject) data(example_data_5_subject) ea1c(example_data_5_subject)
data(example_data_1_subject) ea1c(example_data_1_subject) data(example_data_5_subject) ea1c(example_data_5_subject)
Display Episode Calculation statistics for selected subject
epicalc_profile( data, lv1_hypo = 70, lv2_hypo = 54, lv1_hyper = 180, lv2_hyper = 250, dur_length = 15, end_length = 15, subject = NULL, dt0 = NULL, inter_gap = 45, tz = "" )
epicalc_profile( data, lv1_hypo = 70, lv2_hypo = 54, lv1_hyper = 180, lv2_hyper = 250, dur_length = 15, end_length = 15, subject = NULL, dt0 = NULL, inter_gap = 45, tz = "" )
data |
DataFrame object with column names "id", "time", and "gl". Should only be data for 1 subject. In case multiple subject ids are detected, a warning is produced and only 1st subject is used. |
lv1_hypo |
Numeric value specifying a hypoglycemia threshold for level 1 |
lv2_hypo |
Numeric value specifying a hypoglycemia threshold for level 2 |
lv1_hyper |
Numeric value specifying a hyperglycemia threshold for level 1 |
lv2_hyper |
Numeric value specifying a hyperglycemia threshold for level 2 |
dur_length |
Numeric value specifying the minimum duration in minutes to be considered an episode. Note dur_length should be a multiple of the data recording interval otherwise the function will round up to the nearest multiple. Default is 15 minutes to match consensus. |
end_length |
Numeric value specifying the minimum duration in minutes of improved glycemia for an episode to end. Default is equal to dur_length to match consensus. |
subject |
String corresponding to subject id |
dt0 |
The time frequency for interpolation in minutes, the default will match the CGM meter's frequency (e.g. 5 min for Dexcom). |
inter_gap |
The maximum allowable gap (in minutes) for interpolation. The values will not be interpolated between the glucose measurements that are more than inter_gap minutes apart. The default value is 45 min. |
tz |
A character string specifying the time zone to be used. System-specific (see |
A plot displaying (1) the statistics for the episodes and (2) the episodes colored by level.
Johnathan Shih, Jung Hoon Seo, Elizabeth Chun
episode_calculation()
epicalc_profile(example_data_1_subject)
epicalc_profile(example_data_1_subject)
The function determines episodes or events, calculates summary statistics, and optionally returns data with episode label columns added
episode_calculation( data, lv1_hypo = 70, lv2_hypo = 54, lv1_hyper = 180, lv2_hyper = 250, dur_length = 15, end_length = 15, return_data = FALSE, dt0 = NULL, inter_gap = 45, tz = "" )
episode_calculation( data, lv1_hypo = 70, lv2_hypo = 54, lv1_hyper = 180, lv2_hyper = 250, dur_length = 15, end_length = 15, return_data = FALSE, dt0 = NULL, inter_gap = 45, tz = "" )
data |
DataFrame object with column names "id", "time", and "gl". Should only be data for 1 subject. In case multiple subject ids are detected, a warning is produced and only 1st subject is used. |
lv1_hypo |
Numeric value specifying a hypoglycemia threshold for level 1 |
lv2_hypo |
Numeric value specifying a hypoglycemia threshold for level 2 |
lv1_hyper |
Numeric value specifying a hyperglycemia threshold for level 1 |
lv2_hyper |
Numeric value specifying a hyperglycemia threshold for level 2 |
dur_length |
Numeric value specifying the minimum duration in minutes to be considered an episode. Note dur_length should be a multiple of the data recording interval otherwise the function will round up to the nearest multiple. Default is 15 minutes to match consensus. |
end_length |
Numeric value specifying the minimum duration in minutes of improved glycemia for an episode to end. Default is equal to dur_length to match consensus. |
return_data |
Boolean indicating whether to also return data with episode labels. Defaults to FALSE which means only episode summary statistics will be returned |
dt0 |
The time frequency for interpolation in minutes, the default will match the CGM meter's frequency (e.g. 5 min for Dexcom). |
inter_gap |
The maximum allowable gap (in minutes) for interpolation. The values will not be interpolated between the glucose measurements that are more than inter_gap minutes apart. The default value is 45 min. |
tz |
A character string specifying the time zone to be used. System-specific (see |
We follow the definition of episodes given in the 2023 consensus by Battelino et al. Note we have classified lv2 as a subset of lv1 since we find the consensus to be slightly ambiguous. For lv1 exclusive of lv2, please see lv1_excl which summarises episodes that were exclusively lv1 and did not cross the lv2 threshold. Also note, hypo extended refers to episodes that are >120 consecutive minutes below lv1 hypo and ends with at least 15 minutes of normoglycemia. For more details on each category please see the reference below (Battelino et al 2023).
If return_data is FALSE, a single dataframe with columns:
id |
Subject id |
type |
Type of episode - either hypoglycemia or hyperglycemia |
level |
Level of episode - one of lv1, lv2, extended, lv1_excl |
avg_ep_per_day |
Average number of episodes per day calculated as (total # episodes)/(recording time in days (24hrs)) |
avg_ep_duration |
Average duration of episodes in minutes |
avg_ep_gl |
Average glucose in the episode in mg/dL |
total_episodes |
Total number of episodes in the subject's glucose trace |
If return_data is TRUE, returns a list where the first entry is the episode summary dataframe (see above) and the second entry is the input data with episode labels added. Note the data returned here has been interpolated using the CGMS2DayByDay() function. Mostly for use with epicalc_profile function. Format of the second list entry is:
id |
Subject id |
time |
Interpolated timestamps |
gl |
glucose in mg/dL |
[episode_label] |
One column per episode label - i.e. lv1_hypo, lv2_hypo, lv1_hyper, lv2_hyper, ext_hypo. 0 means not this type of episode, a positive integer label is assigned to each episode. Note the labels are *not* unique by subject only unique by segment |
Elizabeth Chun, Jung Hoon Seo, Johnathan Shih
Battelino et al. (2023): Continuous glucose monitoring and metrics for clinical trials: an international consensus statement Lancet Diabetes & Endocrinology 11(1) .42-57, doi:10.1016/s2213-8587(22)00319-9.
epicalc_profile()
episode_calculation(example_data_5_subject, lv1_hypo=100, lv1_hyper= 120)
episode_calculation(example_data_5_subject, lv1_hypo=100, lv1_hyper= 120)
Dexcom G4 CGM measurements from 1 subject with Type II diabetes, this is a subset of example_data_5_subject.
example_data_1_subject
example_data_1_subject
A data.frame with 2915 rows and 3 columns, which are:
identifier of subject
5-10 minute time value
glucose level
Dexcom G4 CGM measurements for 5 subjects with Type II diabetes.
These data are part of a larger study sample that consisted of patients with Type 2
diabetes recruited from the general community. To be eligible, patients with Type 2 diabetes, not using insulin therapy and with a glycosylated hemoglobin () value at least 6.5
example_data_5_subject
example_data_5_subject
A data.frame with 13866 rows and 3 columns, which are:
identifier of subject
date and time stamp
glucose level as measured by CGM (mg/dL)
Dexcom G4 CGM measurements for 19 subjects from the Hall publicly available dataset. Chosen as a subset of all subjects to be only those with diabetes or pre-diabetes. Primarily intended for use with example_meals_hall
example_data_hall
example_data_hall
a data.frame with 34890 rows and 4 columns, which are:
identifier of subject
date and time stamp
glucose level as measured by CGM (mg/dL)
character indicating diabetes diagnosis: diabetic or pre-diabetic
This dataset can be used along with the example_meals_hall dataset in this package to calculate meal_metrics.
Hall et al. (2018) : Glucotypes reveal new patterns of glucose dysregulation Plos Biology 16 (7): 3:e2005143 doi:10.1371/journal.pbio.2005143.
Example of mealtimes data format for meal_metrics function, corresponds to example_data_hall data.
example_meals_hall
example_meals_hall
A data.frame with 9 rows and 3 columns, which are:
identifier of subject
meal type identifier
time of meal
There are 3 types of meals available: Cereal Flakes (CF), Peanut Butter Sandwich (PB), and Protein Bar (Bar). The number after the abbreviation refers to the replication number for the original study. For more details on nutritional differences, please see the original study reference.
This dataset should be used along with example_data_hall to calculate meal_metrics.
Hall et al. (2018) : Glucotypes reveal new patterns of glucose dysregulation Plos Biology 16 (7): 3:e2005143 doi:10.1371/journal.pbio.2005143.
The function gmi produces GMI values in a tibble object.
gmi(data)
gmi(data)
data |
DataFrame object with column names "id", "time", and "gl", or numeric vector of glucose values. |
A tibble object with 1 row for each subject, a column for subject id and a column for GMI values is returned. NA glucose values are omitted from the calculation of the GMI.
GMI score is calculated by
where G is the vector of Glucose Measurements (mg/dL).
If a data.frame object is passed, then a tibble object with two columns: subject id and corresponding GMI is returned. If a vector of glucose values is passed, then a tibble object with just the GMI value is returned. as.numeric() can be wrapped around the latter to output just a numeric value.
Bergenstal (2018) Glucose Management Indicator (GMI): A New Term for Estimating A1C From Continuous Glucose Monitoring Hormone and Metabolic Research 41 .2275-2280, doi:10.2337/dc18-1581.
data(example_data_1_subject) gmi(example_data_1_subject) data(example_data_5_subject) gmi(example_data_5_subject)
data(example_data_1_subject) gmi(example_data_1_subject) data(example_data_5_subject) gmi(example_data_5_subject)
The function grade produces GRADE score values in a tibble object.
grade(data)
grade(data)
data |
DataFrame object with column names "id", "time", and "gl", or numeric vector of glucose values. |
A tibble object with 1 row for each subject, a column for subject id and a column for GRADE values is returned. NA glucose values are omitted from the calculation of the GRADE.
GRADE score is calculated by
Where
is the ith Glucose measurement and n is the total
number of measurements.
If a data.frame object is passed, then a tibble object with two columns: subject id and corresponding GRADE value is returned. If a vector of glucose values is passed, then a tibble object with just the GRADE value is returned. as.numeric() can be wrapped around the latter to output just a numeric value.
Hill et al. (2007): A method for assessing quality of control from glucose profiles Diabetic Medicine 24 .753-758, doi:10.1111/j.1464-5491.2007.02119.x.
data(example_data_1_subject) grade(example_data_1_subject) data(example_data_5_subject) grade(example_data_5_subject)
data(example_data_1_subject) grade(example_data_1_subject) data(example_data_5_subject) grade(example_data_5_subject)
The function grade_eugly produces %GRADE euglycemia values in a tibble object.
grade_eugly(data, lower = 70, upper = 140)
grade_eugly(data, lower = 70, upper = 140)
data |
DataFrame object with column names "id", "time", and "gl", or numeric vector of glucose values. |
lower |
Lower bound used for hypoglycemia cutoff, in mg/dL. Default is 70 |
upper |
Upper bound used for hyperglycemia cutoff, in mg/dL. Default is 140. |
A tibble object with 1 row for each subject, a column for subject id and a column for %GRADE euglycemia values is returned. NA glucose values are omitted from the calculation of the %GRADE euglycemia values.
%GRADE euglycemia is determined by calculating the percentage of GRADE score (see grade function) attributed to values in the target range, i.e. values not below hypoglycemic or above hyperglycemic cutoffs.
If a data.frame object is passed, then a tibble object with two columns: subject id and corresponding %GRADE euglycemia value is returned. If a vector of glucose values is passed, then a tibble object with just the %GRADE euglycemia value is returned. as.numeric() can be wrapped around the latter to output just a numeric value.
Hill et al. (2007): A method for assessing quality of control from glucose profiles Diabetic Medicine 24 .753-758, doi:10.1111/j.1464-5491.2007.02119.x.
data(example_data_1_subject) grade_eugly(example_data_1_subject) grade_eugly(example_data_1_subject, lower = 80, upper = 180) data(example_data_5_subject) grade_eugly(example_data_5_subject) grade_eugly(example_data_5_subject, lower = 80, upper = 160)
data(example_data_1_subject) grade_eugly(example_data_1_subject) grade_eugly(example_data_1_subject, lower = 80, upper = 180) data(example_data_5_subject) grade_eugly(example_data_5_subject) grade_eugly(example_data_5_subject, lower = 80, upper = 160)
The function grade_hyper produces %GRADE hyperglycemia values in a tibble object.
grade_hyper(data, upper = 140)
grade_hyper(data, upper = 140)
data |
DataFrame object with column names "id", "time", and "gl", or numeric vector of glucose values. |
upper |
Upper bound used for hyperglycemia cutoff, in mg/dL. Default is 140. |
A tibble object with 1 row for each subject, a column for subject id and a column for %GRADE hyperglycemia values is returned. NA glucose values are omitted from the calculation of the %GRADE hyperglycemia values.
%GRADE hyperglycemia is determined by calculating the percentage of GRADE score (see grade function) attributed to hyperglycemic glucose values.
If a data.frame object is passed, then a tibble object with two columns: subject id and corresponding %GRADE hyperglycemia value is returned. If a vector of glucose values is passed, then a tibble object with just the %GRADE hyperglycemia value is returned. as.numeric() can be wrapped around the latter to output just a numeric value.
Hill et al. (2007): A method for assessing quality of control from glucose profiles Diabetic Medicine 24 .753-758, doi:10.1111/j.1464-5491.2007.02119.x.
data(example_data_1_subject) grade_hyper(example_data_1_subject) grade_hyper(example_data_1_subject, upper = 180) data(example_data_5_subject) grade_hyper(example_data_5_subject) grade_hyper(example_data_5_subject, upper = 160)
data(example_data_1_subject) grade_hyper(example_data_1_subject) grade_hyper(example_data_1_subject, upper = 180) data(example_data_5_subject) grade_hyper(example_data_5_subject) grade_hyper(example_data_5_subject, upper = 160)
The function grade_hypo produces %GRADE hypoglycemia values in a tibble object.
grade_hypo(data, lower = 80)
grade_hypo(data, lower = 80)
data |
DataFrame object with column names "id", "time", and "gl", or numeric vector of glucose values. |
lower |
Lower bound used for hypoglycemia cutoff, in mg/dL. Default is 80 |
A tibble object with 1 row for each subject, a column for subject id and a column for %GRADE hypoglycemia values is returned. NA glucose values are omitted from the calculation of the %GRADE hypoglycemia values.
%GRADE hypoglycemia is determined by calculating the percentage of GRADE score (see grade function) attributed to hypoglycemic glucose values.
If a data.frame object is passed, then a tibble object with two columns: subject id and corresponding %GRADE hypoglycemia value is returned. If a vector of glucose values is passed, then a tibble object with just the %GRADE hypoglycemia value is returned. as.numeric() can be wrapped around the latter to output just a numeric value.
Hill et al. (2007): A method for assessing quality of control from glucose profiles Diabetic Medicine 24 .753-758, doi:10.1111/j.1464-5491.2007.02119.x.
data(example_data_1_subject) grade_hypo(example_data_1_subject) grade_hypo(example_data_1_subject, lower = 70) data(example_data_5_subject) grade_hypo(example_data_5_subject) grade_hypo(example_data_5_subject, lower = 65)
data(example_data_1_subject) grade_hypo(example_data_1_subject) grade_hypo(example_data_1_subject, lower = 70) data(example_data_5_subject) grade_hypo(example_data_5_subject) grade_hypo(example_data_5_subject, lower = 65)
The function gri produces a tibble object with values equal to the glycemia risk index (GRI) metric. The output columns are subject id and GRI value. ' The output rows correspond to subjects.
gri(data, tz = "")
gri(data, tz = "")
data |
DataFrame object with column names "id", "time", and "gl", or numeric vector of glucose values. |
tz |
Default: "". A character string specifying the time zone to be used. System-specific (see |
A tibble object with 1 row for each subject, a column for subject id and column for GRI is returned. The formula for GRI is as follows:
where VLow, Low, VHigh, and High correspond to the percent of glucose values in the ranges <54 mg/dL, 54-70 mg/dL, >250 mg/dL, and 180-250 mg/dL respectively. The maximum allowed value for GRI is 100%, any calculated values higher than 100 are capped.
A tibble object with columns for subject id and GRI value. Rows correspond to individual subjects.
Elizabeth Chun
Klonoff et al. (2022) A Glycemia Risk Index (GRI) of Hypoglycemia and Hyperglycemia for Continuous Glucose Monitoring Validated by Clinician Ratings. J Diabetes Sci Technol doi:10.1177/19322968221085273.
data(example_data_1_subject) gri(example_data_1_subject) data(example_data_5_subject) gri(example_data_5_subject, tz = 'GMT')
data(example_data_1_subject) gri(example_data_1_subject) data(example_data_5_subject) gri(example_data_5_subject, tz = 'GMT')
The function mad produces GVP values in a tibble object.
gvp(data)
gvp(data)
data |
DataFrame object with column names "id", "time", and "gl" |
A tibble object with 1 row for each subject, a column for subject id and a column for GVP values is returned. NA glucose values are omitted from the calculation of the GVP.
GVP is calculated by dividing the total length of the line of the glucose trace
by the length of a perfectly flat trace. The formula for this is
, where diff is the change in
Glucose measurements from one reading to the next,
dt0 is the time gap between measurements and n is the number of glucose readings
A tibble object with two columns: subject id and corresponding GVP value.
David Buchanan, Mary Martin
Peyser et al. (2017) Glycemic Variability Percentage: A Novel Method for Assessing Glycemic Variability from Continuous Glucose Monitor Data. Diabetes Technol Ther 20(1):6–16, doi:10.1089/dia.2017.0187.
data(example_data_1_subject) gvp(example_data_1_subject) data(example_data_5_subject) gvp(example_data_5_subject)
data(example_data_1_subject) gvp(example_data_1_subject) data(example_data_5_subject) gvp(example_data_5_subject)
The function hbgi produces HBGI values in a tibble object.
hbgi(data)
hbgi(data)
data |
DataFrame object with column names "id", "time", and "gl", or numeric vector of glucose values. |
A tibble object with 1 row for each subject, a column for subject id and a column for HBGI values is returned. NA glucose values are omitted from the calculation of the HBGI.
HBGI is calculated by ,
where
,
G_i is the ith Glucose measurement for a subject, and
n is the total number of measurements for that subject.
If a data.frame object is passed, then a tibble object with two columns: subject id and corresponding HBGI value is returned. If a vector of glucose values is passed, then a tibble object with just the HBGI value is returned. as.numeric() can be wrapped around the latter to output just a numeric value.
Kovatchev et al. (2006) Evaluation of a New Measure of Blood Glucose Variability in, Diabetes Diabetes care 29 .2433-2438, doi:10.2337/dc06-1085.
data(example_data_1_subject) hbgi(example_data_1_subject) data(example_data_5_subject) hbgi(example_data_5_subject)
data(example_data_1_subject) hbgi(example_data_1_subject) data(example_data_5_subject) hbgi(example_data_5_subject)
The function hist_roc produces a histogram plot of ROC values
hist_roc(data, subjects = NULL, timelag = 15, dt0 = NULL, inter_gap = 45, tz = "")
hist_roc(data, subjects = NULL, timelag = 15, dt0 = NULL, inter_gap = 45, tz = "")
data |
DataFrame object with column names "id", "time", and "gl". |
subjects |
String or list of strings corresponding to subject names in 'id' column of data. Default is all subjects. |
timelag |
Integer indicating the time period (# minutes) over which rate of change is calculated. Default is 15, e.g. rate of change is the change in glucose over the past 15 minutes divided by 15. |
dt0 |
The time frequency for interpolation in minutes, the default will match the CGM meter's frequency (e.g. 5 min for Dexcom). |
inter_gap |
The maximum allowable gap (in minutes) for interpolation. The values will not be interpolated between the glucose measurements that are more than inter_gap minutes apart. The default value is 45 min. |
tz |
A character string specifying the time zone to be used. System-specific (see |
For the default, a histogram is produced for each subject displaying the ROC values colored by ROC categories defined as follows. The breaks for the categories are: c(-Inf, -3, -2, -1, 1, 2, 3, Inf) where the glucose is in mg/dl and the ROC values are in mg/dl/min. A ROC of -5 mg/dl/min will thus be placed in the first category and colored accordingly.
A histogram of ROC values per subject
Elizabeth Chun, David Buchanan
Clarke et al. (2009) Statistical Tools to Analyze Continuous Glucose Monitor Data, Diabetes Diabetes Technology and Therapeutics 11 S45-S54, doi:10.1089/dia.2008.0138.
plot_roc
for reference paper on ROC categories.
data(example_data_1_subject) hist_roc(example_data_1_subject) data(example_data_5_subject) hist_roc(example_data_5_subject) hist_roc(example_data_5_subject, subjects = 'Subject 3')
data(example_data_1_subject) hist_roc(example_data_1_subject) data(example_data_5_subject) hist_roc(example_data_5_subject) hist_roc(example_data_5_subject, subjects = 'Subject 3')
The function hyper_index produces Hyperglycemia Index values in a tibble object.
hyper_index(data, ULTR = 140, a = 1.1, c = 30)
hyper_index(data, ULTR = 140, a = 1.1, c = 30)
data |
DataFrame object with column names "id", "time", and "gl", or numeric vector of glucose values. |
ULTR |
Upper Limit of Target Range, default value is 140 mg/dL. |
a |
Exponent, generally in the range from 1.0 to 2.0, default value is 1.1. |
c |
Scaling factor, to display Hyperglycemia Index, Hypoglycemia Index, and IGC on approximately the same numerical range as measurements of HBGI, LBGI and GRADE, default value is 30. |
A tibble object with 1 row for each subject, a column for subject id and a column for the Hyperglycemia Index values is returned. NA glucose values are omitted from the calculation of the Hyperglycemia Index values.
Hyperglycemia Index is calculated by .
Here n is the total number of Glucose measurements (excluding NA values),
is the jth Glucose measurement above the ULTR cutoff, a is an exponent, and c is a scaling factor.
If a data.frame object is passed, then a tibble object with two columns: subject id and corresponding Hyperglycemia Index value is returned. If a vector of glucose values is passed, then a tibble object with just the Hyperglycemia Index value is returned. as.numeric() can be wrapped around the latter to output just a numeric value.
Rodbard (2009) Interpretation of continuous glucose monitoring data: glycemic variability and quality of glycemic control, Diabetes Technology and Therapeutics 11 .55-67, doi:10.1089/dia.2008.0132.
data(example_data_1_subject) hyper_index(example_data_1_subject) hyper_index(example_data_1_subject, ULTR = 160) data(example_data_5_subject) hyper_index(example_data_5_subject) hyper_index(example_data_5_subject, ULTR = 150)
data(example_data_1_subject) hyper_index(example_data_1_subject) hyper_index(example_data_1_subject, ULTR = 160) data(example_data_5_subject) hyper_index(example_data_5_subject) hyper_index(example_data_5_subject, ULTR = 150)
The function hypo_index produces Hypoglycemia index values in a tibble object.
hypo_index(data, LLTR = 80, b = 2, d = 30)
hypo_index(data, LLTR = 80, b = 2, d = 30)
data |
DataFrame object with column names "id", "time", and "gl", or numeric vector of glucose values. |
LLTR |
Lower Limit of Target Range, default value is 80 mg/dL. |
b |
Exponent, generally in the range from 1.0 to 2.0, default value is 2. |
d |
Scaling factor,to display Hyperglycemia Index, Hypoglycemia Index, and IGC on approximately the same numerical range as measurements of HBGI, LBGI and GRADE, default value is 30. |
A tibble object with 1 row for each subject, a column for subject id and a column for the Hypoglycemia Index values is returned. NA glucose values are omitted from the calculation of the Hypoglycemia Index values.
Hypoglycemia Index is calculated by .
Here n is the total number of Glucose measurements (excluding NA values),
and
is the jth Glucose measurement below the LLTR cutoff, b is an exponent, and d is a scaling factor.
If a data.frame object is passed, then a tibble object with two columns: subject id and corresponding Hypoglycemia Index value is returned. If a vector of glucose values is passed, then a tibble object with just the Hypoglycemia Index value is returned. as.numeric() can be wrapped around the latter to output just a numeric value.
Rodbard (2009) Interpretation of continuous glucose monitoring data: glycemic variability and quality of glycemic control, Diabetes Technology and Therapeutics 11 .55-67, doi:10.1089/dia.2008.0132.
data(example_data_1_subject) hypo_index(example_data_1_subject, LLTR = 60) data(example_data_5_subject) hypo_index(example_data_5_subject) hypo_index(example_data_5_subject, LLTR = 70)
data(example_data_1_subject) hypo_index(example_data_1_subject, LLTR = 60) data(example_data_5_subject) hypo_index(example_data_5_subject) hypo_index(example_data_5_subject, LLTR = 70)
The function igc produces IGC values in a tibble object.
igc(data, LLTR = 80, ULTR = 140, a = 1.1, b = 2, c = 30, d = 30)
igc(data, LLTR = 80, ULTR = 140, a = 1.1, b = 2, c = 30, d = 30)
data |
DataFrame object with column names "id", "time", and "gl", or numeric vector of glucose values. |
LLTR |
Lower Limit of Target Range, default value is 80 mg/dL. |
ULTR |
Upper Limit of Target Range, default value is 140 mg/dL. |
a |
Exponent, generally in the range from 1.0 to 2.0, default value is 1.1. |
b |
Exponent, generally in the range from 1.0 to 2.0, default value is 2. |
c |
Scaling factor, to display Hyperglycemia Index, Hypoglycemia Index, and IGC on approximately the same numerical range as measurements of HBGI, LBGI and GRADE, default value is 30. |
d |
Scaling factor,to display Hyperglycemia Index, Hypoglycemia Index, and IGC on approximately the same numerical range as measurements of HBGI, LBGI and GRADE, default value is 30. |
A tibble object with 1 row for each subject, a column for subject id and a column for the IGC values is returned.
IGC is calculated by taking the sum of the Hyperglycemia
Index and the Hypoglycemia index. See hypo_index
and
hyper_index
.
A tibble object with two columns: subject id and corresponding IGC value.
Rodbard (2009) Interpretation of continuous glucose monitoring data: glycemic variability and quality of glycemic control, Diabetes Technology and Therapeutics 11 .55-67, doi:10.1089/dia.2008.0132.
data(example_data_1_subject) igc(example_data_1_subject) igc(example_data_1_subject, ULTR = 160) data(example_data_5_subject) igc(example_data_5_subject) igc(example_data_5_subject, LLTR = 75, ULTR = 150)
data(example_data_1_subject) igc(example_data_1_subject) igc(example_data_1_subject, ULTR = 160) data(example_data_5_subject) igc(example_data_5_subject) igc(example_data_5_subject, LLTR = 75, ULTR = 150)
The function in_range_percent produces a tibble object with values equal to the percentage of glucose measurements in ranges of target values. The output columns correspond to subject id followed by the target value ranges, and the rows correspond to the subjects. The values will be between 0 (no measurements) and 100 (all measurements).
in_range_percent(data, target_ranges = list(c(70, 180), c(63, 140)))
in_range_percent(data, target_ranges = list(c(70, 180), c(63, 140)))
data |
DataFrame object with column names "id", "time", and "gl", or numeric vector of glucose values. |
target_ranges |
List of target value ranges wrapped in an r 'list' structure. Default list of ranges is ((70, 180), (63, 140)) mg/dL, where the range (70, 180) is recommended to assess glycemic control for subjects with type 1 or type 2 diabetes, and (63, 140) is recommended for assessment of glycemic control during pregnancy; see Battelino et al. (2019) |
A tibble object with 1 row for each subject, a column for subject id and column for each range of target values is returned. NA's will be omitted from the glucose values in calculation of percent.
in_range_percent will only work properly if the target_ranges argument is a list of paired values in the format list(c(a1,b1), c(a2,b2), ...). The paired values can be ordered (min, max) or (max, min). See the Examples section for proper usage.
If a data.frame object is passed, then a tibble object with a column for subject id and then a column for each target value is returned. If a vector of glucose values is passed, then a tibble object without the subject id is returned. as.numeric() can be wrapped around the latter to output a numeric vector.
Rodbard (2009) Interpretation of continuous glucose monitoring data: glycemic variability and quality of glycemic control, Diabetes Technology and Therapeutics 11 .55-67, doi:10.1089/dia.2008.0132.
Battelino et al. (2019) Clinical targets for continuous glucose monitoring data interpretation: recommendations from the international consensus on time in range. Diabetes Care 42(8):1593-603, doi:10.2337/dci19-0028
plot_ranges()
data(example_data_1_subject) in_range_percent(example_data_1_subject) in_range_percent(example_data_1_subject, target_ranges = list(c(50, 100), c(200, 300), c(80, 140))) data(example_data_5_subject) in_range_percent(example_data_5_subject) in_range_percent(example_data_1_subject, target_ranges = list(c(60, 120), c(140, 250)))
data(example_data_1_subject) in_range_percent(example_data_1_subject) in_range_percent(example_data_1_subject, target_ranges = list(c(50, 100), c(200, 300), c(80, 140))) data(example_data_5_subject) in_range_percent(example_data_5_subject) in_range_percent(example_data_1_subject, target_ranges = list(c(60, 120), c(140, 250)))
The function iqr_glu outputs the distance between the 25th percentile and the 25th percentile of the glucose values in a tibble object.
iqr_glu(data)
iqr_glu(data)
data |
DataFrame object with column names "id", "time", and "gl", or numeric vector of glucose values. |
A tibble object with 1 row for each subject, a column for subject id and a column for the IQR values is returned. NA glucose values are omitted from the calculation of the IQR.
If a data.frame object is passed, then a tibble object with two columns: subject id and corresponding IQR value is returned. If a vector of glucose values is passed, then a tibble object with just the IQR value is returned. as.numeric() can be wrapped around the latter to output just a numeric value.
data(example_data_1_subject) iqr_glu(example_data_1_subject) data(example_data_5_subject) iqr_glu(example_data_5_subject)
data(example_data_1_subject) iqr_glu(example_data_1_subject) data(example_data_5_subject) iqr_glu(example_data_5_subject)
The function j_index produces J-Index values a tibble object.
j_index(data)
j_index(data)
data |
DataFrame object with column names "id", "time", and "gl", or numeric vector of glucose values. |
A tibble object with 1 row for each subject, a column for subject id and a column for J-Index values is returned. NA glucose values are omitted from the calculation of the J-Index.
J-Index score is calculated by
where G is the list of Glucose Measurements.
If a data.frame object is passed, then a tibble object with two columns: subject id and corresponding J-Index value is returned. If a vector of glucose values is passed, then a tibble object with just the J-Index value is returned. as.numeric() can be wrapped around the latter to output just a numeric value.
Wojcicki (1995) "J"-index. A new proposition of the assessment of current glucose control in diabetic patients Hormone and Metabolic Research 27 .41-42, doi:10.1055/s-2007-979906.
data(example_data_1_subject) j_index(example_data_1_subject) data(example_data_5_subject) j_index(example_data_5_subject)
data(example_data_1_subject) j_index(example_data_1_subject) data(example_data_5_subject) j_index(example_data_5_subject)
The function lbgi produces LBGI values in a tibble object.
lbgi(data)
lbgi(data)
data |
DataFrame object with column names "id", "time", and "gl", or numeric vector of glucose values. |
A tibble object with 1 row for each subject, a column for subject id and a column for LBGI values is returned. NA glucose values are omitted from the calculation of the LBGI.
LBGI is calculated by ,
where
,
G_i is the ith Glucose measurement for a subject, and
n is the total number of measurements for that subject.
If a data.frame object is passed, then a tibble object with two columns: subject id and corresponding LBGI value is returned. If a vector of glucose values is passed, then a tibble object with just the LBGI value is returned. as.numeric() can be wrapped around the latter to output just a numeric value.
Kovatchev et al. (2006) Evaluation of a New Measure of Blood Glucose Variability in, Diabetes Diabetes care 29 .2433-2438, doi:10.2337/dc06-1085.
data(example_data_1_subject) lbgi(example_data_1_subject) data(example_data_5_subject) lbgi(example_data_5_subject)
data(example_data_1_subject) lbgi(example_data_1_subject) data(example_data_5_subject) lbgi(example_data_5_subject)
Calculates the M-value of Schlichtkrull et al. (1965) for each subject in the data, where the M-value is the mean of the logarithmic transformation of the deviation from a reference value. Produces a tibble object with subject id and M-values.
m_value(data, r = 90)
m_value(data, r = 90)
data |
DataFrame object with column names "id", "time", and "gl", or numeric vector of glucose values. |
r |
A reference value corresponding to basal glycemia in normal subjects; default is 90 mg/dL. |
A tibble object with 1 row for each subject, a column for subject id and a column for the M-values is returned. NA glucose values are omitted from the calculation of the M-value.
M-value is computed by averaging the transformed glucose values, where each
transformed value is equal to , where r is the specified reference value.
If a data.frame object is passed, then a tibble object with two columns: subject id and corresponding M-value is returned. If a vector of glucose values is passed, then a tibble object with just the M-value is returned. as.numeric() can be wrapped around the latter to output just a numeric value.
Schlichtkrull J, Munck O, Jersild M. (1965) The M-value, an index of blood-sugar control in diabetics. Acta Medica Scandinavica 177 .95-102. doi:10.1111/j.0954-6820.1965.tb01810.x.
data(example_data_5_subject) m_value(example_data_5_subject) m_value(example_data_5_subject, r = 100)
data(example_data_5_subject) m_value(example_data_5_subject) m_value(example_data_5_subject, r = 100)
The function mad produces MAD values in a tibble object.
mad_glu(data, constant = 1.4826)
mad_glu(data, constant = 1.4826)
data |
DataFrame object with column names "id", "time", and "gl", or numeric vector of glucose values. |
constant |
Numeric object which will be multipled by the MAD value. Defaults to 1.4826. Reasons for this default value can be seen in the details section of the documentation of r's base mad method |
A tibble object with 1 row for each subject, a column for subject id and a column for MAD values is returned. NA glucose values are omitted from the calculation of the MAD.
MAD is calculated by taking the median of the difference of the
glucose readings from their median and multiplying it by a scaling factor
, where gl is the list of Glucose measurements.
If a data.frame object is passed, then a tibble object with two columns: subject id and corresponding MAD value is returned. If a vector of glucose values is passed, then a tibble object with just the MAD value is returned. as.numeric() can be wrapped around the latter to output just a numeric value.
David Buchanan, Marielle Hicban
data(example_data_1_subject) mad_glu(example_data_1_subject) data(example_data_5_subject) mad_glu(example_data_5_subject)
data(example_data_1_subject) mad_glu(example_data_1_subject) data(example_data_5_subject) mad_glu(example_data_5_subject)
The function mag calculates the mean absolute glucose or MAG.
mag(data, n = 60, dt0 = NULL, inter_gap = 45, tz = "")
mag(data, n = 60, dt0 = NULL, inter_gap = 45, tz = "")
data |
DataFrame object with column names "id", "time", and "gl". |
n |
Integer giving the desired interval in minutes over which to calculate the change in glucose. Default is 60 to have hourly (60 minutes) intervals. |
dt0 |
The time frequency for interpolation in minutes, the default will match the CGM meter's frequency (e.g. 5 min for Dexcom). |
inter_gap |
The maximum allowable gap (in minutes) for interpolation. The values will not be interpolated between the glucose measurements that are more than inter_gap minutes apart. The default value is 45 min. |
tz |
A character string specifying the time zone to be used. System-specific (see |
A tibble object with a column for subject id and a column for MAG values is returned.
The glucose values are linearly interpolated over a time grid starting at the
beginning of the first day of data and ending on the last day of data. Then, MAG
is calculated as where
is
the sum of the absolute change in glucose calculated for each interval as specified
by n, default n = 60 for hourly change in glucose. The sum is then divided by
which is the total time in hours.
A tibble object with two columns: subject id and MAG value
Elizabeth Chun
Hermanides et al. (2010) Glucose Variability is Associated with Intensive Care Unit Mortaility, Critical Care Medicine 38(3) 838-842, doi:10.1097/CCM.0b013e3181cc4be9
data(example_data_1_subject) mag(example_data_1_subject) data(example_data_5_subject) mag(example_data_5_subject)
data(example_data_1_subject) mag(example_data_1_subject) data(example_data_5_subject) mag(example_data_5_subject)
The function calculates MAGE values and can optionally return a plot of the glucose trace.
mage( data, version = c("ma", "naive"), sd_multiplier = 1, short_ma = 5, long_ma = 32, return_type = c("num", "df"), direction = c("avg", "service", "max", "plus", "minus"), tz = "", inter_gap = 45, max_gap = 180, plot = FALSE, title = NA, xlab = NA, ylab = NA, show_ma = FALSE, show_excursions = TRUE )
mage( data, version = c("ma", "naive"), sd_multiplier = 1, short_ma = 5, long_ma = 32, return_type = c("num", "df"), direction = c("avg", "service", "max", "plus", "minus"), tz = "", inter_gap = 45, max_gap = 180, plot = FALSE, title = NA, xlab = NA, ylab = NA, show_ma = FALSE, show_excursions = TRUE )
data |
DataFrame object with column names "id", "time", and "gl" OR numeric vector of glucose values. |
version |
Either |
sd_multiplier |
A numeric value that can change the sd value used to determine size of
glycemic excursions used in the calculation. This is the only parameter that
can be specified for |
short_ma |
Default: 5. Integer for period length of the short moving average. Must be positive and less than 'long_ma'. (Recommended <15) |
long_ma |
Default: 32. Integer for period length for the long moving average. Must be positive and greater than 'short_ma'. (Recommended >20) |
return_type |
Default: "num". One of ("num", "df"). Will return either a single number for the "MAGE over the entire trace" (weighted by segment length) or a DataFrame with the MAGE value for each segment (see the MAGE vignette for discussion of handling large gaps by splitting trace into multiple segments). |
direction |
Default: "avg". One of ("avg", "service", "max", "plus", or "minus"). Algorithm will calculate one of the following: MAGE+ (nadir to peak), MAGE- (peak to nadir), MAGEavg = avg(MAGE+, MAGE-), MAGEmax = max(MAGE+, MAGE-), or automatically choose MAGE+/MAGE- based on the first countable excursion (i.e., "service"). NOTE: the selection of peak-to-nadir or nadir-to-peak is chosen independently on each segment, thus MAGEservice may choose peak-to-nadir on one segment and nadir-to-peak on another, for example. |
tz |
A character string specifying the time zone to be used. System-specific (see |
inter_gap |
The maximum allowable gap (in minutes) for interpolation. The values will not be interpolated between the glucose measurements that are more than inter_gap minutes apart. The default value is 45 min. |
max_gap |
Default: 180. Integer for the maximum length of a gap in minutes before the trace is split into segments and MAGE is calculated on each segment independently. |
plot |
Default: FALSE. Boolean. If ‘TRUE', returns a plot that visualizes all identified peaks and nadirs, excursions, and missing gaps. An interactive GUI can be loaded with 'static_or_gui = ’plotly''. |
title |
Default: "Glucose Trace - Subject [ID]". Title for the ggplot. |
xlab |
Default: "Time". Label for x-axis of ggplot. |
ylab |
Default: "Glucose Level". Label for y-axis of ggplot. |
show_ma |
Default: FALSE. Boolean. If TRUE, plots the moving average lines on the plot. |
show_excursions |
Default: TRUE. Boolean. If TRUE, shows identified excursions as arrows from peak-to-nadir/nadir-to-peak on the plot. |
If version 'ma'
is selected, the function computationally emulates the manual method for calculating the mean amplitude of glycemic excursions (MAGE) first suggested in "Mean Amplitude of Glycemic Excursions, a Measure of Diabetic Instability", (Service, 1970). For this version, glucose values will be interpolated over a uniform time grid prior to calculation.
'ma'
is a more accurate algorithm that uses the crosses of a short and long moving average to identify intervals where a peak/nadir might exist. Then, the height from one peak/nadir to the next nadir/peak is calculated from the _original_ (not moving average) glucose values. (Note: this function internally uses CGMS2DayByDay with dt0 = 5. Thus, all CGM data is linearly interpolated to 5 minute intervals. See the MAGE vignette for more details.)
'naive'
algorithm calculates MAGE by taking the mean of absolute glucose differences (between each value and the mean) that are greater than the standard deviation. A multiplier can be added to the standard deviation using the sd_multiplier
argument.
A tibble object with two columns: the subject id and corresponding MAGE value. If a vector of glucose values is passed, then a tibble object with just the MAGE value is returned.
In version = "ma"
, if plot = TRUE
, a list of ggplots will be returned with one plot per subject.
To return an interactive plot, use iglu::mage_ma_single with static_or_gui='plotly'
on each subject individually.
Service et al. (1970) Mean amplitude of glycemic excursions, a measure of diabetic instability Diabetes 19 .644-655, doi:10.2337/diab.19.9.644.
Fernandes, Nathaniel J., et al. "Open-source algorithm to calculate mean amplitude of glycemic excursions using short and long moving averages." Journal of diabetes science and technology 16.2 (2022): 576-577. doi:10.1177/19322968211061165
data(example_data_5_subject) mage(example_data_5_subject, version = 'ma') mage(example_data_5_subject, return_type='df')
data(example_data_5_subject) mage(example_data_5_subject, version = 'ma') mage(example_data_5_subject, return_type='df')
This function is an internal function used 'mage'. The function will calculate the Mean Amplitude of Glycemic Excursions (MAGE) on all the values of the inputted data set regardless of subject. To calculate separate MAGE values for a group of subjects, use the 'mage' function.
mage_ma_single( data, short_ma = 5, long_ma = 32, return_type = c("num", "df"), direction = c("avg", "service", "max", "plus", "minus"), tz = "", inter_gap = 45, max_gap = 180, plot = FALSE, title = NA, xlab = NA, ylab = NA, show_ma = FALSE, show_excursions = TRUE, static_or_gui = c("plotly", "ggplot") )
mage_ma_single( data, short_ma = 5, long_ma = 32, return_type = c("num", "df"), direction = c("avg", "service", "max", "plus", "minus"), tz = "", inter_gap = 45, max_gap = 180, plot = FALSE, title = NA, xlab = NA, ylab = NA, show_ma = FALSE, show_excursions = TRUE, static_or_gui = c("plotly", "ggplot") )
data |
DataFrame object with column names "id", "time", and "gl". Should only be data for 1 subject. In case multiple subject ids are detected, a warning is produced and only 1st subject is used. |
short_ma |
Default: 5. Integer for period length of the short moving average. Must be positive and less than 'long_ma'. (Recommended <15) |
long_ma |
Default: 32. Integer for period length for the long moving average. Must be positive and greater than 'short_ma'. (Recommended >20) |
return_type |
Default: "num". One of ("num", "df"). Will return either a single number for the "MAGE over the entire trace" (weighted by segment length) or a DataFrame with the MAGE value for each segment (see the MAGE vignette for discussion of handling large gaps by splitting trace into multiple segments). |
direction |
Default: "avg". One of ("avg", "service", "max", "plus", or "minus"). Algorithm will calculate one of the following: MAGE+ (nadir to peak), MAGE- (peak to nadir), MAGEavg = avg(MAGE+, MAGE-), MAGEmax = max(MAGE+, MAGE-), or automatically choose MAGE+/MAGE- based on the first countable excursion (i.e., "service"). NOTE: the selection of peak-to-nadir or nadir-to-peak is chosen independently on each segment, thus MAGEservice may choose peak-to-nadir on one segment and nadir-to-peak on another, for example. |
tz |
A character string specifying the time zone to be used. System-specific (see |
inter_gap |
The maximum allowable gap (in minutes) for interpolation. The values will not be interpolated between the glucose measurements that are more than inter_gap minutes apart. The default value is 45 min. |
max_gap |
Default: 180. Integer for the maximum length of a gap in minutes before the trace is split into segments and MAGE is calculated on each segment independently. |
plot |
Default: FALSE. Boolean. If ‘TRUE', returns a plot that visualizes all identified peaks and nadirs, excursions, and missing gaps. An interactive GUI can be loaded with 'static_or_gui = ’plotly''. |
title |
Default: "Glucose Trace - Subject [ID]". Title for the ggplot. |
xlab |
Default: "Time". Label for x-axis of ggplot. |
ylab |
Default: "Glucose Level". Label for y-axis of ggplot. |
show_ma |
Default: FALSE. Boolean. If TRUE, plots the moving average lines on the plot. |
show_excursions |
Default: TRUE. Boolean. If TRUE, shows identified excursions as arrows from peak-to-nadir/nadir-to-peak on the plot. |
static_or_gui |
Default: "plotly". One of "ggplot" or "plotly". Returns either a ggplot (static image) or Plotly chart (interactive GUI). |
See 'mage'.
A ggplot or Plotly chart if plot = TRUE
, depending on static_or_gui
. Otherwise, a numeric MAGE value for the inputted glucose trace or a DataFrame with the MAGE values on each segment, depending on return_type
.
Nathaniel J. Fernandes
data(example_data_1_subject) mage_ma_single( example_data_1_subject, short_ma = 4, long_ma = 24, direction = 'plus') mage_ma_single( example_data_1_subject, inter_gap = 300) mage_ma_single( example_data_1_subject, plot=TRUE, static_or_gui='ggplot', title="Patient X", xlab="Time", ylab="Glucose Level (mg/dL)", show_ma=FALSE)
data(example_data_1_subject) mage_ma_single( example_data_1_subject, short_ma = 4, long_ma = 24, direction = 'plus') mage_ma_single( example_data_1_subject, inter_gap = 300) mage_ma_single( example_data_1_subject, plot=TRUE, static_or_gui='ggplot', title="Patient X", xlab="Time", ylab="Glucose Level (mg/dL)", show_ma=FALSE)
The function meal_metrics calculates three simple glucose meal metrics
meal_metrics(data, mealtimes, before_win = 1, after_win = 3, recovery_win = 1, interpolate = TRUE, adjust_mealtimes = TRUE, dt0 = NULL, inter_gap = 45, tz = "", glucose_times = FALSE)
meal_metrics(data, mealtimes, before_win = 1, after_win = 3, recovery_win = 1, interpolate = TRUE, adjust_mealtimes = TRUE, dt0 = NULL, inter_gap = 45, tz = "", glucose_times = FALSE)
data |
DataFrame object with column names "id", "time", and "gl". Should only be data for 1 subject. In case multiple subject ids are detected, a warning is produced and only 1st subject is used. |
mealtimes |
Either a vector of mealtimes, corresponding to data being from a single subject, OR a dataframe with at least 2 columns labeled id and mealtime. Optionally the mealtimes dataframe can include a column labeled meal, giving the meal type (helps to compensate for overlapping meals) |
before_win |
integer specifying number of hours to extend window before meal |
after_win |
integer specifying number of hours to extend window after meal |
recovery_win |
interger specifying number of hours for recovery beyond after window |
interpolate |
Boolean to indicate if CGM data should be interpolated or not. Default set to FALSE due to time intensive nature of interpolation. Parameters dt0, inter_gap, and tz will only be used if interpolate is set to TRUE. |
adjust_mealtimes |
Boolean to indicate if function should attempt to align mealtimes with CGM data times. This is important if mealtimes and CGM data times are not exactly aligned, because the function will return NA's for mealtimes that don't match with a corresponding CGM time stamp. |
dt0 |
The time frequency for interpolation in minutes, the default will match the CGM meter's frequency (e.g. 5 min for Dexcom). |
inter_gap |
The maximum allowable gap (in minutes) for interpolation. The values will not be interpolated between the glucose measurements that are more than inter_gap minutes apart. The default value is 45 min. |
tz |
A character string specifying the time zone to be used. System-specific (see |
glucose_times |
Boolean to indicate if underlying glucose and times should be returned
- e.g. baseline glucose value used to calculate |
A tibble object is returned with three metrics calculated for each mealtime.
The last three columns of the output correspond to the three metrics: deltag
refers to , deltat is
, and basereco is % Baseline recovery.
If no meal column is given in the original data, one will be automatically generated
with a unique number for each meal.
By default tibble object with 6 columns will be returned: id, time, meal, deltag, deltat, and basereco. If glucose_times = TRUE then 5 more columns are returned for baseline glucose (basegl), peak glucose (peakgl), recover glucose (recovergl), peak timestamp (peaktime), and recovery timestamp (recovertime)
Service, F. John. (2013) Glucose Variability, Diabetes 62(5): 1398-1404, doi:10.2337/db12-1396
plot_meals()
data(example_data_hall) data(example_meals_hall) meal_metrics(example_data_hall, example_meals_hall)
data(example_data_hall) data(example_meals_hall) meal_metrics(example_data_hall, example_meals_hall)
The function mean_glu is a wrapper for the base function mean(). Output is a tibble object with subject id and mean values.
mean_glu(data)
mean_glu(data)
data |
DataFrame object with column names "id", "time", and "gl", or numeric vector of glucose values. |
A tibble object with 1 row for each subject, a column for subject id and a column for the mean values is returned. NA glucose values are omitted from the calculation of the mean.
If a data.frame object is passed, then a tibble object with two columns: subject id and corresponding mean value is returned. If a vector of glucose values is passed, then a tibble object with just the mean value is returned. as.numeric() can be wrapped around the latter to output just a numeric value.
data(example_data_1_subject) mean_glu(example_data_1_subject) data(example_data_5_subject) mean_glu(example_data_5_subject)
data(example_data_1_subject) mean_glu(example_data_1_subject) data(example_data_5_subject) mean_glu(example_data_5_subject)
The function median_glu is a wrapper for the base function median(). Output is a tibble object with subject id and median values.
median_glu(data)
median_glu(data)
data |
DataFrame object with column names "id", "time", and "gl", or numeric vector of glucose values. |
A tibble object with 1 row for each subject, a column for subject id and a column for the median values is returned. NA glucose values are omitted from the calculation of the median.
If a data.frame object is passed, then a tibble object with two columns: subject id and corresponding median value is returned. If a vector of glucose values is passed, then a tibble object with just the median value is returned. as.numeric() can be wrapped around the latter to output just a numeric value.
data(example_data_1_subject) median_glu(example_data_1_subject) data(example_data_5_subject) median_glu(example_data_5_subject)
data(example_data_1_subject) median_glu(example_data_1_subject) data(example_data_5_subject) median_glu(example_data_5_subject)
Create a heatmap of metric values by subject based on hierarchical clustering order
metrics_heatmap( data = NULL, metrics = NULL, metric_cluster = 6, clustering_method = "complete", clustering_distance_metrics = "correlation", clustering_distance_subjects = "correlation", tz = "" )
metrics_heatmap( data = NULL, metrics = NULL, metric_cluster = 6, clustering_method = "complete", clustering_distance_metrics = "correlation", clustering_distance_subjects = "correlation", tz = "" )
data |
DataFrame object with column names "id", "time", and "gl". |
metrics |
precalculated metric values, with first column corresponding to subject id. If 'NULL', the metrics are calculated from supplied 'data' using |
metric_cluster |
number of visual metric clusters, default value is 6 |
clustering_method |
the agglomeration method for hierarchical clustering, accepts same values as |
clustering_distance_metrics |
the distance measure for metrics clustering, accepts same values as |
clustering_distance_subjects |
the distance measure for subjects clustering, accepts same values as |
tz |
Default: "". A character string specifying the time zone to be used. System-specific (see |
A heatmap of metrics by subjects generated via pheatmap
# Using pre-calculated sd metrics only rather than default (all metrics) mecs = sd_measures(example_data_5_subject) metrics_heatmap(metrics = mecs)
# Using pre-calculated sd metrics only rather than default (all metrics) mecs = sd_measures(example_data_5_subject) metrics_heatmap(metrics = mecs)
The function modd produces MODD values in a tibble object.
modd(data, lag = 1, tz = "")
modd(data, lag = 1, tz = "")
data |
DataFrame object with column names "id", "time", and "gl". |
lag |
Integer indicating which lag (# days) to use. Default is 1. |
tz |
A character string specifying the time zone to be used. System-specific (see |
A tibble object with 1 row for each subject, a column for subject id and a column for the MODD values is returned.
Missing values will be linearly interpolated when close enough to non-missing values.
MODD is calculated by taking the mean of absolute differences between measurements at the same time 1 day away, or more if lag parameter is set to an integer > 1.
A tibble object with two columns: subject id and corresponding MODD value.
Service, F. J. & Nelson, R. L. (1980) Characteristics of glycemic stability. Diabetes care 3 .58-62, doi:10.2337/diacare.3.1.58.
data(example_data_1_subject) modd(example_data_1_subject) modd(example_data_1_subject, lag = 2) data(example_data_5_subject) modd(example_data_5_subject, lag = 2)
data(example_data_1_subject) modd(example_data_1_subject) modd(example_data_1_subject, lag = 2) data(example_data_5_subject) modd(example_data_5_subject, lag = 2)
The function optimized_iglu_functions optimizes the calculation of all time dependent iglu metrics by extracting the CGMS2DayByDay calculation and passing the result into each function.
optimized_iglu_functions(data, dt0 = NULL, inter_gap = 45, tz = "", timelag = 15, lag = 1)
optimized_iglu_functions(data, dt0 = NULL, inter_gap = 45, tz = "", timelag = 15, lag = 1)
data |
DataFrame object with column names "id", "time", and "gl". |
dt0 |
The time frequency for interpolation in minutes, the default will match the CGM meter's frequency (e.g. 5 min for Dexcom). |
inter_gap |
The maximum allowable gap (in minutes) for interpolation. The values will not be interpolated between the glucose measurements that are more than inter_gap minutes apart. The default value is 45 min. |
tz |
A character string specifying the time zone to be used. System-specific (see |
timelag |
Integer indicating the time period (# minutes) over which rate of change is calculated. Default is 15, e.g. rate of change is the change in glucose over the past 15 minutes divided by 15. |
lag |
Integer indicating which lag (# days) to use. Default is 1. |
Returns a tibble object with 1 row for each subject and a column for each metric. This function includes time dependent iglu metrics only. For metric specific information, please see the corresponding function documentation.
If a data.frame object is passed, then a tibble object with 1 row for each subject and one column for each metric is returned.
data(example_data_1_subject) optimized_iglu_functions(example_data_1_subject) # Pass some arguments to possibly change the defaults optimized_iglu_functions(example_data_1_subject, dt0 = 5, inter_gap = 30) data(example_data_5_subject) optimized_iglu_functions(example_data_5_subject)
data(example_data_1_subject) optimized_iglu_functions(example_data_1_subject) # Pass some arguments to possibly change the defaults optimized_iglu_functions(example_data_1_subject, dt0 = 5, inter_gap = 30) data(example_data_5_subject) optimized_iglu_functions(example_data_5_subject)
The function mad produces PGS values in a tibble object.
pgs(data, dur_length = 20, end_length = 30)
pgs(data, dur_length = 20, end_length = 30)
data |
DataFrame object with column names "id", "time", and "gl". Should only be data for 1 subject. In case multiple subject ids are detected, a warning is produced and only 1st subject is used. |
dur_length |
Numeric value specifying the minimum duration in minutes to be considered an episode. Note dur_length should be a multiple of the data recording interval otherwise the function will round up to the nearest multiple. Default is 20 minutes to match the original PGS definition. |
end_length |
Numeric value specifying the minimum duration in minutes of improved glycemia for an episode to end. Default is 30 minutes to match original PGS definition. |
A tibble object with 1 row for each subject, a column for subject id and a column for PGS values is returned. NA glucose values are omitted from the calculation. The formula for PGS is as follows, where GVP = glucose variability percentage, MG = mean glucose, PTIR = percent time in range, and N54, N70 are the number of hypoglycemic episodes per week in the ranges <54 mg/dL and 54 to <70 mg/dL level respectively.
The component functions are listed below.
and b(N70) is defined such that b(N70) = if N70 <= 7.65, and b(N70) = 5 otherwise.
Note that the duration thresholds for episodes are NOT the same as the episode_calculation defaults. The defaults chosen for PGS are those that match the original PGS paper definition, while the episode_calculation defaults match the consensus.
A tibble object with two columns: subject id and corresponding PGS value.
Elizabeth Chun
Hirsch et al. (2017): A Simple Composite Metric for the Assessment of Glycemic Status from Continuous Glucose Monitoring Data: Implications for Clinical Practice and the Artificial Pancreas Diabetes Technol Ther 19(S3) .S38-S48, doi:10.1089/dia.2017.0080.
episode_calculation()
data(example_data_1_subject) pgs(example_data_1_subject)
data(example_data_1_subject) pgs(example_data_1_subject)
The function plot_agp produces an AGP plot that collapses all data into a single 24 hr "modal day".
plot_agp(data, LLTR = 70, ULTR = 180, smooth = TRUE, span = 0.3, dt0 = NULL, inter_gap = 45, tz = "", title = FALSE)
plot_agp(data, LLTR = 70, ULTR = 180, smooth = TRUE, span = 0.3, dt0 = NULL, inter_gap = 45, tz = "", title = FALSE)
data |
DataFrame object with column names "id", "time", and "gl". Should only be data for 1 subject. In case multiple subject ids are detected, a warning is produced and only 1st subject is used. |
LLTR |
Default: 70. Lower Limit of Target Range in mg/dL. |
ULTR |
Default: 180. Upper Limit of Target Range in mg/dL. |
smooth |
Boolean indicating whether quantiles should be smoothed before plotting, default is TRUE |
span |
Optional parameter indicating span for loess smoothing. Default is 0.3, larger values result in more smoothing, recommended to choose between 0.1 to 0.7. |
dt0 |
The time frequency for interpolation in minutes, the default will match the CGM meter's frequency (e.g. 5 min for Dexcom). |
inter_gap |
The maximum allowable gap (in minutes) for interpolation. The values will not be interpolated between the glucose measurements that are more than inter_gap minutes apart. The default value is 45 min. |
tz |
A character string specifying the time zone to be used. System-specific (see |
title |
Indicator whether the title of the plot should display the subject ID. The default is FALSE (no title). |
Only a single subject's data may be plotted. If smooth = TRUE, then the quantiles are loess smoothed with the specified span before plotting. The horizontal green lines represent the target range, default is 70-180 mg/dL. The black line is the median glucose value for each time of day. The dark blue shaded area represents 50% of glucose values - those between the 25th and 75 quantiles. The light blue shaded area shows 90% of the glucose values - those between the 5th and 95th quantiles. Additionally, the percents shown on the right hand side of the plot show which quantiles each line refers to - e.g. the line ending at 95% is the line corresponding to the 95th quantiles of glucose values.
Plot of a 24 hr modal day collapsing all data to a single day.
Elizabeth Chun
Johnson et al. (2019) Utilizing the Ambulatory Glucose Profile to Standardize and Implement Continuous Glucose Monitoring in Clinical Practice, Diabetes Technology and Therapeutics 21:S2 S2-17-S2-25, doi:10.1089/dia.2019.0034.
data(example_data_1_subject) plot_agp(example_data_1_subject)
data(example_data_1_subject) plot_agp(example_data_1_subject)
The function 'plot_daily' plots daily glucose time series profiles for a single subject.
plot_daily(data, maxd = 14, LLTR = 70, ULTR = 180, inter_gap = 45, tz = "")
plot_daily(data, maxd = 14, LLTR = 70, ULTR = 180, inter_gap = 45, tz = "")
data |
DataFrame with column names ("id", "time", and "gl"). |
maxd |
Default: 14. Number of days to plot. If less than 'maxd' days of data are available, all days are plotted. |
LLTR |
Default: 70. Lower Limit of Target Range in mg/dL. |
ULTR |
Default: 180. Upper Limit of Target Range in mg/dL. |
inter_gap |
Default: 45. The maximum allowable gap (in minutes). Gaps larger than this will not be connected in the time series plot. |
tz |
A character string specifying the time zone to be used. System-specific (see |
Only a single subject's data may be plotted. The black line shows the glucose values. The shaded gray area shows the target range, default 70-180 mg/dL. Areas of the curve above the ULTR are shaded yellow, while areas below the LLTR are shaded red.
Daily glucose time series plots for a single subject
Elizabeth Chun
Johnson et al. (2019) Utilizing the Ambulatory Glucose Profile to Standardize and Implement Continuous Glucose Monitoring in Clinical Practice, Diabetes Technology and Therapeutics 21:S2 S2-17-S2-25, doi:10.1089/dia.2019.0034.
data(example_data_1_subject) plot_daily(example_data_1_subject) plot_daily(example_data_1_subject, LLTR = 100, ULTR = 140)
data(example_data_1_subject) plot_daily(example_data_1_subject) plot_daily(example_data_1_subject, LLTR = 100, ULTR = 140)
The function 'plot_glu' supports several plotting methods for both single and multiple subject data.
plot_glu( data, plottype = c("tsplot", "lasagna"), datatype = c("all", "average", "single"), lasagnatype = c("unsorted", "timesorted"), LLTR = 70, ULTR = 180, subjects = NULL, inter_gap = 45, tz = "", color_scheme = c("blue-red", "red-orange"), log = F, static_or_gui = c("ggplot", "plotly") )
plot_glu( data, plottype = c("tsplot", "lasagna"), datatype = c("all", "average", "single"), lasagnatype = c("unsorted", "timesorted"), LLTR = 70, ULTR = 180, subjects = NULL, inter_gap = 45, tz = "", color_scheme = c("blue-red", "red-orange"), log = F, static_or_gui = c("ggplot", "plotly") )
data |
DataFrame with column names ("id", "time", and "gl"). |
plottype |
Default: "tsplot". One of ('tsplot', 'lasagna'). String corresponding to the desired plot type. Options are 'tsplot' for a time series plot and 'lasagna' for a lasagna plot. See the ‘lasagnatype' parameter for further options corresponding to the ’lasagna' 'plottype'. |
datatype |
String corresponding to data aggregation used for plotting, currently supported options are 'all' which plots all glucose measurements within the first |
lasagnatype |
String corresponding to plot type when using |
LLTR |
Default: 70. Lower Limit of Target Range in mg/dL. |
ULTR |
Default: 180. Upper Limit of Target Range in mg/dL. |
subjects |
String or list of strings corresponding to subject names in 'id' column of data. Default is all subjects. |
inter_gap |
Default: 45. The maximum allowable gap (in minutes). Gaps larger than this will not be connected in the time series plot. |
tz |
A character string specifying the time zone to be used. System-specific (see |
color_scheme |
Default: "blue-red". String corresponding to the chosen color scheme when the ‘plottype' is ’lasagna'. By default, 'blue-red' scheme is used, with the values below ‘LLTR' colored in shades of blue, and values above 'ULTR' colored in shades of red. The alternative ’red-orange' scheme mimics AGP output from |
log |
Default: FALSE. Boolean indicating whether 'log10' of glucose values should be taken. When 'log = TRUE', the glucose values, LLTR, and ULTR will all be log transformed, and time series plots will be on a semilogarithmic scale. |
static_or_gui |
Default: "ggplot". One of ("ggplot", "plotly"). Returns either a ggplot (static image) or Plotly chart (interactive GUI). |
For the default option 'plottype = tsplot', a time series graph for each subject is produced with hypo- and hyperglycemia cutoffs shown as horizontal red lines. The time series plots for all subjects chosen (all by default) are displayed on a grid.
The 'lasagna' plot type works best when the datatype argument is set to average.
Any output from the plot object
data(example_data_1_subject) plot_glu(example_data_1_subject) data(example_data_5_subject) plot_glu(example_data_5_subject, subjects = 'Subject 2') plot_glu(example_data_5_subject, plottype = 'tsplot', tz = 'EST', LLTR = 70, ULTR = 150) plot_glu(example_data_5_subject, plottype = 'lasagna', lasagnatype = 'timesorted')
data(example_data_1_subject) plot_glu(example_data_1_subject) data(example_data_5_subject) plot_glu(example_data_5_subject, subjects = 'Subject 2') plot_glu(example_data_5_subject, plottype = 'tsplot', tz = 'EST', LLTR = 70, ULTR = 150) plot_glu(example_data_5_subject, plottype = 'lasagna', lasagnatype = 'timesorted')
Lasagna plot of glucose values for multiple subjects
plot_lasagna( data, datatype = c("all", "average"), lasagnatype = c("unsorted", "timesorted", "subjectsorted"), maxd = 14, limits = c(50, 500), midpoint = 105, LLTR = 70, ULTR = 180, dt0 = NULL, inter_gap = 45, tz = "", color_scheme = c("blue-red", "red-orange"), log = F, static_or_gui = c("ggplot", "plotly") )
plot_lasagna( data, datatype = c("all", "average"), lasagnatype = c("unsorted", "timesorted", "subjectsorted"), maxd = 14, limits = c(50, 500), midpoint = 105, LLTR = 70, ULTR = 180, dt0 = NULL, inter_gap = 45, tz = "", color_scheme = c("blue-red", "red-orange"), log = F, static_or_gui = c("ggplot", "plotly") )
data |
DataFrame object with column names "id", "time", and "gl". |
datatype |
String corresponding to data aggregation used for plotting, currently supported options are 'all' which plots all glucose measurements within the first |
lasagnatype |
String corresponding to plot type when using |
maxd |
For datatype "all", maximal number of days to be plotted from the study. The default value is 14 days (2 weeks). |
limits |
The minimal and maximal glucose values for coloring grid which is gradient from blue (minimal) to red (maximal), see |
midpoint |
The glucose value serving as midpoint of the diverging gradient scale (see |
LLTR |
Lower Limit of Target Range, default value is 70 mg/dL. |
ULTR |
Upper Limit of Target Range, default value is 180 mg/dL. |
dt0 |
The time frequency for interpolated aligned grid in minutes, the default will match the CGM meter's frequency (e.g. 5 min for Dexcom). |
inter_gap |
The maximum allowable gap (in minutes) for interpolation of NA glucose values. The values will not be interpolated between the glucose measurements that are more than inter_gap minutes apart. The default value is 45 min. |
tz |
A character string specifying the time zone to be used. System-specific (see |
color_scheme |
String corresponding to the chosen color scheme. By default, 'blue-red' scheme is used, with the values below ‘LLTR' colored in shades of blue, and values above 'ULTR' colored in shades of red. The alternative ’red-orange' scheme mimics AGP output from |
log |
Logical value indicating whether log10 of glucose values should be taken, default value is FALSE. When log = TRUE the glucose values, limits, midpoint, LLTR, and ULTR will all be log transformed. |
static_or_gui |
One of "ggplot" or "plotly". Default: "plotly". Returns either a ggplot (static image) or Plotly chart (interactive GUI). |
A ggplot object corresponding to lasagna plot
Swihart et al. (2010) Lasagna Plots: A Saucy Alternative to Spaghetti Plots, Epidemiology 21(5), 621-625, doi:10.1097/EDE.0b013e3181e5b06a
plot_lasagna(example_data_5_subject, datatype = "average", lasagnatype = 'timesorted', tz = "EST") plot_lasagna(example_data_5_subject, lasagnatype = "subjectsorted", LLTR = 100, tz = "EST")
plot_lasagna(example_data_5_subject, datatype = "average", lasagnatype = 'timesorted', tz = "EST") plot_lasagna(example_data_5_subject, lasagnatype = "subjectsorted", LLTR = 100, tz = "EST")
Lasagna plot of glucose values for 1 subject aligned across times of day
plot_lasagna_1subject( data, lasagnatype = c("unsorted", "timesorted", "daysorted"), limits = c(50, 500), midpoint = 105, LLTR = 70, ULTR = 180, dt0 = NULL, inter_gap = 45, tz = "", color_scheme = c("blue-red", "red-orange"), log = F, static_or_gui = c("ggplot", "plotly") )
plot_lasagna_1subject( data, lasagnatype = c("unsorted", "timesorted", "daysorted"), limits = c(50, 500), midpoint = 105, LLTR = 70, ULTR = 180, dt0 = NULL, inter_gap = 45, tz = "", color_scheme = c("blue-red", "red-orange"), log = F, static_or_gui = c("ggplot", "plotly") )
data |
DataFrame object with column names "id", "time", and "gl". |
lasagnatype |
Default: "unsorted". String corresponding to plot type, currently supported options are 'unsorted' for an unsorted single-subject lasagna plot, 'timesorted' for a lasagna plot with glucose values sorted within each time point across days, and 'daysorted' for a lasagna plot with glucose values sorted within each day across time points. |
limits |
The minimal and maximal glucose values for coloring grid which is gradient from blue (minimal) to red (maximal), see |
midpoint |
The glucose value serving as midpoint of the diverging gradient scale (see |
LLTR |
Lower Limit of Target Range, default value is 70 mg/dL. |
ULTR |
Upper Limit of Target Range, default value is 180 mg/dL. |
dt0 |
The time frequency for interpolated aligned grid in minutes, the default will match the CGM meter's frequency (e.g. 5 min for Dexcom). |
inter_gap |
The maximum allowable gap (in minutes) for interpolation of NA glucose values. The values will not be interpolated between the glucose measurements that are more than inter_gap minutes apart. The default value is 45 min. |
tz |
A character string specifying the time zone to be used. System-specific (see |
color_scheme |
String corresponding to the chosen color scheme. By default, 'blue-red' scheme is used, with the values below ‘LLTR' colored in shades of blue, and values above 'ULTR' colored in shades of red. The alternative ’red-orange' scheme mimics AGP output from |
log |
Logical value indicating whether log of glucose values should be taken, default values is FALSE. When log = TRUE the glucose values, limits, midpoint, LLTR, and ULTR will all be log transformed. |
static_or_gui |
One of "ggplot" or "plotly". Default: "plotly". Returns either a ggplot (static image) or Plotly chart (interactive GUI). |
A ggplot object corresponding to lasagna plot
Swihart et al. (2010) Lasagna Plots: A Saucy Alternative to Spaghetti Plots, Epidemiology 21(5), 621-625, doi:10.1097/EDE.0b013e3181e5b06a
plot_lasagna_1subject(example_data_1_subject) plot_lasagna_1subject(example_data_1_subject, color_scheme = 'red-orange') plot_lasagna_1subject(example_data_1_subject, lasagnatype = 'timesorted') plot_lasagna_1subject(example_data_1_subject, lasagnatype = 'daysorted') plot_lasagna_1subject(example_data_1_subject, log = TRUE)
plot_lasagna_1subject(example_data_1_subject) plot_lasagna_1subject(example_data_1_subject, color_scheme = 'red-orange') plot_lasagna_1subject(example_data_1_subject, lasagnatype = 'timesorted') plot_lasagna_1subject(example_data_1_subject, lasagnatype = 'daysorted') plot_lasagna_1subject(example_data_1_subject, log = TRUE)
The function plot_meals produces a visual for meals data
plot_meals(data, mealtimes, plot_type=c('ggplot','plotly'), tz = "")
plot_meals(data, mealtimes, plot_type=c('ggplot','plotly'), tz = "")
data |
DataFrame object with column names "id", "time", and "gl". Should only be data for 1 subject. In case multiple subject ids are detected, a warning is produced and only 1st subject is used. |
mealtimes |
Either a vector of mealtimes, corresponding to data being from a single subject, OR a dataframe with at least 2 columns labeled id and mealtime. Optionally the mealtimes dataframe can include a column labeled meal, giving the meal type (helps to compensate for overlapping meals) |
plot_type |
Default: "ggplot". One of 'ggplot', 'plotly'. Determines whether the function returns a static publication-ready image or an interactive GUI. |
tz |
Default: "". A character string specifying the time zone to be used. System-specific (see |
Only a single subject's data may be plotted. The solid black line is the glucose trace. Vertical dashed red lines show the mealtimes, and the horizontal blue lines show the baseline for each meal. Purple triangles are plotted to illustrate the 3 meal_metrics Namely the three vertices show the baseline, peak, and 1hr post-peak recovery. If plot_type = 'plotly', plotly is used to display an interactive visual that allows one to zoom into specific areas of the plot.
Plot to visualize meals data.
Elizabeth Chun
Service, F. John. (2013) Glucose Variability, Diabetes 62(5): 1398-1404, doi:10.2337/db12-1396
meal_metrics()
select_subject = example_data_hall[example_data_hall$id == "2133-018", ] select_meals = example_meals_hall[example_meals_hall$id == "2133-018", ] plot_meals(select_subject, select_meals, tz = 'GMT')
select_subject = example_data_hall[example_data_hall$id == "2133-018", ] select_meals = example_meals_hall[example_meals_hall$id == "2133-018", ] plot_meals(select_subject, select_meals, tz = 'GMT')
The function plot_ranges produces a barplot showing the percent of time in glucose ranges.
plot_ranges(data)
plot_ranges(data)
data |
DataFrame object with column names "id", "time", and "gl". Should only be data for 1 subject. In case multiple subject ids are detected, a warning is produced and only 1st subject is used. |
Only a single subject's data may be used. There are four ranges: very low (below 54 mg/dL), low (54-69 mg/dL), target range (70-180 mg/dL), high (181-250 mg/dL), and very high (above 250 mg/dL). This plot is meant to be used as part of the Ambulatory Glucose Profile (AGP)
Single subject bar chart showing percent in different glucose ranges.
Elizabeth Chun
Johnson et al. (2019) Utilizing the Ambulatory Glucose Profile to Standardize and Implement Continuous Glucose Monitoring in Clinical Practice, Diabetes Technology and Therapeutics 21:S2 S2-17-S2-25, doi:10.1089/dia.2019.0034.
data(example_data_1_subject) plot_ranges(example_data_1_subject)
data(example_data_1_subject) plot_ranges(example_data_1_subject)
The function plot_roc produces a time series plot of glucose values colored by categorized rate of change values
plot_roc(data, subjects = NULL, timelag = 15, dt0 = NULL, inter_gap = 45, tz = "")
plot_roc(data, subjects = NULL, timelag = 15, dt0 = NULL, inter_gap = 45, tz = "")
data |
DataFrame object with column names "id", "time", and "gl". |
subjects |
String or list of strings corresponding to subject names in 'id' column of data. Default is all subjects. |
timelag |
Integer indicating the time period (# minutes) over which rate of change is calculated. Default is 15, e.g. rate of change is the change in glucose over the past 15 minutes divided by 15. |
dt0 |
The time frequency for interpolation in minutes, the default will match the CGM meter's frequency (e.g. 5 min for Dexcom). |
inter_gap |
The maximum allowable gap (in minutes) for interpolation. The values will not be interpolated between the glucose measurements that are more than inter_gap minutes apart. The default value is 45 min. |
tz |
A character string specifying the time zone to be used. System-specific (see |
For the default, a time series is produced for each subject in which the glucose values are plotted and colored by ROC categories defined as follows. The breaks for the categories are: c(-Inf, -3, -2, -1, 1, 2, 3, Inf) where the glucose is in mg/dl and the ROC values are in mg/dl/min. A ROC of -5 mg/dl/min will thus be placed in the first category and colored accordingly. The breaks for the categories come from the reference paper below.
A time series of glucose values colored by ROC categories per subject
Elizabeth Chun, David Buchanan
Klonoff, D. C., & Kerr, D. (2017) A Simplified Approach Using Rate of Change Arrows to Adjust Insulin With Real-Time Continuous Glucose Monitoring. Journal of Diabetes Science and Technology 11(6) 1063-1069, doi:10.1177/1932296817723260.
data(example_data_1_subject) plot_roc(example_data_1_subject) data(example_data_5_subject) plot_roc(example_data_5_subject, subjects = 'Subject 5')
data(example_data_1_subject) plot_roc(example_data_1_subject) data(example_data_5_subject) plot_roc(example_data_5_subject, subjects = 'Subject 5')
A helper function to assist in pre-processing the user-supplied
input data for use with other functions.
Typically, this function will process the data and return another DataFrame.
This function ensures that the returned data will be compatible with every
function within the iglu
package. All NA
s will be removed. See Vignette for further details.
process_data(data, id, timestamp, glu, time_parser = as.POSIXct)
process_data(data, id, timestamp, glu, time_parser = as.POSIXct)
data |
User-supplied dataset containing continuous glucose monitor data. Must contain data for time and glucose readings at a minimum. Accepted formats are dataframe and tibble. |
id |
Optional column name (character string) corresponding to subject id column. If no value is passed, an id of 1 will be assigned to the data. |
timestamp |
Required column name (character string) corresponding to time values in data. The dates can be in any format parsable by as.POSIXct, or any format accepted by the parser passed to time_parser. See time_parser param for an explanation on how to handle arbitrary formats. |
glu |
Required column name (character string) corresponding to glucose values, mg/dL |
time_parser |
Optional function used to convert datetime strings to time objects. Defaults to as.POSIXct. If your times are in a format not parsable by as.POSIXct, you can parse a custom format by passing function(time_string) {strptime(time_string, format = <format string>)} as the time_parser parameter. |
A dataframe with the columns "id", "time", and "gl" will be returned. All NA
s will be removed.
If "mmol/l" in the glucose column name, the glucose values will be multipled by 18 to convert to mg/dL.
Based on John Schwenck's data_process
for his bp package "https://github.com/johnschwenck/bp".
A processed DataFrame object that cooperates with every other
function within the iglu
package - all column names and formats comply.
David Buchanan, John Schwenck
data("example_data_1_subject") # Process example data processed <- process_data(example_data_1_subject, id = "id", timestamp = "time", glu = "gl") processed data("example_data_5_subject") # Process example data processed_5subj <- process_data(example_data_5_subject, id = "id", timestamp = "time", glu = "gl") processed_5subj
data("example_data_1_subject") # Process example data processed <- process_data(example_data_1_subject, id = "id", timestamp = "time", glu = "gl") processed data("example_data_5_subject") # Process example data processed_5subj <- process_data(example_data_5_subject, id = "id", timestamp = "time", glu = "gl") processed_5subj
The function quantile_glu
is a wrapper for the base function quantile()
. Output
is a tibble object with columns for subject id and each of the quantiles.
quantile_glu(data, quantiles = c(0, 25, 50, 75, 100))
quantile_glu(data, quantiles = c(0, 25, 50, 75, 100))
data |
DataFrame object with column names "id", "time", and "gl", or numeric vector of glucose values. |
quantiles |
List of quantile values between 0 and 100. |
A tibble object with 1 row for each subject, a column for subject id and
a column for each quantile is returned. NA
glucose values are
omitted from the calculation of the quantiles.
The values are scaled from 0-1 to 0-100 to be consistent in output with above_percent, below_percent, and in_range_percent.
The command quantile_glu(...) / 100
will scale each element down from 0-100
to 0-1.
If a DataFrame object is passed, then a tibble object with
a column for subject id and then a column for each quantile value is returned. If a vector of glucose
values is passed, then a tibble object without the subject id is returned.
as.numeric()
can be wrapped around the latter to output a numeric vector.
data(example_data_1_subject) quantile_glu(example_data_1_subject) quantile_glu(example_data_1_subject, quantiles = c(0, 33, 66, 100)) data(example_data_5_subject) quantile_glu(example_data_5_subject) quantile_glu(example_data_5_subject, quantiles = c(0, 10, 90, 100))
data(example_data_1_subject) quantile_glu(example_data_1_subject) quantile_glu(example_data_1_subject, quantiles = c(0, 33, 66, 100)) data(example_data_5_subject) quantile_glu(example_data_5_subject) quantile_glu(example_data_5_subject, quantiles = c(0, 10, 90, 100))
The function range_glu
outputs the distance between minimum
and maximum glucose values per subject in a tibble object.
range_glu(data)
range_glu(data)
data |
DataFrame object with column names "id", "time", and "gl", or numeric vector of glucose values. |
A tibble object with 1 row for each subject, a column for subject id and
a column for the range values is returned. NA
glucose values are
omitted from the calculation of the range.
If a DataFrame object is passed, then a tibble object with
two columns: subject id and corresponding range value is returned. If a vector of glucose
values is passed, then a tibble object with just the range value is returned.
as.numeric()
can be wrapped around the latter to output just a numeric value.
data(example_data_1_subject) range_glu(example_data_1_subject) data(example_data_5_subject) range_glu(example_data_5_subject)
data(example_data_1_subject) range_glu(example_data_1_subject) data(example_data_5_subject) range_glu(example_data_5_subject)
Helper function to assist in reading data directly from sensor outputs. Should return a dataframe in correct format
for use with the rest of the iglu
package. Assumes all data will be readable with base R read.csv()
function.
read_raw_data( filename, sensor = c("dexcom", "libre", "librepro", "asc", "ipro"), id = "filename", tz = "" )
read_raw_data( filename, sensor = c("dexcom", "libre", "librepro", "asc", "ipro"), id = "filename", tz = "" )
filename |
String matching the name of the data to be read. Assumed to be .csv |
sensor |
Default: "dexcom". String naming the type of sensor the data was exported from. Must be one of "dexcom", "libre", "librepro", "asc", or "ipro". |
id |
Default: "filename". String indicating subject id. A value of "read" will cause the program to attempt to read the subject id from the file. A value of "filename" will cause the program to use the basename of the filename (i.e. filename without any directory information) with .csv removed, as subject id. A value of "default" will cause the program to use whichever of "read" or "filename" that is default for that specific sensor. Any other string will be treated as the unique id for the entire file. Note the asc reader currently does not support id="read" |
tz |
A character string specifying the time zone to be used. System-specific (see |
A DataFrame object with the columns "id", "time" and "gl" and one row per reading will be returned. For the libre reader, if the phrase "mmol/l" is found in the column names, the glucose values will be multiplied by 18.
Assumes .csv format for all data.
Sensor formats change with ongoing development, so these functions may become deprecated. If any issues are encountered, contact the package maintainer: this is currently Irina Gaynanova, who can be reached at [email protected].
Note: this function is heavily derived from the readers avaiable in the cgmanalysis package's cleandata
function.
A dataframe containing the data read from the named file.
David Buchanan
Vigers et al. (2019) cgmanalysis: An R package for descriptive analysis of continuous glucose monitor data PLoS ONE 14(10): e0216851, doi:10.1371/journal.pone.0216851
The function roc
produces rate of change values in a tibble object.
roc(data, timelag = 15, dt0 = NULL, inter_gap = 45, tz = "")
roc(data, timelag = 15, dt0 = NULL, inter_gap = 45, tz = "")
data |
DataFrame object with column names "id", "time", and "gl". |
timelag |
Integer indicating the time period (# minutes) over which rate of change is calculated. Default is 15, e.g. rate of change is the change in glucose over the past 15 minutes divided by 15. |
dt0 |
The time frequency for interpolation in minutes, the default will match the CGM meter's frequency (e.g. 5 min for Dexcom). |
inter_gap |
The maximum allowable gap (in minutes) for interpolation. The values will not be interpolated between the glucose measurements that are more than inter_gap minutes apart. The default value is 45 min. |
tz |
A character string specifying the time zone to be used. System-specific (see |
A tibble object with a column for subject id and a column for ROC values is
returned. A ROC value is returned for each time point for all the subjects. Thus
multiple rows are returned for each subject. If the rate of change cannot be
calculated, the function will return NA
for that point.
The glucose values are linearly interpolated over a time grid starting at the
beginning of the first day of data and ending on the last day of data. Because
of this, there may be many NA
s at the beginning and the end of the roc values
for each subject. These NA
s are a result of interpolated time points that do
not have recorded glucose values near them because recording had either not
yet begun for the day or had already ended.
The ROC is calculated as
where
is the Glucose measurement at time
and
is the
Glucose measurement at time
. The time difference between the points,
, is selectable and set at a default of 15 minutes.
A tibble object with two columns: subject id and rate of change values
Elizabeth Chun, David Buchanan
Clarke et al. (2009) Statistical Tools to Analyze Continuous Glucose Monitor Data, Diabetes Diabetes Technology and Therapeutics 11 S45-S54, doi:10.1089/dia.2008.0138.
data(example_data_1_subject) roc(example_data_1_subject) roc(example_data_1_subject, timelag = 10) data(example_data_5_subject) roc(example_data_5_subject)
data(example_data_1_subject) roc(example_data_1_subject) roc(example_data_1_subject, timelag = 10) data(example_data_5_subject) roc(example_data_5_subject)
The function sd_glu
is a wrapper for the base function
sd()
. Output is a tibble object with subject id and sd values.
sd_glu(data)
sd_glu(data)
data |
DataFrame object with column names "id", "time", and "gl", or numeric vector of glucose values. |
A tibble object with 1 row for each subject, a column for subject id and
a column for the sd values is returned. NA
glucose values are
omitted from the calculation of the sd.
If a data.frame object is passed, then a tibble object with
two columns: subject id and corresponding sd value is returned. If a vector of glucose
values is passed, then a tibble object with just the sd value is returned.
as.numeric()
can be wrapped around the latter to output just a numeric value.
data(example_data_1_subject) sd_glu(example_data_1_subject) data(example_data_5_subject) sd_glu(example_data_5_subject)
data(example_data_1_subject) sd_glu(example_data_1_subject) data(example_data_5_subject) sd_glu(example_data_5_subject)
The function sd_measures
produces SD subtype values in a tibble object
with a row for each subject and columns corresponding to id followed by
each SD subtype.
sd_measures(data,dt0 = NULL, inter_gap = 45, tz = "")
sd_measures(data,dt0 = NULL, inter_gap = 45, tz = "")
data |
DataFrame object with column names "id", "time", and "gl". |
dt0 |
The time frequency for interpolation in minutes, the default will match the CGM meter's frequency (e.g. 5 min for Dexcom). |
inter_gap |
The maximum allowable gap (in minutes) for interpolation. The values will not be interpolated between the glucose measurements that are more than inter_gap minutes apart. The default value is 45 min. |
tz |
A character string specifying the time zone to be used. System-specific (see |
A tibble object with 1 row for each subject, a column for subject id and a column for each SD subtype values is returned.
Missing values will be linearly interpolated when close enough to non-missing values.
SDw - vertical within days:
Calculated by first taking the standard deviation of each day's glucose measurements,
then taking the mean of all the standard deviations. That is, for d
days we compute daily standard deviations and calculate
SDhhmm - between time points:
Also known as SDhh:mm. Calculated by taking the mean glucose values at each time point in the grid across days,
and taking the standard deviation of those mans. That is, for t time points
we compute means for each time point and then compute
.
SDwsh - within series:
Also known as SDws h. Calculated by taking the hour-long intervals starting at every point in the interpolated
grid, computing the standard deviation of the points in each hour-long interval, and then
finding the mean of those standard deviations. That is, for n time points compute
, where
is the standard deviation of the glucose values
corresponding to hour-long window starting at observation
, the number of observations in the window k depends on CGM meter frequency. Then, take
.
SDdm - horizontal sd:
Calculated by taking the daily mean glucose values, and then taking the standard deviation
of those daily means. That is, for d days we take daily means, and then compute
.
SDb - between days, within timepoints:
Calculated by taking the standard deviation of the glucose values across days for each time point,
and then taking the mean of those standard deviations.
That is, for t time points take standard deviations, and then compute
SDbdm - between days, within timepoints, corrected for changes in daily means:
Also known as SDb // dm. Calculated by subtracting the daily mean from each glucose value, then taking the standard deviation
of the corrected glucose values across days for each time point, and then taking the mean of those
standard deviations.
That is, for t time points take standard deviations, and then compute
. where
is the standard deviation of d daily values at the
1st time point, where each value is the dth measurement for the ith time point subtracted by
the mean of all glucose values for day d.
A tibble object with a column for id and a column for each of the six SD subtypes.
Rodbard (2009) New and Improved Methods to Characterize Glycemic Variability Using Continuous Glucose Monitoring Diabetes Technology and Therapeutics 11 .551-565, doi:10.1089/dia.2009.0015.
data(example_data_1_subject) sd_measures(example_data_1_subject)
data(example_data_1_subject) sd_measures(example_data_1_subject)
The function sd_roc
produces the standard deviation of the rate of change
values in a tibble object.
sd_roc(data, timelag = 15, dt0 = NULL, inter_gap = 45, tz = "")
sd_roc(data, timelag = 15, dt0 = NULL, inter_gap = 45, tz = "")
data |
DataFrame object with column names "id", "time", and "gl". |
timelag |
Integer indicating the time period (# minutes) over which rate of change is calculated. Default is 15, e.g. rate of change is the change in glucose over the past 15 minutes divided by 15. |
dt0 |
The time frequency for interpolation in minutes, the default will match the CGM meter's frequency (e.g. 5 min for Dexcom). |
inter_gap |
The maximum allowable gap (in minutes) for interpolation. The values will not be interpolated between the glucose measurements that are more than inter_gap minutes apart. The default value is 45 min. |
tz |
A character string specifying the time zone to be used. System-specific (see |
A tibble object with one row for each subject, a column for subject id and a column for the standard deviation of the rate of change.
When calculating rate of change, missing values will be linearly interpolated when close enough to non-missing values.
Calculated by taking the standard deviation of all the ROC values for each individual subject. NA rate of change values are omitted from the standard deviation calculation.
A tibble object with two columns: subject id and standard deviation of the rate of change values for each subject.
Elizabeth Chun, David Buchanan
Clarke et al. (2009) Statistical Tools to Analyze Continuous Glucose Monitor Data, Diabetes Diabetes Technology and Therapeutics 11 S45-S54, doi:10.1089/dia.2008.0138.
data(example_data_1_subject) sd_roc(example_data_1_subject) sd_roc(example_data_1_subject, timelag = 10) data(example_data_5_subject) sd_roc(example_data_5_subject) sd_roc(example_data_5_subject, timelag = 10)
data(example_data_1_subject) sd_roc(example_data_1_subject) sd_roc(example_data_1_subject, timelag = 10) data(example_data_5_subject) sd_roc(example_data_5_subject) sd_roc(example_data_5_subject, timelag = 10)
The function 'summary_glu' is a wrapper for the base function 'summary()'. Output is a tibble object with subject id and the summary value: Minimum, 1st Quantile, Median, Mean, 3rd Quantile and Max.
summary_glu(data)
summary_glu(data)
data |
DataFrame object with column names "id", "time", and "gl", or numeric vector of glucose values. |
A tibble object with 1 row for each subject, a column for subject id and a column for each of summary values is returned. 'NA' glucose values are omitted from the calculation of the summary values.
If a DataFrame object is passed, then a tibble object with a column for subject id and then a column for each summary value is returned. If a vector of glucose values is passed, then a tibble object without the subject id is returned. 'as.numeric()' can be wrapped around the latter to output a numeric vector with values in order of Min, 1st Quantile, Median, Mean, 3rd Quantile and Max.
data(example_data_1_subject) summary_glu(example_data_1_subject) data(example_data_5_subject) summary_glu(example_data_5_subject)
data(example_data_1_subject) summary_glu(example_data_1_subject) data(example_data_5_subject) summary_glu(example_data_5_subject)