Measures of Skewness and Kurtosis
[This article was first published on Analysis with R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Skewness and kurtosis in R are available in the moments package (to install an R package, click here), and these are:Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
- Skewness – skewness
- Kurtosis – kurtosis
This file contains 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
time <- c(19.09, 19.55, 17.89, 17.73, 25.15, 27.27, 25.24, 21.05, 21.65, 20.92, 22.61, 15.71, 22.04, 22.60, 24.25) | |
library(moments) | |
skewness(time) | |
[1] -0.01565162 | |
kurtosis(time) | |
[1] 2.301051 |
Graphical illustration of the data is in Figure 1.
![]() |
Figure 1. Histogram of the Time Elapsed |
This file contains 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
library(ggplot2) | |
qplot(time, geom = 'histogram', binwidth = 2) + xlab('Time') |
This file contains 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
#Simulation | |
n.sample <- rnorm(n = 10000, mean = 55, sd = 4.5) | |
#Skewness and Kurtosis | |
library(moments) | |
skewness(n.sample) | |
[1] -0.008525844 | |
kurtosis(n.sample) | |
[1] 2.96577 | |
#Histogram | |
library(ggplot2) | |
datasim <- data.frame(n.sample) | |
ggplot(datasim, aes(x = n.sample), binwidth = 2) + | |
geom_histogram(aes(y = ..density..), fill = 'red', alpha = 0.5) + | |
geom_density(colour = 'blue') + xlab(expression(bold('Simulated Samples'))) + | |
ylab(expression(bold('Density'))) |
![]() |
Figure 2. Histogram of the Simulated Data |
To leave a comment for the author, please follow the link and comment on their blog: Analysis with R.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.