Description Usage Arguments Value References Examples
Predict the future values of an fitted carx
object. If the model has non-null covariate x
other than the constant mean, the new observations in x
must be supplied via newxreg
. The model prediction is done in a similar way as in fitted.carx
by identifying the latest p consecutive observed responses in the data used to estimate model, then compute the mean of the conditional distribution of the future values given the information since the latest p consecutive observed values and the supplied new covariate values. For more details, see Wang and Chan (2017).
1 2 3 4 |
object |
a fitted |
newxreg |
the new observations for the coverates |
n.ahead |
the number of steps ahead to predict, default = 1. |
CI.level |
the CI.level to construct the confidence interval, default = 0.95. |
nRep |
the number of replications to be performed in the bootstrap for prediction confidence intervals when censoring exists in the last |
na.action |
how should |
useSimulatedResidual |
if True, the innovation sequence will be sampled from the simulated residuals, otherwise, they will be sampled from normal distribution with mean 0 and standard deviation |
... |
not used. |
A list consisting of fit
, se.fit
, and ci
representing the predictions,
standard errors of predictions, and confidence intervals respectively.
Wang C, Chan KS (2017). "Quasi-likelihood estimation of a censored autoregressive model with exogenous variables." Journal of the American Statistical Association. 2017 Mar 20(just-accepted).
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 45 46 47 48 49 50 51 52 53 54 55 56 | #This is the function to run a simulation study about the empirical coverage rate of
#the predictive confidence intervals,
runSimPredCR <- function(nRep=200,nObs=200,n.ahead=10,
saveRslt=FALSE,saveDir='./testPredictCR',
seed=NULL)
{
if(!is.null(seed))
set.seed(seed)
crMat = matrix(nrow=n.ahead,ncol=nRep)
if(saveRslt)
{
dir.create(saveDir,showWarnings=FALSE,recursive=TRUE)
}
replication = list()
simSingle <- function(iRep)
{
message(sprintf("iRep: %04d",iRep))
sdata = carxSim(nObs=nObs+n.ahead)
trainingData = sdata[1:nObs,]
testData = sdata[-(1:nObs),]
mdl = carx(y~X1+X2-1,data=trainingData,p=2)
newxreg = testData[,c('X1','X2')]
predVal = predict(mdl,newxreg=newxreg,n.ahead=n.ahead)
crInd = (predVal$ci[,1] <= testData$y) & (predVal$ci[,2] >= testData$y)
crMat[,iRep] = crInd
list(trainingData=trainingData,
testData=testData,
fitted=mdl,
predVal = predVal,
crInd= crInd)
}
replication = lapply(1:nRep,simSingle)
crMat = sapply(replication,FUN=function(x){x$crInd})
print(crMat)
crPred = apply(crMat,1,mean)
message("empirical coverage rate:")
print(crPred)
if(saveRslt)
{
save(replication,file=paste0(saveDir,'/replication.RData'))
save(crMat,file=paste0(saveDir,'/crMat.RData'))
save(crPred,file=paste0(saveDir,'/crPred.RData'))
}
list(replication=replication,crMat=crMat,meanCR=crPred)
}
#note that nRep=2 is for illustration only, for more stable result, use nRep>=500.
simPredCR = runSimPredCR(nRep=2,nObs=100)
## Not run:
# for more stable simulation result, run with nRep = 500.
simPredCR = runSimPredCR(nRep=500,nObs=100)
message("Empirical coverage rate:")
print(simPredCR$meanCR)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.