diff --git a/DESCRIPTION b/DESCRIPTION index 9761b09d..486bb88c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: iglu Type: Package Title: Interpreting Glucose Data from Continuous Glucose Monitors -Version: 4.2.3 +Version: 4.3.0 Authors@R: c(person("Elizabeth", "Chun", role = c("aut")), person("Steve", "Broll", diff --git a/NEWS.md b/NEWS.md index bfdf0c8f..84b1a2d2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,6 @@ +# iglu 4.3.0 +* Updated MAG computation in the presence of large missing data + # iglu 4.2.3 * Fixed GVP output for iglu::all_metrics diff --git a/R/mag.R b/R/mag.R index 2bbe8548..7882b312 100644 --- a/R/mag.R +++ b/R/mag.R @@ -22,9 +22,8 @@ #' 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 \eqn{\frac{|\Delta G|}{\Delta t}} where \eqn{|\Delta G|} 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 -#' \eqn{\Delta t} which is the total time in hours. +#' the sum of the absolute change in glucose. The sum is then divided by \eqn{\Delta t}, +#' the total number of n-minute intervals (default n = 60 for hourly change). #' #' @author Elizabeth Chun #' @@ -54,10 +53,10 @@ mag <- function (data, n = 60L, dt0 = NULL, inter_gap = 45, tz = "") { n <- dt0 } - idx = seq(1, ncol(data_ip[[1]]), by = round(n/data_ip[[3]])) - idx_gl = as.vector(t(data_ip[[1]][, idx])) - mag = sum(abs(diff(idx_gl)), na.rm = TRUE)/ - (length(na.omit(idx_gl))*n/60) + diffs = diff(as.vector(t(data_ip[[1]]))) + total_time = (length(na.omit(diffs))*dt0)/n + mag = sum(abs(diffs), na.rm = TRUE)/total_time + return(mag) } diff --git a/man/mag.Rd b/man/mag.Rd index 45df5bec..41299493 100644 --- a/man/mag.Rd +++ b/man/mag.Rd @@ -31,9 +31,8 @@ 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 \eqn{\frac{|\Delta G|}{\Delta t}} where \eqn{|\Delta G|} 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 -\eqn{\Delta t} which is the total time in hours. +the sum of the absolute change in glucose. The sum is then divided by \eqn{\Delta t}, +the total number of n-minute intervals (default n = 60 for hourly change). } \examples{