sgtmle: Maximum Likelihood Estimation with the Skewed Generalized T...

Description Usage Arguments Details Value Author(s) References See Also Examples

Description

This function allows data to be fit to the skewed generalized t distribution using maximum likelihood estimation. This function uses the maxLik package to perform its estimations.

Usage

1
2
3
4
5
6
7
sgt.mle(X.f, mu.f = mu ~ mu, sigma.f = sigma ~ sigma, 
lambda.f = lambda ~ lambda, p.f = p ~ p, q.f = q ~ q, 
data = parent.frame(), start, subset, 
method = c("Nelder-Mead", "BFGS"), itnmax = NULL,
hessian.method="Richardson", 
gradient.method="Richardson",
mean.cent = TRUE, var.adj = TRUE, ...)

Arguments

X.f

A formula specifying the data, or the function of the data with parameters, that should be used in the maximisation procedure. X should be on the left-hand side and the right-hand side should be the data or function of the data that should be used.

mu.f, sigma.f, lambda.f, p.f, q.f

formulas including variables and parameters that specify the functional form of the parameters in the skewed generalized t log-likelihood function. mu, sigma, lambda, p, and q should be on the left-hand side of these formulas respectively.

data

an optional data frame in which to evaluate the variables in formula and weights. Can also be a list or an environment.

start

a named list or named numeric vector of starting estimates for every parameter.

subset

an optional vector specifying a subset of observations to be used in the fitting process.

method

A list of the optimization methods to be used, which is passed directly to the optimx function in the optimx package. See ?optimx for a list of methods that can be used. Note that the method that achieves the highest log-likelihood value is the method that is printed and reported. The default method is to use both "Nelder-Mead" and the "BFGS" methods.

itnmax

If provided as a vector of the same length as method, gives the maximum number of iterations or function values for the corresponding method. If a single number is provided, this will be used for all methods.

hessian.method

method used to calculate the hessian of the final estimates, either "Richardson" or "complex". This method is passed to the hessian function in the numDeriv package. See ?hessian for details.

gradient.method

method used to calculate the gradient of the final estimates, either "Richardson", "simple", or "complex". This method is passed to the grad function in the numDeriv package. See ?grad for details.

mean.cent, var.adj

arguments passed to the skewed generalized t distribution function (see ?dsgt).

...

further arguments that are passed to the control argument in the optimx function in the optimx package. See ?optimx for a list of arguments that can be used in the control argument.

Details

The parameter names are taken from start. If there is a name of a parameter or some data found on the right-hand side of one of the formulas but not found in data and not found in start, then an error is given.

This function simply uses the optimx function in the optimx package to maximize the skewed generalized t distribution log-likelihood function. It takes the method that returned the highest log-likelihood, and saves these results as the final estimates.

Value

sgt.mle returns a list of class "sgtest". A list of class "sgtest" has the following components:

maximum

log-likelihood value of estimates (the last calculated value if not converged) of the method that achieved the greatest log-likelihood value.

estimate

estimated parameter value with the method that achieved the greatest log-likelihood value.

convcode

convcode returned from the optimx function in the optimx package of the method that achieved the greatest log-likelihood value. See ?optimx for the different convcode values.

niter

The amount of iterations that the method which achieved the the greatest log-likelihood value used to reach its estimate.

best.method.used

name of the method that achieved the greatest log-likelihood value.

optimx

A data.frame of class "optimx" that contains the results of the optimx maximization for every method (not just the method that achieved the highest log-likelihood value). See ?optimx for details.

gradient

vector, gradient value of the estimates with the method that achieved the greatest log-likelihood value.

hessian

matrix, hessian of the estimates with the method that achieved the greatest log-likelihood value.

varcov

variance/covariance matrix of the maximimum likelihood estimates

std.error

standard errors of the estimates

Author(s)

Carter Davis, carterdavis@byu.edu

References

Davis, Carter, James McDonald, and Daniel Walton (2015). "A Generalized Regression Specification using the Skewed Generalized T Distribution" working paper.

See Also

The optimx package and its documentation. The sgt.mle simply uses its functions to maximize the skewed generalized t log-likelihood. Also, the sgt.mle function uses the numDeriv package to compute the final hessian and gradients of the estimates.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# SINGLE VARIABLE ESTIMATION:
### generate random variable
set.seed(7900)
n = 1000
x = rsgt(n, mu = 2, sigma = 2, lambda = -0.25, p = 1.7, q = 7)

