# you'll need lots of extra packages to run these examples of different distributions
if (FALSE) # these examples require multiple packages from 'Suggests', so don't test on CRAN
library(MASS)
library(PerformanceAnalytics)
data(managers)
x = checkData(managers[,2, drop = FALSE], na.rm = TRUE, method = "vector")
# Panel 1: Normal distribution
chart.QQPlot(x, main = "Normal Distribution",
line=c("quartiles"), distribution = 'norm',
envelope=0.95)
# Panel 2, Log-Normal distribution
fit = fitdistr(1+x, 'lognormal')
chart.QQPlot(1+x, main = "Log-Normal Distribution", envelope=0.95,
distribution='lnorm',distributionParameter='meanlog = fit$estimate[[1]],
sdlog = fit$estimate[[2]]')
# Panel 3: Mixture Normal distribution
# library(nor1mix)
obj = norMixEM(x,m=2)
chart.QQPlot(x, main = "Normal Mixture Distribution",
line=c("quartiles"), distribution = 'norMix', distributionParameter='obj',
envelope=0.95)
# Panel 4: Symmetric t distribution
library(sn)
n = length(x)
fit.tSN = st.mple(as.matrix(rep(1,n)),x,symmetr = TRUE)
names(fit.tSN$dp) = c("location","scale","dof")
round(fit.tSN$dp,3)
chart.QQPlot(x, main = "MO Symmetric t-Distribution QQPlot",
xlab = "quantilesSymmetricTdistEst",line = c("quartiles"),
envelope = .95, distribution = 't',
distributionParameter='df=fit.tSN$dp[3]',pch = 20)
# Panel 5: Skewed t distribution
fit.st = st.mple(as.matrix(rep(1,n)),x)
# fit.st = st.mple(y=x) Produces same result as line above
names(fit.st$dp) = c("location","scale","skew","dof")
round(fit.st$dp,3)
chart.QQPlot(x, main = "MO Returns Skewed t-Distribution QQPlot",
xlab = "quantilesSkewedTdistEst",line = c("quartiles"),
envelope = .95, distribution = 'st',
distributionParameter = 'xi = fit.st$dp[1],
omega = fit.st$dp[2],alpha = fit.st$dp[3],
nu=fit.st$dp[4]',
pch = 20)
# Panel 6: Stable Parietian
library(fBasics)
fit.stable = stableFit(x,doplot=FALSE)
chart.QQPlot(x, main = "Stable Paretian Distribution", envelope=0.95,
distribution = 'stable',
distributionParameter = 'alpha = fit(stable.fit)$estimate[[1]],
beta = fit(stable.fit)$estimate[[2]],
gamma = fit(stable.fit)$estimate[[3]],
delta = fit(stable.fit)$estimate[[4]], pm = 0')
#end examples
Run the code above in your browser using DataLab