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 actually 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.

Syntax

nStdDev = sdevxn( tbl, val )

bullet.gif    tbl is a general lua table.

bullet.gif    val is the target value about which the standad deviation is calculated.

bullet.gif    nStdDev is the standard deviation of the values.

Examples

The following script returns the standard deviation of a table containing 1 million random numbers.

t = random( 1000000 )

-- create a table of uniform random numbers

sd = sdevn( t )

-- ordinary standard devation about the mean

sdx = sdevxn( t, 0.6 )

-- standard deviation about the value 0.6

Printf("sd=%lg, sdx=%lg\n", sd, sdx )

-- 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:

t = { 6, -2, 15, "a", {5,"b"}, c="5.4" }

 

sd = sdevn(t)

-- ordinary standard deviation

sdx = sdevxn(t, 7)

-- standard deviation about the value 7

Printf("sd=%lg, sdx=%lg\n", sd, sdx )

-- result: sd=6.97615, sdx=6.12372

 

-- note that a small sample may give sd > sdx

Related Topics

Table and Array Functions, sdevn, meansdevn, sdev


Mira Pro x64 Script User's Guide, Copyright Ⓒ 2024 Mirametrics, Inc. All Rights Reserved.