How to measure central tendency in Python and R
A measure of central tendency is a summary measure that attempts to describe a whole set of data with a single value that represents the middle or centre of its distribution.
There are three statistical measurements that can be used to measure the central tendency, and these measurements are:-
- Mean, being the average of a group of numbers.
- Median, being the centre number in a group of numbers.
- Mode, being the most frequently used number.
Computer technology is great because it enables a researcher to quickly and efficiently calculate the central tendency. In this post I will demonstrate how to measure the central tendency of a list of ages in two different programming languages, being Python and R.
Python is a general purpose language that utilises inbuilt and outsourced open source libraries to help it to make calculations by calling a function.
R is a statistical programming language designed for statisticians. This language has many inbuilt functions, but some of them, such as the mode function, must be imported through libraries.
The first language that I am going to demonstrate the measure of the central tendency is Python. I have written the code in a Jupyter Notebook that is hosted by Google, being Google Colab:-
- Python does not have an inbuilt mean function, so a variable must be created, mean_age, which is the sum of…