-
Notifications
You must be signed in to change notification settings - Fork 224
/
z_score.js
28 lines (27 loc) · 1 KB
/
z_score.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/**
* The [Z-Score, or Standard Score](http://en.wikipedia.org/wiki/Standard_score).
*
* The standard score is the number of standard deviations an observation
* or datum is above or below the mean. Thus, a positive standard score
* represents a datum above the mean, while a negative standard score
* represents a datum below the mean. It is a dimensionless quantity
* obtained by subtracting the population mean from an individual raw
* score and then dividing the difference by the population standard
* deviation.
*
* The z-score is only defined if one knows the population parameters;
* if one only has a sample set, then the analogous computation with
* sample mean and sample standard deviation yields the
* Student's t-statistic.
*
* @param {number} x
* @param {number} mean
* @param {number} standardDeviation
* @return {number} z score
* @example
* zScore(78, 80, 5); // => -0.4
*/
function zScore(x, mean, standardDeviation) {
return (x - mean) / standardDeviation;
}
export default zScore;