I had to compute the SD for some numbers recently, so after figuring out
what Standard Deviation is (thanks to my brother), I whipped up this code
if anyone is interested:

<!--- Usage <cf_sd list="162.5,163.6,165.2"> --->

<CFPARAM NAME="Attributes.List" DEFAULT="162.5,163.6,165.2">

<CFSCRIPT>
// Convert list to array and set values
ThisArray = ListToArray(Attributes.List); Total = ArraySum(ThisArray); 
Average = ArrayAvg(ThisArray); Items = ArrayLen(ThisArray); SDTotal = 0;
// Compute Standard Deviation Total
for(Loop=1 ; Loop LTE Items; Loop=Loop+1) { SDTotal = SDTotal +
(ThisArray[Loop] - Average)^2; }
// Output variables
Caller.Average = Average;
Caller.Variance = (SDTotal / Items);
Caller.SD = SQR(Caller.Variance);
</CFSCRIPT>

<CFOUTPUT><P>Average: #Caller.Average#<BR>Variance:
#Caller.Variance#<BR>Standard Deviation: #Caller.SD#</P></CFOUTPUT>

Of course, I then found CF_StandardDeviation in the Developer's Exchange,
but mine is shorter. ;p


Tony Schreiber, Senior Partner                  Man and Machine, Limited
mailto:[EMAIL PROTECTED]                   http://www.technocraft.com

http://www.linktoss.com _______The Fastest Way to Send a Link to Anyone!
http://www.digitacamera.com ______________DigitA Camera Scripts and Tips
http://www.is300.net ___________The Enthusiast's Home of the Lexus IS300
http://www.cfug-sfl.org ___________South Florida Cold Fusion Users Group
http://www.simplemessageboard.com ___Free Forum Software for Cold Fusion


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm

Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to