### Get starting values and estimate the parameter values
start = list(mu = 0, sigma = 1, lambda = 0, p = 2, q = 10)
result = sgt.mle(X.f = ~ x, start = start, method = "nlminb")
print(result)
print(summary(result))

# REGRESSION MODEL ESTIMATION:
### Generate Random Data 
set.seed(1253)
n = 1000
x1 = rnorm(n)
x2 = runif(n)
y = 1 + 2*x1 + 3*x2 + rnorm(n)
data = as.data.frame(cbind(y, x1, x2))

### Estimate Linear Regression Model
reg = lm(y ~ x1 + x2, data = data)
coef = as.numeric(reg$coefficients)
rmse = summary(reg)$sigma
start = c(b0 = coef[1], b1 = coef[2], b2 = coef[3], 
g0 = log(rmse)+log(2)/2, g1 = 0, g2 = 0, d0 = 0, 
d1 = 0, d2 = 0, p = 2, q = 10)

### Set up Model
X.f = X ~ y - (b0 + b1*x1 + b2*x2)
mu.f = mu ~ 0
sigma.f = sigma ~ exp(g0 + g1*x1 + g2*x2)
lambda.f = lambda ~ (exp(d0 + d1*x1 + d2*x2)-1)/(exp(d0 + d1*x1 + d2*x2)+1)

### Estimate Regression with a skewed generalized t error term
### This estimates the regression model from the Davis, 
### McDonald, and Walton (2015) paper cited in the references section
### q is in reality infinite since the error term is normal
result = sgt.mle(X.f = X.f, mu.f = mu.f, sigma.f = sigma.f, 
lambda.f = lambda.f, data = data, start = start, 
var.adj = FALSE, method = "nlm")
print(result)
print(summary(result))

Example output

Loading required package: optimx
Loading required package: numDeriv
Skewed Generalized T MLE Fit
Best Result with nlminb Maximization
Convergence Code 0: Successful Convergence
Iterations: 24, Log-Likelihood: -2076.966 
Estimate(s):
     mu   sigma  lambda       p       q 
 1.9735  2.0075 -0.2761  1.7199  7.7856 
Skewed Generalized T MLE Fit
Best Result with nlminb Maximization
Convergence Code 0: Successful Convergence
Iterations: 24, Log-Likelihood: -2076.966 

          Est. Std. Err.       z  P>|z|    
mu      1.9735    0.0634 31.1041 0.0000 ***
sigma   2.0075    0.0594 33.7782 0.0000 ***
lambda -0.2761    0.0410 -6.7376 0.0000 ***
p       1.7199    0.2673  6.4333 0.0000 ***
q       7.7856    7.5662  1.0290 0.3035    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Skewed Generalized T MLE Fit
Best Result with nlm Maximization
Convergence Code 5: Maximization Failure
Iterations: 89, Log-Likelihood: -1387.566 
Estimate(s):
         b0          b1          b2          g0          g1          g2 
     1.0404      1.9982      2.9713      0.2631     -0.0312      0.0246 
         d0          d1          d2           p           q 
    -0.1315      0.0773      0.1402      1.8593 109515.9925 
Skewed Generalized T MLE Fit
Best Result with nlm Maximization
Convergence Code 5: Maximization Failure
Iterations: 89, Log-Likelihood: -1387.566 

          Est.    Std. Err.       z  P>|z|    
b0      1.0404       0.0624 16.6736 0.0000 ***
b1      1.9982       0.0303 66.0191 0.0000 ***
b2      2.9713       0.1064 27.9316 0.0000 ***
g0      0.2631       0.0632  4.1652 0.0000 ***
g1     -0.0312       0.0236 -1.3185 0.1873    
g2      0.0246       0.0817  0.3008 0.7636    
d0     -0.1315       0.1811 -0.7262 0.4677    
d1      0.0773       0.0852  0.9076 0.3641    
d2      0.1402       0.2890  0.4852 0.6275    
p       1.8593       0.1367 13.6008 0.0000 ***
q  109515.9925 9162008.0441  0.0120 0.9905    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

sgt documentation built on May 2, 2019, 8:27 a.m.