| Signature | Description | Parameters |
|---|---|---|
include <DataFrame/DataFrameStatsVisitors.h> template<arithmetic T, typename I = unsigned long> struct ConfIntervalVisitor; // ---------------------------------- template<std::floating_point T, typename I = unsigned long> using coni_v = ConfIntervalVisitor<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. A confidence interval is a range of values derived from sample data that is likely to contain the true, unknown population parameter. It's calculated as a point estimate (like the sample mean) plus or minus a margin of error. The accompanying confidence level, such as 95%, indicates the long-run probability that repeated sampling would result in intervals containing the true parameter. A 95% confidence interval does not mean there is a 95% probability that the true population mean lies in this specific interval . Instead, it means that if you were to conduct this procedure many times with different samples, 95% of the intervals you generate would contain the true population mean.
explicit
ConfIntervalVisitor (value_type conf_level = 0.95);
conf_level: Confidence level must be between 80% and 99.9% inclusive,
otherwise the result is NaN.
There are also the following member functions:
get_result(): Returns a std::pair<T, T> containing lower and upper limits of
plausible values for the true population parameter.
get_error_margin(): Returns the the margin pf error.
|
T: Column data type. I: Index type. |
static void test_ConfIntervalVisitor() { 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); ConfIntervalVisitor<double, std::string> ci_v1 { 0.95 }; df.single_act_visit<double>("Extra Col", ci_v1); assert(std::fabs(ci_v1.get_error_margin() - 0.149697) < 0.000001); assert(std::fabs(ci_v1.get_result().first - 4.9003) < 0.0001); assert(std::fabs(ci_v1.get_result().second - 5.1997) < 0.0001); ConfIntervalVisitor<double, std::string> ci_v2 { 0.96 }; df.single_act_visit<double>("Extra Col", ci_v2); assert(std::fabs(ci_v2.get_error_margin() - 0.159023) < 0.000001); assert(std::fabs(ci_v2.get_result().first - 4.89098) < 0.00001); assert(std::fabs(ci_v2.get_result().second - 5.20902) < 0.00001); coni_v<double, std::string> ci_v3 { 0.99 }; df.single_act_visit<double>("IBM_Close", ci_v3); assert(std::fabs(ci_v3.get_error_margin() - 1.39119) < 0.00001); assert(std::fabs(ci_v3.get_result().first - 128.601) < 0.001); assert(std::fabs(ci_v3.get_result().second - 131.383) < 0.001); }