| Type: | Package |
| Title: | Dynamic Model Averaging with Grid Search |
| Version: | 1.5-5 |
| Maintainer: | Leopoldo Catania <leopoldo.catania@econ.au.dk> |
| Description: | Perform dynamic model averaging with grid search as in Dangl and Halling (2012) <doi:10.1016/j.jfineco.2012.04.003> using parallel computing. |
| SystemRequirements: | Requires the OpenMP library for parallel computing. If the OpenMP library is not available, the code is executed sequentially and a warning is printed. |
| License: | GPL-2 | GPL-3 [expanded from: GPL (≥ 2)] |
| LazyData: | TRUE |
| Imports: | Rcpp (≥ 0.12.5) |
| LinkingTo: | Rcpp,RcppArmadillo |
| Depends: | zoo,xts,methods,parallel |
| NeedsCompilation: | yes |
| Author: | Leopoldo Catania |
| Packaged: | 2026-10-19 08:38:22 UTC; au588008 |
| Repository: | CRAN |
| Date/Publication: | 2026-10-19 09:50:02 UTC |
Dynamic Model Averaging with Modifications
Description
Perform Dynamic Model Averaging with modifications introduced in Dangl and Halling (2012) using parallel computing.
Details
| Package: | eDMA |
| Type: | Package |
| Version: | 1.5-4 |
| Date: | 2018-27-08 |
| License: | GPL (>= 2) |
Author(s)
Leopoldo Catania
Maintainer: Leopoldo Catania <leopoldo.catania@econ.au.dk>
References
Raftery, Adrian E., Miroslav Karny, and Pavel Ettler. "Online prediction under model uncertainty via dynamic model averaging: Application to a cold rolling mill." Technometrics 52.1 (2010): 52-66.
Catania, Leopoldo, and Nima Nonejad (2018). "Dynamic Model Averaging for Practitioners in Economics and Finance: The eDMA Package." Journal of Statistical Software, 84(11), 1-39. doi:10.18637/jss.v084.i11.
Dangl, Thomas, and Michael Halling. "Predictive regressions with time-varying coefficients." Journal of Financial Economics 106.1 (2012): 157-181.
Raftery, Adrian E., David Madigan, and Jennifer A. Hoeting. "Bayesian model averaging for linear regression models." Journal of the American Statistical Association 92.437 (1997): 179-191.
Harrison, Jeff, and Mike West. Bayesian Forecasting & Dynamic Models. Springer, 1999.
See Also
Examples
library(eDMA)
## load data
data("USData")
## do DMA, keep the first three predictors fixed and the intercept
Fit <- DMA(GDPDEF ~ Lag(GDPDEF, 1) + Lag(GDPDEF, 2) + Lag(GDPDEF, 3) +
Lag(ROUTP, 1) + Lag(UNEMP, 1), data = USData, vDelta = c(0.9,0.95,0.99),
vKeep = c(1, 2, 3, 4))
Backtest measures for Dynamic Model Averaging and comparison with Dynamic Model Selection
Description
Backtest measures for Dynamic Model Averaging and comparison with Dynamic Model Selection. This function evaluates the out of sample performance of DMA and compare it with DMS.
Usage
BacktestDMA(object, iBurnPeriod = NULL)
Arguments
object |
an object of the class DMA-class, created using the function DMA. |
iBurnPeriod |
An integer between zero and one less than the sample size indicating the length of the burn-in period. By default |
Details
The function returns a matrix with Mean Squared Error (MSE), Mean Absolute Error (MAD) and summed predictive log likelihood for DMA and DMS using the predictions during the out-of-sample period.
Value
An object of the class matrix.
Author(s)
Leopoldo Catania
Examples
library(eDMA)
## load data
data("USData")
## do DMA, keep the first three predictors fixed and the intercept
Fit <- DMA(GDPDEF ~ Lag(GDPDEF, 1) + Lag(GDPDEF, 2) + Lag(GDPDEF, 3) +
Lag(ROUTP, 1) + Lag(UNEMP, 1), data = USData, vDelta = c(0.9, 0.95, 0.99),
vKeep = c(1, 2, 3))
BacktestDMA(Fit, iBurnPeriod = 32)
Perform Dynamic Model Averaging
Description
Implements the Dynamic Model Averaging procedure with the possibility of also performing averaging over a grid of forgetting factor values
Usage
DMA(formula, data = NULL, vDelta = c(0.9, 0.95, 0.99), dAlpha = 0.99,
vKeep = NULL, bZellnerPrior = FALSE, dG = 100, bParallelize = TRUE,
iCores = NULL, dBeta = 1.0, dS0 = 1.0, dN0 = 2.0)
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 |
an object of the class data.frame, (or object coercible by as.data.frame to a data frame) containing the variables in the model. It can also be an object of the classes |
vDelta |
D x 1 numeric vector representing the the grid of values of |
dAlpha |
numeric variable representing |
vKeep |
|
bZellnerPrior |
Boolean variable indicating whether the Zellner prior should be used on the coefficients at time t=0. Default = |
dG |
numeric variable equal to 100 by default. If |
bParallelize |
Boolean variable indicating whether to use multiple processors to speed up the computations. By default |
iCores |
integer indicating the number of cores to use if |
dBeta |
numeric scalar in (0, 1] indicating the forgetting factor for the measurement variance, see Prado and West (2010) pp. 132 and Beckmann and Schussler (2014). |
dS0 |
Positive initial observation scale, fixed before observing the data. Defaults to 1. |
dN0 |
Positive initial degrees-of-freedom accumulator. Defaults to 2. |
Details
All discounts must lie in (0, 1]. The model space consists of nonempty
subsets of the columns of the model matrix, including factor expansions and
formula transformations. Indices in vKeep refer to these columns;
"KS" includes all columns. At most 20 optional columns are allowed.
An estimated working-memory limit of 1 GiB is checked before allocating
model/delta state arrays. Formula offsets are not supported.
At each step both the conditional model probabilities and delta probabilities
are raised to dAlpha and separately normalized. These prediction
probabilities are used consistently for point forecasts, predictive densities,
and all predictive variance components. After observing the response, Bayes'
rule updates both probability layers using the same conditional predictive
likelihoods. Filtered coefficients use these posterior probabilities, with
absent coefficients represented by zeros. Normalization is performed in log
space. This coherent discounted prediction convention is an explicit change
from the lagged-weight forecast formulas in the published paper; see NEWS.
The coefficient prior has mean zero and covariance dG * I unless
bZellnerPrior = TRUE. The first row is processed through the same
prediction and update equations as subsequent rows, with no coefficient
covariance inflation before that first observation. Observation scale starts
at dS0 and the degrees-of-freedom accumulator starts at dN0.
Predictive Student-t densities retain the package's convention
\nu_t = \beta n_{t-1}+1. The scale is
Q_t = S_{t-1}+x_t'R_t x_t. Observation and coefficient contributions
to predictive variance multiply their scale contributions by
\nu_t/(\nu_t-2) when \nu_t>2; otherwise the predictive
variance is infinite. Between-model and between-delta contributions use
prediction means and prediction probabilities. The coefficient covariance
update remains the plug-in Kalman recursion, without a subsequent scale-ratio
rescaling; it is not an exact Normal–inverse-gamma filter.
The Zellner covariance uses least squares on all supplied observed responses,
with residual sum of squares divided by T-1, and is reused across deltas.
A terminal forecast-only row is excluded. A residual-scale floor of
dS0 * 1e-12 prevents a zero prior covariance for an exact fit.
Rank-deficient or ill-conditioned designs are rejected. Because this prior
uses the complete observed sample, historical forecasts with the Zellner
option are not real-time forecasts. Use the fixed prior for causal filtering.
DMS forecasts retain the nested selection rule: select the largest prediction probability for delta, then the largest conditional model probability within that delta. The model-size and maximum/top-ten-percent probability diagnostics instead describe the marginal posterior distribution over models.
Rows with incomplete data are omitted, except that a final missing response with complete predictors is retained for prediction only. Nonfinite observed data are rejected. Original time indexes are preserved for ts, zoo and xts inputs. No artificial response is imputed.
There might be situations when the practitioner desires to predict T+1 conditional on observation till time T in a true out-of-sample fashion. In such circumstances the user can substitute the future value of the dependent variable with an NA. This way, the code treats the last observation as missing and does not perform backtesting or updating of the coefficients. However, the filter provides us with the necessary quantities to perform prediction. The predicted value \hat{y_{T+1}} = E[y_T+1 | F_T] as well as the predicted variance decomposition can then be extracted using the getLastForecast method. The other quantities that can be extracted, for example via the as.data.frame method, will ignore the presence of the last NA and report results only for the first T observations.
See Catania and Nonejad (2016) for further details.
Value
An object of the class DMA, see DMA-class.
Author(s)
Leopoldo Catania
References
Beckmann, J., & Schussler, R. (2014). Forecasting Equity Premia using Bayesian Dynamic Model Averaging (No. 2914). Center for Quantitative Economics (CQE), University of Muenster.
Dangl, T., & Halling, M. (2012). Predictive regressions with time–varying coefficients. Journal of Financial Economics, 106(1), 157–181. doi:10.1016/j.jfineco.2012.04.003.
Catania, Leopoldo, and Nima Nonejad (2018). "Dynamic Model Averaging for Practitioners in Economics and Finance: The eDMA Package." Journal of Statistical Software, 84(11), 1-39. doi:10.18637/jss.v084.i11.
Paye, B.S. (2012). 'Deja vol': Predictive Regressions for Aggregate Stock Market Volatility Using Macroeconomic Variables.Journal of Financial Economics, 106(3), 527-546. ISSN 0304-405X. doi:10.1016/j.jfineco.2012.06.005. URL http://www.sciencedirect.com/science/article/pii/S0304405X12001316.
Prado, R., & West, M. (2010). Time series: modeling, computation, and inference. CRC Press.
Examples
# Code chunk of Catania and Nonejad (2016) Fast Dynamic Model Averaging
# for Practitioners in Economics and Finance: The eDMA Package
library(eDMA)
## load data
data("USData")
## do DMA, keep the first three predictors fixed and the intercept
Fit <- DMA(GDPDEF ~ Lag(GDPDEF, 1) + Lag(GDPDEF, 2) + Lag(GDPDEF, 3) +
Lag(ROUTP, 1) + Lag(UNEMP, 1), data = USData, vDelta = c(0.9,0.95,0.99),
vKeep = c(1, 2, 3, 4))
Fit
class: Class for the DMA class
Description
Class for the DMA estimate.
Objects from the Class
Objects are created by DMA().
Slots
model:Object of class
"list"Contains information about the DMA specification.data:Object of class
"list"Contains the data given to theDMAfunction.Est:Object of class
"list"Contains the estimated quantities.
Methods
- as.data.frame
signature(object = "DMA"): Extracts estimated quantities, (see note).- plot
signature(x = "DMA", y = "missing"): Plots estimated quantities.- show
signature(object = "DMA")
.
- summary
signature(object = "DMA"): Print a summary of the estimated model. This method accepts the additional argumentiBurnPeriodcorresponding at the length of the burn-in period. By defaultiBurnPeriod = NULL, i.e. all the sample is used.- coef
signature(object = "DMA"): Extract the filtered regressor coefficients. This method accepts the additional argumentiBurnPeriodcorresponding at the length of the burn-in period. By defaultiBurnPeriod = NULL, i.e. all the sample is used.- residuals
signature(object = "DMA"): Extract the residuals of the model. This method accepts the additional argumentiBurnPeriodcorresponding at the length of the burn-in period. By defaultiBurnPeriod = NULL, i.e. all the sample is used. The additional Boolean argumentstandardizecontrols if standardize residuals should be returned. By defaultstandardize = FALSE. The additional argumenttypepermits to choose between residuals evaluated using DMA or DMS. By defaulttype = "DMA".- inclusion.prob
signature(object = "DMA"): Extract the inclusion probabilities of the regressors. This method accepts the additional argumentiBurnPeriodcorresponding at the length of the burn-in period. By defaultiBurnPeriod = NULL, i.e. all the sample is used.- pred.like
signature(object = "DMA"): Extract the predictive log-likelihood series. This method accepts the additional argumentiBurnPeriodcorresponding at the length of the burn-in period. By defaultiBurnPeriod = NULL, i.e. all the sample is used. The additional argumenttypepermits to choose between predictive likelihood evaluated using DMA or DMS. By defaulttype = "DMA".- getLastForecast
signature(object = "DMA"): If the last observation of the dependent variable wasNA, i.e. the practitioner desidered to predictY_{T+1}having a sample of lengthT(without backtesting the result), this method can be used to extract the predicted value\hat{y_T+1} = E[y_{T+1} | F_T]as well as the predicted variance decomposition using the prediction weights and Student-t variance convention documented inDMA.
Note
For compatibility, as.data.frame() returns a matrix for ordinary data,
an xts object for Date/POSIX indexes, or a zoo object for other time indexes.
It does not return a base data frame. Dimensions are preserved for a single
column or a single retained observation. Burn-in must be an integer from
zero to one less than the observed sample size. All rows, including the
first, now contain defined prediction and filtering results.
Residual standardization divides by the sample standard deviation over the
retained residuals; it is not conditional-volatility standardization.
type must be "DMA" or "DMS". Plotting preserves the
current graphics device and restores its parameters. In noninteractive use,
the default plot is the point forecast. Nonfinite variances are omitted from
plot lines. getLastForecast() returns PointForecast,
VarianceDecomposition and ForecastDate (NULL without an index),
and gives an informative error if there is no forecast-only row.
Additional extraction names are mpmt_pred for prediction probabilities
over delta, mLpdf for conditional predictive log likelihoods,
vdf for predictive degrees of freedom, and mcovhat for diagonal
mixture variances of the plug-in filtered coefficient distributions, including
between-component mean dispersion and zero coefficients in absent models.
The latter are not exact conjugate Student-t posterior variances.
Predictive variance components refer to the same distribution as the forecast
and are calculated before observing the current response. They include the
Student-t variance multiplier; total variance can be infinite.
DMS point forecasts use nested delta/model selection. The marginal posterior
model diagnostics need not identify that same model. The top-ten-percent
statistic sums the largest \lceil 0.1M\rceil marginal probabilities.
The as.data.frame() method permits to extract several estimated quantities. It accepts the two additional arguments: which with possible values:
mincpmt: Posterior inclusion probabilities of the predictors.vsize: Expected number of predictors (average size).mtheta: Filtered estimates of the regression coefficients.mpmt: Posterior probability of the degree of instability.vyhat: Point forecasts.vLpdfhat: Predictive log-likelihood.vdeltahat: Posterior weighted average of delta.mvdec: representing the y_t variance decomposition. The function returns a T x 5 matrix whose columns contains the variables.vtotal: total variance.vobs: Observational variance.vcoeff: Variance due to errors in the estimation of the coefficients.vmod: Variance due to model uncertainty.vtvp: Variance due to uncertainty with respect to the choice of the degrees of time–variation in the regression coefficients.
-
vhighmp_DMS: Highest posterior model probability. -
vhighmpTop01_DMS: Sum of the 10% highest posterior model probabilities.
and iBurnPeriod which is an integer indicating the length of the burn-in period. For instance, if iBurnPeriod = 50 the first 50 observations are removed from the output. By default iBurnPeriod = NULL meaning that all the observations are returned.
Author(s)
Leopoldo Catania
References
Catania, Leopoldo, and Nima Nonejad (2018). "Dynamic Model Averaging for Practitioners in Economics and Finance: The eDMA Package." Journal of Statistical Software, 84(11), 1-39. doi:10.18637/jss.v084.i11.
Lag a vector or a matrix of observations
Description
Lag a vector or a matrix of observations by iK periods.
Usage
Lag(mY, iK)
Arguments
mY |
a vector or a matrix of observations. |
iK |
An integer indicating the number of lag. |
Details
The lag must be a nonnegative integer. Zero returns the original input; a lag at least as large as the number of observations returns only missing values. Empty vectors and matrices are supported, and names and dimensions are preserved.
The function returns a numeric vector or a matrix depending on the class of mY. The dimension of the object is preserved and NA's are introduced for the missing values.
Value
An object of the class numeric or matrix.
Author(s)
Leopoldo Catania
Examples
# Code chunk of Catania and Nonejad (2016) Dynamic Model Averaging
# for Practitioners in Economics and Finance: The eDMA Package
library(eDMA)
## load data
data("USData")
UDData_lagged <- Lag(USData, 1)
Build the power set of the values {0,1,2,...,iK-1}.
Description
Build the power set of the values {0,1,2,...,iK-1}.
Usage
PowerSet(iK)
Arguments
iK |
|
Details
The function returns a list of numeric vectors with the indices representing all the 2^iK subsets.
The empty subset {} is represented by the numeric(0) vector.
Value
An object of the class list.
Author(s)
Leopoldo Catania
Examples
library(eDMA)
PowerSet(5)
data: Simulated data from DLM of West and Harrison (1999).
Description
This is the simulated dataset used in Section 4.1 of Catania and Nonejad (2016).
Usage
data(USData)
Format
A matrix object containing 500 x 6 simulated observations.
References
Catania, Leopoldo, and Nima Nonejad (2018). "Dynamic Model Averaging for Practitioners in Economics and Finance: The eDMA Package." Journal of Statistical Software, 84(11), 1-39. doi:10.18637/jss.v084.i11.
West, Mike. Bayesian forecasting. John Wiley & Sons, Inc., 1999.
Examples
#the data set has been generated as:
set.seed(7892)
iT <- 500
iK <- 3
dV <- 0.1
mW <- diag(iK + 1) * 0.01
dPhi <- 1
vBeta0 <- rep(0, iK + 1)
mX <- cbind(1, matrix(rnorm(iT * (iK)), iT, iK))
lOut <- SimulateDLM(iT, mX, vBeta0, mW, dV, dPhi)
vY <- lOut$vY
mX <- mX[, -1]
iK_Add <- 2
mX_add <- matrix(rnorm(iT * iK_Add), iT, iK_Add)
SimData <- cbind(y = vY, mX, mX_add)
colnames(SimData) <- c("y", paste("x", 2:(iK + iK_Add + 1), sep = ""))
Simulate from DLM of West and Harrison (1999).
Description
Simulate from DLM of West and Harrison (1999), as in Section 2 of Catania and Nonejad (2016).
Usage
SimulateDLM(iT, mX, vBeta0, mW, dV, dPhi)
Arguments
iT |
|
mX |
|
vBeta0 |
|
mW |
|
dV |
|
dPhi |
|
Details
The function returns a list of two elements: vY and mBeta. vY is a iT x 1 numeric vector of simulated dependent variables. mBeta is a matrix of dimension ncol(mX) x iT of regressor coefficients.
Value
An object of the class list.
Author(s)
Leopoldo Catania
References
Catania, Leopoldo, and Nima Nonejad (2018). "Dynamic Model Averaging for Practitioners in Economics and Finance: The eDMA Package." Journal of Statistical Software, 84(11), 1-39. doi:10.18637/jss.v084.i11.
West, Mike. Bayesian forecasting. John Wiley & Sons, Inc., 1999.
Examples
set.seed(7892)
iT <- 500
iK <- 3
dV <- 0.1
mW <- diag(iK + 1) * 0.01
dPhi <- 1
vBeta0 <- rep(0, iK + 1)
mX <- cbind(1, matrix(rnorm(iT * (iK)), iT, iK))
lOut <- SimulateDLM(iT, mX, vBeta0, mW, dV, dPhi)
vY <- lOut$vY
data: Quarterly US inflation and associated predictors
Description
This is the dataset used in Groen et al. (2013) and is downloadable from http://www.tandfonline.com/doi/suppl/10.1080/07350015.2012.727718.
The variables are:
GDPDEF : Quarterly log changes in the Gross Domestic Product implicit price deflator.
ROUTP : Real GDP in volume terms.
RCONS : Real durable personal consumption expenditures in volume terms
RINVR : Real residential investment in volume terms
PIMP : Import deflator
UNEMP : Unemployment ratio
NFPR : Non-farm payrolls data on employment
HSTS : Housing starts
OIL : Real spot price of oil
FOOD : Real food commodities price index
RAW : Real raw material commodities price index
M2 : The M2 monetary aggregate
YL : The level factor
TS : The slope factor
CS : Curvature factor
MS : One-year ahead inflation expectations that come from the Reuters/Michigan Survey of Consumers.
Usage
data(USData)
Format
A xts object containing 206x16 observations from from 1960-01-01 to 2011-04-01.
References
Groen, Jan JJ, Richard Paap, and Francesco Ravazzolo. (2013) Real–time inflation forecasting in a changing world. Journal of Business & Economic Statistics, 31.1 : 29–44.
data: Dates of U.S. recessions as inferred by GDP-based recession indicator (JHDUSRGDPBR).
Description
Dates of U.S. recessions as inferred by GDP-based recession indicator (JHDUSRGDPBR) downloaded from FRED. https://fred.stlouisfed.org/series/JHDUSRGDPBR#0.
From the FRED website:
The series assigns dates to U.S. recessions based on a mathematical model of the way that recessions differ from expansions. Whereas the NBER business cycle dates are based on a subjective assessment of a variety of indicators, the dates here are entirely mechanical and are calculated solely from historically reported GDP data. Whenever the GDP-based recession indicator index rises above 67%, the economy is determined to be in a recession. The date that the recession is determined to have begun is the first quarter prior to that date for which the inference from the mathematical model using all data available at that date would have been above 50%. The next time the GDP-based recession indicator index falls below 33%, the recession is determined to be over, and the last quarter of the recession is the first quarter for which the inference from the mathematical model using all available data at that date would have been below 50%.
Usage
data(USData)
Format
A zoo object containing 206 observations at quarterly frequency from 1960-Q1 to 2011-Q4.
References
Hamilton, James, Dates of U.S. recessions as inferred by GDP-based recession indicator [JHDUSRGDPBR], retrieved from FRED, Federal Reserve Bank of St. Louis; https://fred.stlouisfed.org/series/JHDUSRGDPBR, February 4, 2018.
Examples
data("USRecessions")