Learn R Programming

NGSSEML (version 1.0)

Prediction: The h-step-ahead forecast for the observations

Description

The function Prediction implements the h-step-ahead forecast for the observations of SR and Poisson models.

Usage

Prediction(formula,data,na.action="na.omit",pz=NULL,nBreaks=NULL,
model="Poisson",StaPar=NULL,a0=0.01,b0=0.01,distl="PRED",
ci=0.95,samples=500,hh=1,Xtprev=NULL,method="MLE")

Arguments

formula

an object of class "formula" (or one that can be coerced to that class): a symbolic description of the model to be fitted.

data

a data frame containing the variables in the model. The variables are: - the time series of interest Yt (first column of the data frame). the explanatory time series to be inserted in the model. - Xt must be always specified as a matrix of order n by p (after Yt). - the explanatory time series to be inserted in the mean of volatility model. Zt must be always specified as a matrix of order n by p (after Xt). - a censoring indicator of the event (a vector), only for the PEM. If the model is the PEM, put the variable Event in the secon column of tha data frame after Yt, and he explanatory time series after the variable Event. The value 1 indicates failure.

na.action

a function which indicates what should happen when the data contain NAs. The default is set by the na.action setting of options, and is na.fail if that is unset. Optional argument.

pz

the number of the explanatory time series to be inserted in the mean of volatility model. Default: NULL. Optional argument.

nBreaks

the number of breaks used to build a vector with the interval limits, only for the PEM. Optional argument.

model

the chosen model for the observations. The options are: Poisson, SRGamma, and SRWeibull models.

StaPar

a numeric vector of initial values for the static parameters. Optional argument.

a0

the shape parameter of the initial Gamma distribution. Optional argument. Default: a0=0.01.

b0

the scale parameter of the initial Gamma distribution. Optional argument. Default: b0=0.01.

distl

the latent states distribution to be returned. Optional argument.

ci

the confidence level of the confidence interval for the states. Optional argument. Default: ci=0.95.

samples

the number of samples drawn from the predictive distributions for the observations, given a point of the static parameters (StaPar). Default: samples=500.

hh

the forecast horizon. Optional argument. Default: hh=1.

Xtprev

the future values of covariates, if there are covariates in the model. Optional argument.

method

the estimation method used, MLE or Bayesian.

Value

Mean

'Mean' is the mean of the one-step-ahead forecast distribution for the observations.

Median

'Median' is the median of the one-step-ahead forecast distribution for the observations.

Perc1

'Perc1' the the percentile of ((1-ci)/2) order of the one-step-ahead forecast distribution for the observations.

Perc2

'Perc2' is the percentile of (1-(1-ci)/2) order of the one-step-ahead forecast distribution for the observations.

%% ...

Details

Typical usages are

Prediction(Ytm~Trend+CosAnnual+SinAnnual+CosSemiAnnual+SinSemiAnnual,
data=data1,model=model,pz=NULL,StaPar=estopt,a0=a0,b0=b0,ci=ci,distl="PRED",
samples=500,hh=hh,Xtprev=Xtprev,method="MLE")

References

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.

Santos T. R., Gamerman, D., Franco, G. C. (2017). Reliability Analysis via Non-Gaussian State-Space Models. IEEE Transactions on Reliability, 66, 309-318.

See Also

LikeF SmoothingF

Examples

Run this code
# NOT RUN {
<!-- %% -->
# }
# NOT RUN {
################################################################################
##
##  SR Weibull MODEL: the SYS1 data
##
################################################################################
library(NGSSEML) 
#Classical:
data(sys1_data)
Ytm=sys1_data[,1]+0.00001
Xtm=as.matrix(sys1_data[,2])
hh=3
Xtprev=as.matrix(135+1:hh)
model="SRWeibull" 
#model="SRGamma"    
LabelParTheta=c("w","nu","Beta1")
StaPar=c(0.9,0.7,0.01)
#Fit:
fit=ngssm.mle(Ytm~Xtm,data=data.frame(Ytm,Xtm),
model=model,pz=NULL,StaPar=StaPar,a0=0.01,b0=0.01,ci=0.95)
estopt=c(0.99,0.75262104,0.02342691)
estopt=fit[[1]][1:3]
predpar=Prediction(Ytm~Xtm,data=data.frame(Ytm,Xtm),
model=model,StaPar=estopt,pz=NULL,a0=0.01,
b0=0.01,distl="FILTER",ci=0.95,samples=500,hh=hh,
Xtprev=Xtprev,method="MLE")

#library(NGSSEML)
#Bayesian:
#### Inputs: 
data(sys1_data)
Yt=sys1_data[,1]+0.00001
Xt=as.matrix(sys1_data[,2])  # Xt as matrix always!
hh=3
Xtprev=as.matrix(135+1:hh)
Zt="NULL"
model="SRWeibull"  
#model="SRGamma"  
LabelParTheta=c("w","nu","Beta1")
pointss=4    ### points
nsamplex=50 ## Multinomial sampling posterior
StaPar=c(0.9,0.7,0.01)
#Fit:
fitbayes=ngssm.bayes(Ytm~Xtm,data=data.frame(Ytm,Xtm),
model=model,pz=NULL,StaPar=StaPar,
prw=c(1,1),prnu=c(0.1,0.1),prbetamu=rep(0,1),prbetasigma=diag(100,1,1),
pointss=pointss,nsamplex=50,postplot=FALSE,contourplot=FALSE)
posts=fitbayes[[2]]
#Prediction:
set.seed(1000)
predpar=Prediction(Ytm~Xtm,data=data.frame(Ytm,Xtm),
model=model,pz=NULL,StaPar=posts,
a0=0.01,b0=0.01,distl="PRED",ci=0.95,samples=500,hh=hh,
Xtprev=Xtprev,method="Bayes")
predpar
 
# }

Run the code above in your browser using DataLab