sdevxn
The sdevxn function returns the standard deviation about a specified mean value for a general lua table that may contain a multi-dimensional array or a mixture of numbers, strings, named keys, and sub-tables. This differs from the ordinary standard deviation which calculates the standard deviation about the mean value.
Note that specifying the mean value changes the number of degrees of freedom from n-1 for the ordinary standard deviation to n for this calculation, and this leads to a different result. Since the ordinary standard deviation minimizes the deviation about the calculated (optimal) mean value, the smallest standard deviation should result from calculating the ordinary standard deviation. Be wary of getting sporadic results from small samples. A smaller sample size has less statistical significance and may produce a standard deviation that is smaller than from the ordinary calculation. See the examples below.
Only numeric values found in the table are used in the calculation. If the mean value is not specified use sdevn to calculate the ordinary standard deviation of a general table.
The related sdev function calculates the mean of a 1-dimensional array, CImage, or list of numbers.
nStdDev = sdevxn( tbl, val )
tbl is a general lua table.
val is the target value about which the standad deviation is calculated.
nStdDev is the standard deviation of the values.
The following script returns the standard deviation of a table containing 1 million random numbers.
|
-- create a table of uniform random numbers |
|
-- ordinary standard devation about the mean |
|
-- standard deviation about the value 0.6 |
|
-- result: sd=0.288824, sdx=0.305442 |
|
-- theoretical value as n --> infinity is sd=0.28868 |
The next example computes the standard deviation about the vale 7 for an ugly, complex table:
|
|
|
-- ordinary standard deviation |
|
-- standard deviation about the value 7 |
|
-- result: sd=6.97615, sdx=6.12372 |
|
-- note that a small sample may give sd > sdx |
Mira Pro x64 Script User's Guide, v.8.73 Copyright Ⓒ 2024
Mirametrics, Inc. All Rights Reserved.