mad
The mad aggregate returns the median absolute deviation from a set of input values. Available only in the Enterprise Edition.
Synopsis
AFL% aggregate(array,mad(attribute),[dimension_1[,dimension_2,...]])
Library
The mad aggregate resides in the Linear Algebra library. Run the following query to load this library:
AFL% load_library('linear_algebra');
Summary
The mad aggregate returns the median absolute deviation (MAD) for specified dimension(s) of an array or the entire array. MAD is defined as the median of the absolute deviations from the data's median value.
For each possible combination of values of specified dimensions (once if none are specified), a subset of the values of the specified attribute of the array is formed over all other dimensions. For each of these subsets , MAD calculates:
(1) |
Examples
Find the MAD of Each Row
To find the MAD of each row of a 2×3 1-attribute array:
Create an array M:
AFL% create array M<v:double>[row=0:1; col=0:2]; AFL% store(build(M, '[[1, 5, 17],[22, 6, -11]]', true), M);
The output is:{row,col} v {0,0} 1 {0,1} 5 {0,2} 17 {1,0} 22 {1,1} 6 {1,2} -11
Find the MAD of both rows of M:
AFL% aggregate(M, mad(v), row);
The output is:{row} v_mad {0} 4 {1} 16
Find the MAD of the columns of M:
AFL% aggregate(M, mad(v), col);
The output is:{col} v_mad {0} 10.5 {1} 0.5 {2} 14
Find the MAD of the entire array:
AFL% aggregate(M, mad(v));
The output is:{i} v_mad {0} 8
Remove the example array:
AFL% remove(M);