- Related Questions & Answers
- Absolute and Relative frequency in Pandas
- Array element with minimum sum of absolute differences?
- Arrange first N natural numbers such that absolute difference between all adjacent elements > 1?
- Absolute distinct count in a sorted array?
- Absolute Difference between the Sum of Non-Prime numbers and Prime numbers of an Array?
- Absolute Difference between the Product of Non-Prime numbers and Prime numbers of an Array?
- Absolute difference between the first X and last X Digits of N?
- Absolute difference between sum and product of roots of a quartic equation?
- Absolute Difference of even and odd indexed elements in an Array (C++)?
- Absolute Difference of all pairwise consecutive elements in an array (C++)?
- Absolute and Relative Imports in Python
- How to SELECT records if the absolute value of the difference between two values is greater than a certain number?
- Get Absolute value with MongoDB aggregation framework?
- How to find absolute difference between two numbers in MySQL?
- Get an Absolute Filename Path from a Relative Filename with Path in Java

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

In Statistical analysis study of data variability in a sample indicates how dispersed are the values in a given data sample. The two important ways we calculate the variability are **Absolute Deviation** and ** Mean Absolute Deviation**.

In this method we first find the mean value of the given sample and then calculate the difference between each value and the mean value of the sample called as the absolute deviation value of each data sample. So for the values higher than mean the value the deviation value will be positive and for those lower than the mean value the deviation value will be negative. Next we take the absolute values using the **absolute** function to make each deviation as positive. Summing up all these absolute deviation gives a positive result. Without absolute value the sum of these deviations would be zero.

In the below example we take a data sample and calculate the absolute deviation for each data element.

from numpy import mean, absolute data = [12, 42, 53, 13, 112] # Find mean value of the sample M = mean(data) print "Sample Mean Value = ",mean(data) print "\n" # Calculate absolute deviation print "Data-Mean","","deviation" for i in range(len(data)): dev = absolute(data[i] - M) print data[i],"-",M,round((dev),2)

Running the above code gives us the following result -

Sample Mean Value = 46.4 Data-Mean deviation 12 - 46.4 34.4 42 - 46.4 4.4 53 - 46.4 6.6 13 - 46.4 33.4 112 - 46.4 65.6

Mean Absolute Deviation (MAD) is the mean value of all the absolute deviations we calculate for each data point. Taking the same sample as in previous example, we add code to sum up the value of the absolute deviations and divide it by the sample size.

from numpy import mean, absolute data = [12, 42, 53, 13, 112] # Find mean value of the sample M = mean(data) print "Sample Mean Value = ",mean(data) sum = 0 # Calculate mean absolute deviation for i in range(len(data)): dev = absolute(data[i] - M) sum = sum + round(dev,2) print "Mean Absolute Deviation: ", sum/len(data)

Running the above code gives us the following result:

Sample Mean Value = 46.4 Mean Absolute Deviation: 28.88

Advertisements