Skewness and Kurtosis in R Programming - GeeksforGeeks

25 Jan, 2022
In statistics, skewness and kurtosis are the measures which tell about the shape of the data distribution or simply, both are numerical methods to analyze the shape of data set unlike, plotting graphs and histograms which are graphical methods. These are normality tests to check the irregularity and asymmetry of the distribution. To calculate skewness and kurtosis in R language, moments package is required.  
Skewness is a statistical numerical method to measure the asymmetry of the distribution or data set. It tells about the position of the majority of data values in the distribution around the mean value. Formula:where,  
represents coefficient of skewness represents value in data vector represents mean of data vector n represents total number of observations
There exist 3 types of skewness values on the basis of which asymmetry of the graph is decided. These are as follows: 
If the coefficient of skewness is greater than 0 i.e. , then the graph is said to be positively skewed with the majority of data values less than mean. Most of the values are concentrated on the left side of the graph.Example:  
Python3
# Required for skewness() functionlibrary(moments) # Defining data vectorx <- c(40, 41, 42, 43, 50) # output to be present as PNG filepng(file = "positiveskew.png") # Print skewness of distributionprint(skewness(x)) # Histogram of distributionhist(x) # Saving the filedev.off()
Output:  
[1] 1.2099
Graphical Representation:  
 
If the coefficient of skewness is equal to 0 or approximately close to 0 i.e. , then the graph is said to be symmetric and data is normally distributed.Example:  
Python3
# Required for skewness() functionlibrary(moments) # Defining normally distributed data vectorx <- rnorm(50, 10, 10) # output to be present as PNG filepng(file = "zeroskewness.png") # Print skewness of distributionprint(skewness(x)) # Histogram of distributionhist(x) # Saving the filedev.off()
Output:  
[1] -0.02991511
Graphical Representation:  
 
If the coefficient of skewness is less than 0 i.e. , then the graph is said to be negatively skewed with the majority of data values greater than mean. Most of the values are concentrated on the right side of the graph.Example:  
Python3
# Required for skewness() functionlibrary(moments) # Defining data vectorx <- c(10, 11, 21, 22, 23, 25) # output to be present as PNG filepng(file = "negativeskew.png") # Print skewness of distributionprint(skewness(x)) # Histogram of distributionhist(x) # Saving the filedev.off()
Output:  
[1] -0.5794294
Graphical Representation:  
 
Kurtosis is a numerical method in statistics that measures the sharpness of the peak in the data distribution.Formula: where,  
represents coefficient of kurtosis represents value in data vector represents mean of data vector n represents total number of observations
There exist 3 types of Kurtosis values on the basis of which sharpness of the peak is measured. These are as follows: 
If the coefficient of kurtosis is less than 3 i.e. , then the data distribution is platykurtic. Being platykurtic doesn’t mean that the graph is flat-topped.Example:  
Python3
# Required for kurtosis() functionlibrary(moments) # Defining data vectorx <- c(rep(61, each = 10), rep(64, each = 18),rep(65, each = 23), rep(67, each = 32), rep(70, each = 27),rep(73, each = 17)) # output to be present as PNG filepng(file = "platykurtic.png") # Print skewness of distributionprint(kurtosis(x)) # Histogram of distributionhist(x) # Saving the filedev.off()
Output:  
[1] 2.258318
Graphical Representation:  
 
If the coefficient of kurtosis is equal to 3 or approximately close to 3 i.e. , then the data distribution is mesokurtic. For normal distribution, kurtosis value is approximately equal to 3.Example:  
Python3
# Required for kurtosis() functionlibrary(moments) # Defining data vectorx <- rnorm(100) # output to be present as PNG filepng(file = "mesokurtic.png") # Print skewness of distributionprint(kurtosis(x)) # Histogram of distributionhist(x) # Saving the filedev.off()
Output:  
[1] 2.963836
Graphical Representation:  
 
If the coefficient of kurtosis is greater than 3 i.e. , then the data distribution is leptokurtic and shows a sharp peak on the graph.Example:  
Python3
# Required for kurtosis() functionlibrary(moments) # Defining data vectorx <- c(rep(61, each = 2), rep(64, each = 5),rep(65, each = 42), rep(67, each = 12), rep(70, each = 10)) # output to be present as PNG filepng(file = "leptokurtic.png") # Print skewness of distributionprint(kurtosis(x)) # Histogram of distributionhist(x) # Saving the filedev.off()
Output:  
[1] 3.696788
Graphical Representation:  
 
rkbhola5
R-Statistics
R Language
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Change column name of a given DataFrame in R
How to Replace specific values in column in R DataFrame ?
Filter data by multiple conditions in R using Dplyr
Loops in R (for, while, repeat)
Adding elements in a vector in R programming - append() method
How to change Row Names of DataFrame in R ?
Change Color of Bars in Barchart using ggplot2 in R
Convert Factor to Numeric and Numeric to Factor in R Programming
Group by function in R using Dplyr
How to Change Axis Scales in R Plots?