Last Update: January 14, 2021
Descriptive statistics consists of quantitative or qualitative data population or sample frequency distribution, central tendency measures, dispersion measures, association measures and frequency distribution shape.
This topic is part of Business Statistics with R course. Feel free to take a look at Course Curriculum.
This tutorial has an educational and informational purpose and doesn’t constitute any type of forecasting, business, trading or investment advice. All content, including code and data, is presented for personal educational use exclusively and with no guarantee of exactness of completeness. Past performance doesn’t guarantee future results. Please read full Disclaimer.
1. Dispersion measures
Dispersion measures consist of data population or sample variability. Main dispersion measures are standard deviation, variance and average deviation or mean absolute deviation.
- Standard deviation consists of squared root of average data population or sample squared dispersion.
Where = population standard deviation, = data, = population mean, = population number of observations, = corrected sample standard deviation, = sample mean, = sample number of observations.
- Variance consists of average data population or sample squared dispersion.
Where = population variance, = data, = population mean, = population number of observations, = corrected sample variance, = sample mean, = sample number of observations.
- Mean absolute deviation or average deviation consists of average data population or sample absolute dispersion.
Where = population mean absolute deviation or average deviation, = data, = population mean, = population number of observations, = sample mean absolute deviation or average deviation, = sample mean, = sample number of observations.
2. R script code example.
2.1. Load R package [1].
library('quantmod')
2.2. Dispersion measures data reading and data daily arithmetic returns calculation.
- Data: S&P 500® index replicating ETF (ticker symbol: SPY) daily adjusted close prices (2007-2015).
data <- read.csv('Dispersion-Measures-Data.txt',header=T)
spy <- xts(data[,2],order.by=as.Date(data[,1]))
rspy <- dailyReturn(spy)
colnames(rspy) <- 'rspy'
2.3. Dispersion measures data daily arithmetic returns corrected sample standard deviation calculation and output.
In:
sd(rspy)
Out:
[1] 0.01356701
2.4. Dispersion measures data daily arithmetic returns corrected sample variance calculation and output.
In:
var(rspy)
Out:
rspy
rspy 0.0001840637
2.5. Dispersion measures data daily arithmetic returns sample mean absolute deviation or sample average deviation calculation and output.
In:
mean(abs(rspy-mean(rspy)))
Out:
[1] 0.008663449
3. References.
[1] Jeffrey A. Ryan and Joshua M. Ulrich. “quantmod: Quantitative Financial Modelling Framework”. R package version 0.4-17. 2020.