LikeF {NGSSMEL} | R Documentation |
This function computes the marginal maximum likelihood function of the static parameters of the model.
LikeF(StaPar,Yt,Xt=NULL,model="Poisson",a0=0.01,b0=0.01)
StaPar |
is the static parameter vector |
Yt |
is the time series of interest |
Xt |
are the explanatory time series to be inserted in the model |
model |
is the chosen model for the observations |
a0 |
is the shape parameter of the initial Gamma distribution |
b0 |
is the scale parameter of the initial Gamma distribution |
llik |
This function returns of the value of the marginal likelihood function in the logarithmic scale. |
Thiago Rezende dos Santos
Gamerman, D., Santos, T. R., and Franco, G. C. (2013). A Non-Gaussian Family of State-Space Models with Exact Marginal Likelihood. Journal of Time Series Analysis, 34(6), 625-645.
Harvey, A. C., and Fernandes, C. (1989). Time series models for count or qualitative observations. Journal of Business and Economic Statistics, 7(4), 407-417.
########################################################## ## ## Poisson Example with Covariate Cosine ## ########################################################## data(Ytm) Yt=Ytm[,1] Ytm[,2] Xt=as.matrix(Ytm[,2]) StaPar=c(0.88,0.90) LikeF(StaPar,Yt,Xt=Xt,model="Poisson",a0=0.01,b0=0.01) resultsopt=optim(StaPar, hessian=TRUE,LikeF,lower=c(0.0001,-1000),upper=c(0.9999,1000), ,method="L-BFGS-B",Yt=Yt,Xt=Xt,model="Poisson", control = list(maxit = 30000, temp = 2000, trace = TRUE,REPORT = 500)) estopt=resultsopt$par estopt Hessianmatrixopt=-resultsopt$hessian Hessianmatrixopt MIFopt=-solve(Hessianmatrixopt) MIFopt linfwopt=estopt[1]-1.96*sqrt(MIFopt[1,1]) linfwopt lsupwopt=estopt[1]+1.96*sqrt(MIFopt[1,1]) lsupwopt linfbetaopt=estopt[2]-1.96*sqrt(MIFopt[2,2]) linfbetaopt lsupbetaopt=estopt[2]+1.96*sqrt(MIFopt[2,2]) lsupbetaopt # -1*log-lik: resultsopt$value # log-lik: -resultsopt$value set.seed(1000) MeanSmooth=SmoothingF(estopt,Yt=Yt,Xt=Xt,model="Poisson", a0=0.01,b0=0.01,samples=500,alpha=0.05) #MeanSmooth filpar=ForecastingF(estopt,Yt=Yt,Xt=Xt,model="Poisson", a0=0.01,b0=0.01) n1=length(Yt) ytm=matrix(0,n1,5) ytm[,1]=Yt ytm[,2]=MeanSmooth$Mean ytm[,3]=filpar[1,]/ filpar[2,] ytm[,4]=MeanSmooth$Perc1 ytm[,5]=MeanSmooth$Perc2 ts.plot(ytm,xlab="t",ylab="Y_t",lty=c(1,2,3,2,2), col=c("black","blue","red","blue","blue")) legend("topright", c("Time Series","Smoothed Mean", "Prediction", "Smoothed Lower 95 CI", "Smoothed Upper 95 CI"),lty=c(1,2,3,2,2), col=c("black","blue","red","blue","blue"), cex=0.68, bty="n", pt.cex = 1) ########################################################## ## ## Example PETR3 ## ########################################################## data(Rt) StStaPar=c(0.9818846,1.2367185) Yt=Rt resultsopt=optim(StStaPar, hessian=TRUE,LikeF, lower=c(0.0001,0.0001),upper=c(0.9999,1000), ,method="L-BFGS-B",Yt,Xt=NULL,a0=0.01,b0=0.01, model="GED",control = list(maxit = 30000, temp = 2000, trace = TRUE,REPORT = 500)) estopt=resultsopt$par # Point Estimates: estopt Hessianmatrixopt=-resultsopt$hessian #Hessian Matrix Hessianmatrixopt MIFopt=-solve(Hessianmatrixopt) #MIF MIFopt linfwopt=estopt[1]-1.96*sqrt(MIFopt[1,1]) # CI Asymptotic for w: linfwopt lsupwopt=estopt[1]+1.96*sqrt(MIFopt[1,1]) lsupwopt linfropt=estopt[2]-1.96*sqrt(MIFopt[2,2]) # CI Asymptotic for r: linfropt lsupropt=estopt[2]+1.96*sqrt(MIFopt[2,2]) lsupropt # -1*log-lik: resultsopt$value # log-lik: -resultsopt$value #Smoothing: set.seed(1000) MeanSmooth=SmoothingF(estopt,Yt=Yt,Xt=NULL,model="GED", a0=0.01,b0=0.01,samples=500,alpha=0.05) #MeanSmooth filpar=ForecastingF(estopt,Yt=Yt,Xt=NULL,model="GED", a0=0.01,b0=0.01) n1=length(Yt) ytm=matrix(0,n1,5) ytm[,1]=(Yt^2) ytm[,2]=(MeanSmooth$Mean^(-1/estopt[2])) ytm[,3]=((filpar[1,]/ filpar[2,])^(-1/estopt[2])) ytm[,4]=(MeanSmooth$Perc1^(-1/estopt[2])) ytm[,5]=(MeanSmooth$Perc2^(-1/estopt[2])) ts.plot(ytm,xlab="t",ylab="Y_t",lty=c(1,2,3,2,2), col=c("black","blue","red","blue","blue")) legend("topleft", c("Square of Returns", "Smoothed estimate of the square root of the stochastic volatility", "Prediction one-step-ahead of the square root of the stochastic volatility", "Smoothed Lower 95 percent CI", "Smoothed Upper 95 percent CI"),lty=c(1,2,3,2,2), col=c("black","blue","red","blue","blue"), cex=0.68, bty="n", pt.cex = 1)