############################################################# ## ## R functions for the non-central skew t distribution ## ############################################################# ## R function to compute the PDF of the non-central skew t distribution: pdf.t = function(t, mu,sigma, alpha,r) { g = function (u){ w = (t*sqrt(u/r)-mu)/sigma return(dchisq(u,df = r)* dnorm(w)*pnorm(alpha*w)*sqrt(u/r)) } I = integrate(g ,lower = 0, upper = Inf,stop.on.error = FALSE)\$value c = 2/sigma return(c*I) } ## This chunk can be used to compute -log likelihood as a function of the parameter vector (mu, sigma, alpha, r) ## After reading the data and stroing it under the name data ## Set m = the length of the data vector LL = function (x ) { mu = x[1] ; sigma = x[2]; alpha=x[3]; r=x[4] sum = 0 for (i in 1:m){ sum = sum + log(pdf.t(data[i], mu,sigma,alpha, r ))} return(-sum) } LL(c( .78, 1.170, 1, 1)) ## numerical example ### Use a built in routine to maximize the likelihood function (equivalently minimize LL) fit1 = optim ( c(.6,1,2,3), LL) par = fit1\$par mu = par[1]; sigma = par[2] ; alpha = par[3]; r = par[4]