Statistics for Programmers - Frequency Distributions
source link: https://nishtahir.com/1-statistics-for-programmers-frequency-distributions/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
By Nish Tahir in Statistics For Programmers — Feb 11, 2024
Statistics for Programmers - Frequency Distributions
A Frequency Distribution is a common way to understand a trend in a dataset. It's a tabular representation of the number of times a value appears in a dataset. If we denote values in a dataset as x1,x2,…,xn, their corresponding frequencies can be denoted as f1,f2,…,fn. This relationship can be expressed as a table.
Value (x)Frequency (f)x1f1x2f2⋮⋮xnfn
Applying this practically, let's consider a dataset of 10 users who were asked to review a product on a scale of 1 to 5. The dataset can be represented as an array of reviews.
[3, 1, 5, 5, 2, 4, 5, 3, 1, 5]
We can construct a frequency distribution table for this dataset by counting the number of times each unique element appears in the array.
Value (x) | Frequency (f)
-------------------------
1 | 2
2 | 1
3 | 2
4 | 1
5 | 4
This can be expressed in code using a Map
(or Dictionary
depending on your language of choice) of unique values and how many times they appear in a given dataset.
Once again considering our array of reviews,
const arr = [3, 1, 5, 5, 2, 4, 5, 3, 1, 5];
We can construct a function that counts the number of times each unique element appears in the array.
function frequencyDistribution(arr) {
const map = {};
for(let i = 0; i < arr.length; i++) {
const item = arr[i];
if (map[item]) {
map[item] += 1;
} else {
map[item] = 1;
}
}
return map;
}
Applying this function to our dataset gives us the following output,
This post is for subscribers only
Recommend
-
75
Dragonfire the open-source virtual assistant for Ubuntu based Linux distributions
-
96
Samsung phones soon can run true GNU/Linux distributions Imagine being able to place your cellphone into a small little dock, and be able to run your favourite Linux distribution on a monitor with proper mouse and keyboard, use it as yo...
-
116
FSF adds PureOS to list of endorsed GNU/Linux distributions
-
47
FSF adds PureOS to list of endorsed GNU/Linux distributionsPurismBeautiful, Secure, Privacy-Respecting Laptops & P...
-
115
This is a brief rant about a poor packaging decision in Debian that was made recently that just caught me by surprise and I felt like sharing.
-
37
As a mixed methods researcher, I love working with qualitative data, but I also love the idea of using quantitative methods to add some meaning and context to the words. This is the main reason I’ve started digging into usin...
-
8
Some good "Statistics for programmers" resources This post is basically a list of books & other resources that teach statistics using programming. But first I wanted to say why I think that is important! You c...
-
0
By Nish Tahir in Statistics...
-
5
By Nish Tahir in Statistics...
-
4
By Nish Tahir in Statistics...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK