# Add function to Math UDF

## Recommended Posts

I'd like to get a function added to the Math UDF, Standard Deviation. This function is usefull in determining in a set of values are well distributed within a bathtub plot. I've already written it and an example:

The Function:

```; #FUNCTION# ====================================================================================================================
; Name...........: _StandardDeviation()
; Description ...: Returns the standard deviation for all entries in an array
; Syntax.........: _StandardDeviation( \$ArrayVariable )
; Parameters ....: \$ArrayVariable = The array variable to calculate Standard Deviation for
; Return values .: On Success: = Sets @Error and Returns the Standard Deviation for the array variable's entries
;                  On Failure: = Sets @Error and Returns -1
;                  @ERROR:     = 0 = No error.
;                                -1 = The variable passed was not an array
; Author ........: "tim292stro" Tim Strommen <tim292stro at yahoo.com dot com>
; Remarks .......: Array must be 1 based, entry 0 in the array should be the count of the array elements
; Example .......: MsgBox ( 0, "Standard Deviation of \$SomeArrayVariable:", _StandardDeviation ( \$SomeArrayVariable ) )
; ===============================================================================================================================
Func _StandardDeviation ( \$StandardDevArray = "" )
Local \$SDAveLoop = 0
Local \$SDAveVal = 0
Local \$SDDeviationArray[1] = [0]
Local \$DevArrayPopLoop = 0
Local \$SDCalc = 0
If IsArray ( \$StandardDevArray ) Then
For \$SDAveLoop = 1 To \$StandardDevArray[0]
\$SDAveVal = \$SDAveVal + \$StandardDevArray[\$SDAveLoop]
Next
\$SDAveVal = \$SDAveVal / \$StandardDevArray[0]
For \$DevArrayPopLoop = 1 To \$StandardDevArray[0]
_ArrayAdd ( \$SDDeviationArray, ( \$StandardDevArray[\$DevArrayPopLoop] - \$SDAveVal )^2 )
\$SDDeviationArray[0] = \$SDDeviationArray[0] + 1
Next
\$SDAveVal = 0
For \$SDCalc = 1 To \$SDDeviationArray[0]
\$SDAveVal = \$SDAveVal + \$SDDeviationArray[\$SDCalc]
Next
@error = 0
Return ( \$SDAveVal / ( \$SDDeviationArray[0] - 1 ) )
Else
@error = -1
Return -1
EndIf
EndFunc```

And an example:

```#include-once
#include <array.au3>
Global \$SomeArrayVariable[25] = [24,34,35,35,34,33,33,33,34,34,33,35,34,34,35,34,33,33,32,33,31,32,33,33,32]

MsgBox ( 0, "Standard Deviation of \$SomeArrayVariable:", _StandardDeviation ( \$SomeArrayVariable ) )```

For those who haven't used a standard deviation before, it is more or less a way of evaluating how good a data set is. There are plenty of websites describing the use of this function - just google "Standard Deviation".

Best,

-Tim

Edited by tim292stro

##### Share on other sites

That's nice to have but I believe it belongs to a Statistics UDF rather than the (basic) Maths UDF.

There might be a need for classical functions of statistical analysis (mean, median, variance, quantile, multivariate stuf, usual distributions and their related functions, non-linear fit, data smoothing, inter- & extrapolation, ...) but I find they should be set apart. Not because they stink, simply because then there would be no good reason not to include as well matrix & tensor calculus, number theoretic stuff, and endless [interesting] functions as well. Mere users needing only Floor or Sqrt would see useless bloat in their scripts just by including <Maths.au3>.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

##### Share on other sites

You should specify that your function assumes a population sample in the array and applies Bessel's Correction as a default. Otherwise, your function will return the incorrect standard deviation if the array contains the entire population, especially at low degrees of freedom.

- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!

## Create an account

Register a new account

×

• Wiki

• Back

• Git