ocmath_bin_width

 

Contents

Description

Compute bin width for a histogram

Syntax

double ocmath_bin_width( const double * pSource, UINT nSourceSize, int nRule = BIN_RULE_FREEDMAN_DIACONIS, int nInterpolatePercentiles = INTERPOLATE_EDF )

Parameters

pSource
[input] source data
nSourceSize
[input] source data size
nRule
[input] bin rules to calculate bin width
BIN_RULE_FREEDMAN_DIACONIS//Width = 2*IQR*N^(-1/3)
BIN_RULE_SCOTT//Width = 3.49*SD*N^(-1/3)
BIN_RULE_STURGES //Bins = 1+log2(N)
nInterpolatePercentiles
[input] when nRule is BIN_RULE_FREEDMAN_DIACONIS, this arguemnt is provided as option to calculate IQR.
INTERPOLATE_WEIGHT_AVER_RIGHT = 0, // Weighted average aimed at x(n + 1) p
INTERPOLATE_WEIGHT_AVER_LEFT, // Weighted average aimed at xnp
INTERPOLATE_NEAREST_NEIGHBOR, // Observation numbered closest to np
INTERPOLATE_EDF, // Empirical distribution function, No Interpolation
INTERPOLATE_EDF_AVER, // Empirical distribution function with averaging
INTERPOLATE_TUKEY, // Tukey Hinges, only avaiable in Quartile
INTERPOLATE_LAST_ITEM // Size of this enumeration, number of interpolation methods

Return

Returns bin width on success, otherwise returns NANUM.

Examples

EX1

void ocmath_bin_width_ex1()
{
    vector vSource = {1,2,3,4,5,6,7,6,5,5,4,4,3,32,2};
    double dBinWidth = ocmath_bin_width(vSource, vSource.GetSize());
    // dBinWidth is  2*IQR*nSourceSize^(-1/3)
}

EX2

void ocmath_bin_width_ex2()
{
    vector vSource = {1,2,3,4,5,6,7,6,5,5,4,4,3,32,2};
    double dBinWidth = ocmath_bin_width(vSource, vSource.GetSize(),BIN_RULE_SCOTT);
    // dBinWidth is 3.49*SD*nSourceSize^(-1/3)
}

EX3

void ocmath_bin_width_ex3()
{
    vector vSource = {1,2,3,4,5,6,7,6,5,5,4,4,3,32,2};
    double dBinWidth = ocmath_bin_width(vSource, vSource.GetSize(),BIN_RULE_STURGES);
    // Bins = 1+log2(N), dBinWidth = (vSource.Max - vSource.Min)/bins
}

Remark

See Also

header to Include

origin.h

Reference