Created
September 21, 2015 14:46
-
-
Save Dartv/4e77ffa81efc17f5e80a to your computer and use it in GitHub Desktop.
Calculating frequency
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let nums = [30, 36, 37, 41, 42, 41, 40, 41, 46, 47, 46, 46, 47, 45, 46, 45, 50, 51, 50, 52, 52, 51, 51, 52, 50, 50, 56, 55, 56, 57, 57, 57, 57, 58, 58, 55, 61, 62, 67, 67]; | |
let unique = _.unique(nums); | |
let absoluteFrequency = _.countBy(nums, num => num); | |
let relativeFrequency = () => { | |
let obj = {}; | |
let values = _.values(absoluteFrequency); | |
let keys = _.keys(absoluteFrequency); | |
for (var i = 0; i < keys.length; i++) { | |
obj[keys[i]] = values[i] / nums.length; | |
} | |
return obj; | |
} | |
let cummulativeFrequency = _.values(absoluteFrequency).reduce((sum, val) => sum += val, 0); | |
unique.sort(); | |
console.log(`Уникальные числа: ${unique}`); | |
console.log(`Относительная частота: `, relativeFrequency()); | |
console.log(`Абсолютная частота: `, absoluteFrequency); | |
console.log(`Накопительная частота: ${cummulativeFrequency}`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment