/** * Calculates the "Median Absolute Deviation" of an array of data. * * Formula: * 1) Sort the array * 2) Calculate the first median * 3) Create new array that each item will be the item of the initial * array minus the first median, as absolute values * 4) Calculate the median again * * @param array $array_of_values */ public static function madCalculate(array $data) { $new_data = []; // Step 1. sort($data); // Step 2. $first_median = Basic::median($data); // Step 3. foreach ($data as $val) { array_push($new_data, abs($val - $first_median)); } // Step 4. $mad = Basic::median($new_data); return $mad * 1.4826; }