| Signature | Description | Parameters |
|---|---|---|
include <DataFrame/DataFrameStatsVisitors.h> template<arithmetic T, typename I = unsigned long> struct CoeffVariationVisitor; // ---------------------------------- template<std::floating_point T, typename I = unsigned long> using cffv_v = CoeffVariationVisitor<T, I>; |
This is a "single action visitor", meaning it is passed the whole data vector in one call and you must use the single_act_visit() interface. The coefficient of variation (CV) is a standardized, unitless measure of data dispersion, calculated as the ratio of the standard deviation to the mean. It allows for the comparison of variability between different datasets, even those with different units or vastly different means, providing insight into the relative variability or the precision of an estimate. Standard deviation measures absolute variability (spread) in a dataset with specific units, while the coefficient of variation (CV) measures relative variability by expressing the standard deviation as a percentage of the mean, making it unitless and ideal for comparing variability across datasets with different units or scales. The CV helps determine which dataset has greater variability relative to its average. |
T: Column data type. I: Index type. |
static void test_CoeffVariationVisitor() { std::cout << "\nTesting ConfIntervalVisitor{ } ..." << std::endl; using StrDataFrame = StdDataFrame<std::string>; StrDataFrame df; try { df.read("IBM.csv", io_format::csv2); } catch (const DataFrameError &ex) { std::cout << ex.what() << std::endl; ::exit(-1); } df.load_column("Extra Col", std::vector<double> { 5.1, 4.9, 5.0, 5.3, 5.2, 4.8 }, nan_policy::dont_pad_with_nans); CoeffVariationVisitor<double, std::string> cv_v1; df.single_act_visit<double>("Extra Col", cv_v1); assert(std::fabs(cv_v1.get_result() - 0.037046) < 0.000001); cffv_v<double, std::string> cv_v2; df.single_act_visit<double>("IBM_Close", cv_v2); assert(std::fabs(cv_v2.get_result() - 0.294703) < 0.000001); }