Data_percentiles
Description
Calculate percentiles at given percent values for the given dataset.
Syntax
BOOL Data_percentiles( Dataset * pdsData, const double ardPercents[], double ardPercentiles[], int nValues, BOOL bInterpolate = FALSE )
Parameters
- pdsData
- [input] Dataset for which percentiles are computed
- ardPercents
- [input] array of percents at which percentiles are computed
- ardPercentiles
- [output] array of percentiles
- nValues
- [input] number of percentile values to compute
- bInterpolate
- [input] flag indicating whether or not to average (interpolate) when needed such as when computing the 50th percentile for an even number of data values
Return
Returns TRUE on success and FALSE on failure.
Examples
EX1
// This is a self contained sample program for the function Data_percentiles,
// and it demonstrates a simple call of the function.
// The sample data is created at the beginning of the program.
// To run the program, enter the following command in the Script window:
// Data_percentiles_ex1
// This will return the result percentile like following:
// Applying Data_percentiles on Data5_A succedded.
// Simple call; No interpolation
// The 50th Percentile is 0.300000
void Data_percentiles_ex1()
{
BOOL success;
Worksheet wks;
wks.Create();
Dataset myInDs(wks,0);
String strInDsName = myInDs.GetName();
//******* Create sample data *****************
myInDs.SetSize(8);
myInDs[0]=0.3;
myInDs[1]=0.097;
myInDs[2]=0.41256;
myInDs[3]=0.24909;
myInDs[4]=0.47304;
myInDs[5]=0.2476;
myInDs[6]=0.64529;
myInDs[7]=0.44514;
double dPercent = 50;
double dPercentile;
//******** End of Sample Data Creation ******
success = Data_percentiles(&myInDs, &dPercent, &dPercentile, 1); // Demonstration of Data_sum
if(success)
{
printf("Applying Data_percentiles on %s succedded.\n" " Simple call; No interpolation\n",strInDsName);
printf( " The %gth Percentile is %f\n", dPercent, dPercentile );
}
else
printf("Error: Data_percentiles (simple call) failed.\n");
}
EX2
// This is a self contained sample program for the function Data_percentiles,
// and it demonstrates the function call with full specifications.
// The sample data is created at the beginning of the program.
// To run the program, enter the following command in the Script window:
// Data_percentiles_ex1
// This will return the result percentile like following:
// Applying Data_percentiles on Data6_A succedded.
// With full specifications, Flag of Interpolation = 1
// The 5th Percentile is 0.097000
// The 25th Percentile is 0.248345
// The 50th Percentile is 0.356280
void Data_percentiles_ex2()
{
BOOL success;
Worksheet wks;
wks.Create();
Dataset myInDs(wks,0);
String strInDsName = myInDs.GetName();
//******* Create sample data *****************
myInDs.SetSize(8);
myInDs[0]=0.3;
myInDs[1]=0.097;
myInDs[2]=0.41256;
myInDs[3]=0.24909;
myInDs[4]=0.47304;
myInDs[5]=0.2476;
myInDs[6]=0.64529;
myInDs[7]=0.44514;
#define NP 3 // Number of calculated percentiles
double dPercentArray[NP] = { 5, 25, 50 };
double dPercentileArray[NP];
BOOL INTERPOLATE = TRUE;
//******** End of Sample Data Creation ******
success = Data_percentiles(&myInDs,dPercentArray,dPercentileArray,NP,INTERPOLATE); // Demonstration of Data_sum
if(success)
{
printf("Applying Data_percentiles on %s succedded.\n" " With full specifications, Flag of Interpolation = %d\n",strInDsName,INTERPOLATE);
for(int ii = 0; ii < 3; ii++ )
printf(" The %gth Percentile is %f\n",dPercentArray[ii],dPercentileArray[ii]);
}
else
printf("Error: Data_percentiles (with full specifications) failed.\n");
}
Remark
Calculate percentiles at given percent values for the given dataset.
See Also
header to Include
origin.h
Reference
|