CFLib.org – Common Function Library Project

hyGetQuantile(qtil, range)

Last updated July 13, 2006

author

Ralf Guttmann

Version: 1 | Requires: CF5 | Library: MathLib

Description:
Function which returns the value of a certain quantile from a list of numeric values. Similar to the quantile(matrix,alpha) function in ms excel.

Return Values:
Returns a number.

Example:

<cfset quantile = hyGetQuantile("30","1,2,3,4")>
<cfoutput>#quantile#</cfoutput>

Parameters:

Name Description Required
qtil Threshold value for the quantile, numeric between 1 and 100 Yes
range Comma delimited list of numeric values Yes

Full UDF Source:

/**
 * Function which returns the value of a certain quantile from a list of numeric values.
 * Rewritten by Raymond Camden to include VAR statements.
 * 
 * @param qtil 	 Threshold value for the quantile, numeric between 1 and 100 (Required)
 * @param range 	 Comma delimited list of numeric values (Required)
 * @return Returns a number. 
 * @author Ralf Guttmann (ralf.guttmann@hyperspace.de) 
 * @version 1, July 13, 2006 
 */
function hyQuantile(qtil, range) {
	var rangeArr = ListToArray(range);
	var hyqtil = "";
 	var nrofelms = "";
 	var nrofsteps = "";
	var percpos = "";
	var percpos1 = "";
 	var percpos2 = "";
	var rP1 = "";
	var rP2 = "";
	var deltarp = "";
	var wfactor = "";
	var deltarp_v = "";

	qtil = qtil * 0.01;
	arraySort(rangeArr, "numeric");
  
	nrofelms = arrayLen(rangeArr);
	nrofsteps = qtil * (nrofelms - 1);
	
	if(int(nrofsteps) eq nrofsteps) {
		percpos = nrofsteps + 1;
		hyqtil = rangeArr[percpos];
    } else {
		percpos1 = Int(nrofsteps) + 1;
		percpos2 = percpos1 + 1;
		rP1 = rangeArr[percpos1];
		rP2 = rangeArr[percpos2];
		deltarp = rP2 - rP1;
		wfactor = nrofsteps - (Int(nrofsteps));
		deltarp_v = deltarp * wfactor;
		hyqtil = rP1 + deltarp_v;
	}
	return hyqtil;
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson