#' Calculates entropy using a sliding window approach. Takes the entropy of a smaller
#' time windows then averages them. This is to eliminate any bias that may result from time-series length.
#' @author Samuel Hamilton
#' @param entmeasure chosen entropy measure. Either FastSampEn or FastApEn
#' @param ofint A numeric vector representing the value of interest
#' @param size size of the sliding window. Numeric
#' @param step step size for the window, how "Fast" it slides. Numeric
#' @param r_thresh what is the tolerance r to be used. Numeric
#' @import TSEntropies
#' @keywords null distributions
#' @return dataframe with the entropy value for each group in varslist
#' @export
#' @examples plotruns(cgms.df)
calc_En_slidingwindow <- function(entmeasure = "FastSampEn",ofint,size,step,r_thresh) {
slidingentlist <- c() #init list
if(length(ofint) <= size) stop("Window size is larger than your time series!")
for(i in seq(from = 1, to = (length(ofint) - size), by = step)){
window <- ofint[i:(i+size)] #Make window
EN <- do.call(entmeasure,list(window, r = r_thresh)) # Calculate Entropy for that window
slidingentlist <- append(slidingentlist,EN)
}
return(slidingentlist)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.