| ocmath_percentiles  DescriptionFunction to compute percentiles (vector) for the vectors passing the percents and data. Syntax
int ocmath_percentiles( const double * pData, const int nSize, const double * pPercents, const int nPercentSize, double * pPercentiles, int nInterpolate = INTERPOLATE_WEIGHT_AVER_RIGHT, const double * pWeight = NULL )
 Parameters
    pData[input] pointer to data on which percentiles are computednSize[input] value of size of pData.pPercents[input] pointer to percents for which percentiles are computednPercentSize[input] value of size of percents to be computedpPercentiles[output] pointer containing percentiles (results)nInterpolate[input] Optional input indicating interpolation type, possible values include:INTERPOLATE_WEIGHT_AVER_RIGHT(Default) Weighted average aimed at x(n + 1) pINTERPOLATE_WEIGHT_AVER_LEFT Weighted average aimed at xnpINTERPOLATE_NEAREST_NEIGHBOR Observation numbered closest to npINTERPOLATE_EDF Empirical distribution functionINTERPOLATE_EDF_AVER Empirical distribution function with averagingpWeight[input] Optional input of weight. if observations have identical weights, the weighted percentiles are the same as unweighted percentile with nInterpolate == INTERPOLATE_EDF_AVER. ReturnReturns STATS_NO_ERROR on successful exit and a non-zero STATS error code on failure. Examples
void ocmath_percentiles_ex1()
{
//--- Input data and percents for calculate the percentiles
        
        int nDataSize = 11;   // odd number of data points
//        vector vData(nDataSize);
        vector vData={1.0,1.0,2.0,3.0,3.0,3.0,5.0,6.0,7.0,8.0,9.0};
        
        int nPercents = 3;
//        vector vPercents(nPercents);
        vector vPercents = {50,70,80};  // 50%, 70% percents etc
        
        // The way to calculate the percentiles
        int nInterpolateType = INTERPOLATE_EDF;
        
//--- Output vector to store the percentiles
        vector vPercentiles(nPercents);
//--- Calculate the percentiles   
        ocmath_percentiles(vData,nDataSize,vPercents,nPercents,vPercentiles,nInterpolateType);
//--- Print and show the percentiles      
        printf("\n");
        for(int i=0; i<nPercents; i++)
        {
                printf("%f ", vPercentiles[i]);
        }
        printf("\n");
// For 50% percent, the corresponding returned element in percentiles vector is equal to the median value of the data vector
// Expected result:   3.0  6.0  7.0
}
RemarkSee Alsoheader to Includeorigin.h Reference |