dma | R Documentation |
Implemtent dynamic model averaging for continuous outcomes as described in Raftery, A.E., Karny, M., and Ettler, P. (2010). Online Prediction Under Model Uncertainty Via Dynamic Model Averaging: Application to a Cold Rolling Mill. Technometrics 52:52-66. Along with the values described below, plot() creates a plot of the posterior model probabilities over time and model-averaged fitted values and print() returns model matrix and posterior model probabilities. There are TT time points, K models, and d total covariates.
dma(x, y, models.which, lambda=0.99, gamma=0.99,
eps=.001/nrow(models.which), delay=0, initialperiod=200)
x |
TTxd matrix of system inputs |
y |
TT-vector of system outputs |
models.which |
Kxd matrix, with 1 row per model and 1 col per variable indicating whether that variable is in the model (the state theta is of dim (model.dim+1); the extra 1 for the intercept) |
lambda |
parameter forgetting factor |
gamma |
flatterning parameter for model updating |
eps |
regularization parameter for regularizing posterior model model probabilities away from zero |
delay |
When |
initialperiod |
length of initial period. Performance is summarized with and without the first initialperiod samples. |
yhat.bymodel |
TTxK matrix whose |
yhat.ma |
TT vector whose |
pmp |
TTxK matrix whose |
thetahat |
KxTTx(nvar+1) array whose |
Vtheta |
KxTTx(nvar+1) array whose |
thetahat.ma |
TTx(nvar+1) matrix whose |
Vtheta.ma |
TTx(nvar+1) matrix whose |
mse.bymodel |
MSE for each model |
mse.ma |
MSE of model-averaged prediction |
mseinitialperiod.bymodel |
MSE for each model excluding the first initialperiod samples |
mseinitialperiod.ma |
MSE of model averaging excluding the first initialperiod samples |
model.forget |
forgetting factor for the model switching matrix |
Adrian Raftery, Tyler H. McCormick
Raftery, A.E., Karny, M., and Ettler, P. (2010). Online Prediction Under Model Uncertainty Via Dynamic Model Averaging: Application to a Cold Rolling Mill. Technometrics 52:52-66.
#simulate some data to test
#first, static coefficients
coef<-c(1.8,3.4,-2,3,-2.8,3)
coefmat<-cbind(rep(coef[1],200),rep(coef[2],200),
rep(coef[3],200),rep(coef[4],200),
rep(coef[5],200),rep(coef[6],200))
#then, dynamic ones
coefmat<-cbind(coefmat,seq(1,2.45,length.out=nrow(coefmat)),
seq(-.75,-2.75,length.out=nrow(coefmat)),
c(rep(-1.5,nrow(coefmat)/2),rep(-.5,nrow(coefmat)/2)))
npar<-ncol(coefmat)-1
dat<-matrix(rnorm(200*(npar),0,1),200,(npar))
ydat<-rowSums((cbind(rep(1,nrow(dat)),dat))[1:100,]*coefmat[1:100,])
ydat<-c(ydat,rowSums((cbind(rep(1,nrow(dat)),dat)*coefmat)[-c(1:100),c(6:9)]))
mmat<-matrix(c(c(1,0,1,0,0,rep(1,(npar-7)),0,0),
c(rep(0,(npar-4)),rep(1,4)),rep(1,npar)),3,npar,byrow=TRUE)
dma.test<-dma(dat,ydat,mmat,lambda=.99,gamma=.99,initialperiod=20)
plot(dma.test)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.