-
Notifications
You must be signed in to change notification settings - Fork 4
Adding Median absolute deviation, #4 #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
import { mean } from './central'; | ||
import { | ||
mean, | ||
median, | ||
} from './central'; | ||
|
||
import { | ||
min, | ||
max, | ||
|
@@ -81,6 +85,24 @@ export function stdev(arr, xBar) { | |
return v === undefined ? v : Math.sqrt(v); | ||
} | ||
|
||
/** | ||
* Return the median absolute deviation of a numeric data array. | ||
* The median absolute deviation is the median of the absolute deviations | ||
* from a data sample's median. | ||
* @param {Number[]} arr the data array | ||
* @returns {Number} the median absolute deviation of the data array | ||
*/ | ||
export function medAbsdev(arr) { | ||
const med = median(arr); | ||
const absoluteDeviationArr = []; | ||
if (med === undefined) return undefined; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can go above the previous line. It is not necessary to declare |
||
for (let i = 0; i < arr.length; i += 1) { | ||
const absdev = Math.abs(arr[i] - med); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please be consistent with variable naming and use camelCase. Following the previously defined array In this case, |
||
absoluteDeviationArr.push(absdev); | ||
} | ||
return median(absoluteDeviationArr); | ||
} | ||
|
||
/** | ||
* Return the range of a numeric data array. | ||
* The range of a set of data is the difference between the largest and smallest values. | ||
|
@@ -99,5 +121,6 @@ export default { | |
pStdev, | ||
variance, | ||
stdev, | ||
medAbsdev, | ||
range, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please rename this method to
mad
throughout all files?