The TPSAS R package implements the univariate two-piece sinh–arcsinh distribution, which contains two shape parameters that separately control skewness and kurtosis. This distribution can capture higher levels of asymmetry than the original sinh–arcsinh distribution, in terms of some asymmetry measures, while keeping flexibility of the tails and tractability.
References.
Example: Data fitting.
rm(list=ls())
#Required packages
library(TPSAS)
#Simulated data
set.seed(123)
data = rtpsas(10000,10,1,0.5,0.75)
############################################################################################
# TP SAS Fit
############################################################################################
# Log-likelihood
ll = function(par){
if(par[2]>0 & abs(par[3])<1 & par[4]>0){
return( - sum(dtpsas(data,par[1],par[2],par[3],par[4],param="eps",log=T)))
}
else return(Inf)
}
OPT = optim(c(10,1,0.5,0.75),ll, control = list(maxit=50000),method = c("Nelder-Mead"))
MLE = OPT$par
# fitted TPSAS density
fit.den = Vectorize(function(x) dtpsas(x,MLE[1],MLE[2],MLE[3],MLE[4],param="eps"))
hist(data,breaks=50,probability=T,ylim=c(0,0.45),cex.axis=1.5,cex.lab=1.5)
curve(fit.den,3,13,lwd=2,col="red",add=T,n=1000)
box()