-
Notifications
You must be signed in to change notification settings - Fork 16
SHRIMP: Function fdNmad
sbodorkos edited this page Feb 6, 2018
·
3 revisions
This subroutine evaluates the double-precision value fdNmad (median absolute deviation) corresponding to an input vector v comprising double-precision numbers.
fdNmad( v )
v: Vector containing double-precision values.
Values of type Integer
i, N, Nn
Values of type Double
med, medyr2, fdNmad
Arrays of type Double
v, yr2
The function utilises the Excel function UBound (http://www.excelfunctions.net/vba-ubound-function.html) to determine the length of the input vector:
N = UBound( v ) --like length(v)
med = Median( v )
Nn = Max( 3, N ) --minimum value of 3
ReDim yr2[1 to N] --apparently not zero-addressed
For i = 1 to N
yr2[i] = ( v[i] - med )^2
Next i
medyr2 = Median( yr2 )
fdNmad = 1.4826 * ( 1 + 5 / (Nn - 2) ) * Sqrt( medyr2 )
End Function
The magic number 1.4826 is hard-coded (by Ludwig and by most other users of MAD-related functions: this value ensures that "± MAD" encompasses 50% (i.e. between 1/4 and 3/4) of the normal cumulative distribution function (e.g. https://en.wikipedia.org/wiki/Median_absolute_deviation).