# Dynamic Model Averaging in Economics and Finance with fDMA: A Package for R
## 4 Fundamental Functions
It is strongly suggested to execute graphics.off from grDevices before executing plot commands. Of course, the user should take care to save all other plots before executing this command, as they can be lost. But if graphics.off is not executed sometimes a legend might cover the important parts of the plot. Finally, for dma object some other useful methods are implemented. In particular, coef extracts the expected values of regression coefficients. fitted extracts the predicted values. predict can be used to estimate the predicted values basing on the already estimated expected values of regression coefficients, but for some arbitrary newdata, as well as, to estimate the predicted values basing on the already estimated expected values of regression coefficients in the last period, but also for some arbitrary newdata. residuals extracts the residuals from the model. rvi extracts relative variable importances, i.e., posterior inclusion probabilities given by Equation (15). Usually, in applications of DMA it was suggested to take \(\alpha=0.99\) and \(\lambda=0.99\). However, it is based on experimental ground; there is no theory indicating which values of forgetting factors should be taken [1]. Generally, they have some interpretation. For example, setting \(\lambda=0.99\) for monthly data, means that observations 3 months ago receive around 97% as much weight as the observation of the last month. For \(\lambda=0.90\) it would be around 73%. In other words, observations lagged \(i\) periods back are given \(\lambda^{i}\) weight. This is somehow similar to applying a rolling window regression with a window size of \((1-\lambda)^{-1}\). However, forgetting factors are responsible for controlling the degree of instability in coefficients. But rapidly changing coefficients can \"catch the noise\" instead of reasonably adapt to data, i.e., they can inflate estimation errors. Therefore, some researchers advise to compare the results based on different forgetting factors [150]. In this context, grid.DMA is useful. grid.DMA(y, x, grid.alpha, grid.lambda, initvar, W = NULL, initial.period = NULL, V.meth = NULL, kappa = NULL, gprob = NULL, omega = NULL, model = NULL, parallel.grid = NULL, m.prior = NULL, mods.incl = NULL, DOW = NULL, DOW.nmods = NULL, DOW.type = NULL, DOW.limit.mmods = NULL, forced.models = NULL, forbidden.models = NULL, forced.variables = NULL, bm = NULL, small.c = NULL)  
This function is just a wrapper for fDMA, so its arguments are used in the same way; except three of them:  
* grid.alpha is a numeric vector of different values of the forgetting parameter \(\alpha\) to be used,
* grid.lambda is a numeric vector of different values of the forgetting parameter \(\lambda\) to be used, or a list of numeric vectors for multiple lambda in one model,
* parallel.grid is optional. This logical indicates whether parallel computations of models with different forgetting factors should be used. By default parallel.grid = FALSE is used. The outcomes are an object of class grid.dma, i.e., a list of:  
* \[\pi_{0|0,k}=\pi p_{k}\cdot(1-\pi)^{m-p_{k}}\quad,\]0RMSE: matrix with RMSE (Root Mean Squared Error) for all estimated models,
* \[\pi_{0|0,k}=\pi p_{k}\cdot(1-\pi)^{m-p_{k}}\quad,\]1y.hat: fitted (forecasted) values,
* \[\pi_{0|0,k}=\pi p_{k}\cdot(1-\pi)^{m-p_{k}}\quad,\]2pred.dens. : predictive densities from each period,
* \[\pi_{0|0,k}=\pi p_{k}\cdot(1-\pi)^{m-p_{k}}\quad,\]3models: list of estimated tvp objects,
* $fq: matrix with RMSE and MAE of all estimated models. As previously, the outcomes can be easily presented with print.grid.tvp, summary.grid.tvp and plot.grid.tvp functions. The first one prints RMSE and MAE for all estimated models. The second one additionally finds the model minimizing RMSE and the model minimizing MAE.