#' Calculate Entropy of a cgms.df object for each selected group
#' to the mean glucose value of a cgms.df dataframe
#' @author Samuel Hamilton
#' @param df input cgms.df dataframe. Object
#' @param outputdir folder to save in. String
#' @param entmeasure which entropy measure to use/Either "FastSampEn" "FastApEn". String
#' @param varlist which groups to calculate entropy. Takes a list of strings
#' @param r_thrsh what do you set the tolerance parameter r too. This input number multiplies by the sd of all glucose values.
#' @param ofint What variable is of interest. String
#' @import TSEntropies dplyr
#' @keywords null distributions
#' @return dataframe with the entropy value for each group in varslist
#' @export
#' @examples CalcEn(df = cgms.df, varlist = c("Group"))
#Plot time course data for each subject, save to figures folder as df.plotruns
CalcEn <- function(entmeasure = "FastSampEn",ofint = "historic_glucose",df,varlist,r_thrsh = .2) {
#calculate standard deviation of the time series
allsd <- sd(dplyr::pull(df,
ofint),
na.rm = T)
print(allsd)
k <- plyr::ddply(df,
varlist,
plyr::here(summarise),
entropy = do.call(entmeasure,list(get(ofint),
r = r_thrsh*allsd)
)
)
return(k)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.