R/featurewise_volatility.R

Defines functions get_fw_volatility get_fw_diff

Documented in get_fw_diff get_fw_volatility

#' Make a table of pairwise feature differences based on group membership.
#' @description Given the relevant pairwise distances, compute change in every feature in a table.  .
#' @param x A pairwise distance table, for instance generated by `get_pairwise_distance`.
#' @param y A table containing the features (as columns) that should be contrasted over time.
#' @return a `data.frame` with pairwise differences
#'
get_fw_diff <- function(x, y){
  do.call(rbind, unname(c(y[,x[,"to"]] - y[,x[,"from"]])))
}


#' Make a table of pairwise feature differences based on group membership.
#' @description Given the relevant pairwise distances, compute change in every feature in a table.  .
#' @param pw_dist A pairwise distance table, for instance generated by `get_pairwise_distance`.
#' @param f_table A table containing the features (as columns) that should be contrasted over time.
#' @return a `data.frame` with pairwise differences
#' @export
#'
get_fw_volatility <- function(pw_dist, f_table){
  cbind(pw_dist[,c("from", "to")],
        `colnames<-`(get_fw_diff(x = pw_dist, y = f_table), rownames(f_table)))
}
thomazbastiaanssen/Volatility documentation built on July 13, 2024, 9:09 a.m.