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,
return_data = FALSE,
dt0 = NULL,
inter_gap = 45,
tz = ""
)
If return_data is FALSE, a single dataframe with columns:
Subject id
Type of episode - either hypoglycemia or hyperglycemia
Level of episode - one of lv1, lv2, or extended
Average number of episodes per day calculated as (total # episodes)/(recording time in days (24hrs))
Average duration of episodes in minutes
Average glucose in the episode in mg/dL
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. Mostly for use with epicalc_profile function. Format of the second list entry is:
Subject id
Interpolated timestamps
glucose in mg/dL
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
DataFrame object with column names "id", "time", and "gl". Should only be data for 1 subject. In case multiple subject ids are detected, the warning is produced and only 1st subject is used.
Numeric value specifying a hypoglycemia threshold for level 1
Numeric value specifying a hypoglycemia threshold for level 2
Numeric value specifying a hyperglycemia threshold for level 1
Numeric value specifying a hyperglycemia threshold for level 2
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.
Boolean indicating whether to also return data with episode labels. Defaults to FALSE which means only episode summary statistics will be returned
The time frequency for interpolation in minutes, the default will match the CGM meter's frequency (e.g. 5 min for Dexcom).
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.
A character string specifying the time zone to be used. System-specific (see as.POSIXct
), but " " is the current time zone, and "GMT" is UTC (Universal Time, Coordinated). Invalid values are most commonly treated as UTC, on some platforms with a warning.
Johnathan Shih, Jung Hoon Seo, Elizabeth Chun
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.
Battelino et al. (2023): Continuous glucose monitoring and metrics for clinical trials: an international consensus statement Lancet Diabetes & Endocrinology 11(1) .42-57, tools:::Rd_expr_doi("10.1016/s2213-8587(22)00319-9").
episode_calculation(example_data_5_subject, lv1_hypo=100, lv1_hyper= 120)
Run the code above in your browser using DataLab