Estimation Demo

Alexios Galanos

2024-08-22

This provides a quick demo to illustrate how to specify and estimate a distribution.

We’ll choose the Hyperbolic distribution which is a special case of the Generalized Hyperbolic when \(\lambda = 1\). This will allow us to show how parameters can be fixed pre-estimation.

library(tsdistributions)
#> Loading required package: tsmethods
# simulate data
set.seed(101)
sim <- rgh(3000, mu = 0, sigma = 1, skew = -0.8, shape = 4, lambda = 1)
spec <- distribution_modelspec(sim, distribution = "gh")
# fix lambda to value and set it to non-estimate
spec$parmatrix[parameter == "lambda", value := 1.0]
spec$parmatrix[parameter == "lambda", estimate := 0]
mod <- estimate(spec, use_hessian = FALSE)
summary(mod, vcov_type = "QMLE")
#> GH Model Summary
#> 
#> Coefficients:
#>        Estimate Std. Error t value Pr(>|t|)    
#> mu    -0.004746   0.018188  -0.261    0.794    
#> sigma  0.994586   0.017599  56.512  < 2e-16 ***
#> skew  -0.862228   0.069727 -12.366  < 2e-16 ***
#> shape  5.192491   1.282574   4.048 5.15e-05 ***
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#> N: 3000,  dof: 5,  
#> LogLik: -3983,  AIC:  -7957,  BIC: -7933

A variety of estimators are available for the standard error, and the package makes use of the sandwich package for the methods. The gradients, hessian and scores (jacobian) are calculated using autodiff making use of the framework provided by the TMB package.

We can also calculate the moments of the distribution using the tsmoments method, or directly call the dskewness and dkurtosis functions. Note that the kurtosis reported is in excess of the Normal (3.0).

tsmoments(mod)
#>           mu        sigma     skewness     kurtosis 
#> -0.004745947  0.994585965 -1.059717793  1.899709892