# Dynamic Model Averaging in Economics and Finance with fDMA: A Package for R
## 8 Make Work Easier
#### 4.2.3 onevar(x)  
Only one argument is used for this function. x should be a matrix of explanatory variables. The outcomes are a matrix, which can serve as the argument mods.incl in various functions from package fDMA. In particular, the inclusion of a variable is indicated by 1, and omission by 0. R> wti <- crudeoil[-1, 1] R> drivers <- (lag(crudeoil[, -1], k = 1))[-1, ]R> ld.wti <- (diff(log(wti)))[-1, ] R> ld.drivers <- (diff(log(drivers)))[-1, ]  
R> mds <- diag(1, ncol(ld.drivers), ncol(ld.drivers)) R> mds <- cbind(rep(1, ncol(ld.drivers)), mds) R> mds <- rbind(rep(0, ncol(mds)), mds) R> mds[1, 1] <-^1  
R> m1 <- fDMA(y = ld.wti, x = ld.drivers, alpha = 0.95, lambda = 0.95, + initvar = 1, mods.incl = mds)  
R> m2 <- fDMA(y = ld.wti, x = ld.drivers, alpha = 0.95, lambda = 0.95, + initvar = 1, mods.incl = onevar(ld.drivers))  
Models m1 and m2 from the above example are the same models. Recursive regression is implemented as the function rec.reg. This function is simply based on lm from the package stats. rec.reg(y, x = NULL, c = NULL)  
The arguments for this function are the following:  
* y should be a numeric or a column matrix representing the dependent variable,
* x is optional. This matrix represents the explanatory variables. Different columns should correspond to different variables. If not specified, then only the constant term is used in the regression,
* c is optional. This logical is the parameter indicating whether the constant term should be included in the regression equation. If not specified c = TRUE is used, i.e., the constant term is included. It is not possible to set c = FALSE if x = NULL. In such a case the function will automatically reset to c = TRUE inside the code. The outcomes are a class reg object, i.e., a list of:  
* $y.hat: a vector of fitted (forecasted) values,
* $AIC: a vector of Akaike Information Criterion (AIC), from the current set of observations,
* $AIC: a vector of Akaike Information Criterion with a correction for finite sample sizes (AICc) from the current set of observations,
* $BIC: a vector of Bayesian Information Criterion (BIC), from the current set of observations,
* $MSE: a vector of Mean Squared Error (MSE), from the current set of observations,
* $coeff. : a matrix of regression coefficients,
* $p.val: a matrix of \(p\)-values for \(t\)-test for statistical significance of regression coefficients,
* $y: a vector of the dependent time-series. It might happen during computations that lm function (used inside rec.reg) will produce NA or NaN. In such a case regression coefficients for the given period are taken as 0 and \(p\)-values for \(t\)-test for statistical significance of regression coefficients are taken as 1. R> wti <- crudeoil[-1, 1] R> drivers <- (lag(crudeoil[, -1], k = 1))[-1, ]  
R> ld.wti <- (diff(log(wti)))[-1, ] R> ld.drivers <- (diff(log(drivers)))[-1, ]R> rec1 <- rec.reg(y = ld.wti, x = ld.drivers) R> rec2 <- rec.reg(y = ld.wti)  
The function roll.reg computes rolling window regression. It is similar to the already described rec.reg. roll.reg(y, x = NULL, window, c = NULL)  
The arguments y, x and c are the same as for the already described function rec.reg. The argument window should be a numeric indicating the size of a window for rolling. In particular, for the first window \(-1\) observations recursive regression is computed. Then, since window-th observation the exact rolling is performed. The outcomes are the already described reg object. R> wti <- crudeoil[-1, 1] R> drivers <- (lag(crudeoil[, -1], k = 1))[-1, ] R> ld.wti <- (diff(log(wti)))[-1, ] R> ld.drivers <- (diff(log(drivers)))[-1, ] R> roll1 <- roll.reg(y = ld.wti, x = ld.drivers, window = 100) R> roll2 <- roll.reg(y = ld.wti, window = 100)  
Outcomes from the object of class reg can be easily presented with a help of functions print.reg, summary.reg and plot.reg. The first function prints mean regression coefficients from the analysed period, RMSE (Root Mean Squared Error) and MAE (Mean Absolute Error) from the estimated model.