Package {eDMA}


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 ORCID iD [aut, cre], Nima Nonejad ORCID iD [ctb]
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

DMA

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 iBurnPeriod = NULL. If iBurnPeriod = NULL then one third of the total sample is used as the burn-in in period and a warning is printed.

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 ts, xts or zoo. If this is the case, the time information is used in the graphical representation of the results. The last observation of the dependent variable can be equal to NA. This is the case when a series of length T is available but the user wants to have predictions for time T+1, see Details.

vDelta

D x 1 numeric vector representing the the grid of values of \delta. By default vDelta = c(0.9, 0.95, 0.99).

dAlpha

numeric variable representing \alpha. By default dAlpha = 0.99.

vKeep

numeric vector of indices representing the predictors that must be always included in the models. The combinations of predictors that do not include the variables declared in vKeep are automatically discarded. The indices must be consistent with the model description given in formula, i.e., if the first and the fourth variables always have to be included, then we must set vKeep=c(1, 4). Note that, the intercept (if not removed from formula) is always in the first position. It can also be a character vector indicating the names of the predictors if these are consistent with the provided formula. If vKeep = "KS" the "Kitchen Sink" formulation is adopted, i.e., all the predictors are always included, see, e.g., Paye (2012). By default all the combinations are considered, i.e. vKeep = NULL.

bZellnerPrior

Boolean variable indicating whether the Zellner prior should be used on the coefficients at time t=0. Default = FALSE.

dG

numeric variable equal to 100 by default. If bZellnerPrior = TRUE this represent the variable 'g' in Eq. (4) of Dangl Halling (2012). Otherwise, if bZellnerPrior = FALSE it represents the scaling factor for the variance covariance matrix of the normal prior for \theta_0, i.e. \theta_0~N(0,dG*I) where I is the identity matrix.

bParallelize

Boolean variable indicating whether to use multiple processors to speed up the computations. By default bParallelize = TRUE.

iCores

integer indicating the number of cores to use if bParallelize = TRUE. By default all but one cores are used. The number of cores is guessed using the detectCores() function from the parallel package.

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 the DMA function.

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 argument iBurnPeriod corresponding at the length of the burn-in period. By default iBurnPeriod = NULL, i.e. all the sample is used.

coef

signature(object = "DMA"): Extract the filtered regressor coefficients. This method accepts the additional argument iBurnPeriod corresponding at the length of the burn-in period. By default iBurnPeriod = NULL, i.e. all the sample is used.

residuals

signature(object = "DMA"): Extract the residuals of the model. This method accepts the additional argument iBurnPeriod corresponding at the length of the burn-in period. By default iBurnPeriod = NULL, i.e. all the sample is used. The additional Boolean argument standardize controls if standardize residuals should be returned. By default standardize = FALSE. The additional argument type permits to choose between residuals evaluated using DMA or DMS. By default type = "DMA".

inclusion.prob

signature(object = "DMA"): Extract the inclusion probabilities of the regressors. This method accepts the additional argument iBurnPeriod corresponding at the length of the burn-in period. By default iBurnPeriod = NULL, i.e. all the sample is used.

pred.like

signature(object = "DMA"): Extract the predictive log-likelihood series. This method accepts the additional argument iBurnPeriod corresponding at the length of the burn-in period. By default iBurnPeriod = NULL, i.e. all the sample is used. The additional argument type permits to choose between predictive likelihood evaluated using DMA or DMS. By default type = "DMA".

getLastForecast

signature(object = "DMA"): If the last observation of the dependent variable was NA, i.e. the practitioner desidered to predict Y_{T+1} having a sample of length T (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 in DMA.

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:

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

numeric an integer between 0 and 20 giving the number of elements in the series {0,1,2,...,iK-1}.

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

numeric, positive integer number of observations to simulate.

mX

matrix of dimension iT x N where N is the number of covariates.

vBeta0

numeric vector with initial value for the regressor coefficients.

mW

matrix symmetric positive-semidefinite covariance matrix of the state equation. Zero and rank-deficient covariance matrices are supported.

dV

numeric nonnegative variance of the observation (measurement equation).

dPhi

numeric value for the autoregressive parameter of the regressors. It imposes that all the regressors have the same autoregressive parameters, if dPhi = 1, then the regressors evolve as random-walks.

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")

mirror server hosted at Truenetwork, Russian Federation.