Title: | Mixed Data Sampling Regression |
---|---|
Description: | Methods and tools for mixed frequency time series data analysis. Allows estimation, model selection and forecasting for MIDAS regressions. |
Authors: | Virmantas Kvedaras <[email protected]>, Vaidotas Zemlys-Balevicius <[email protected]> |
Maintainer: | Vaidotas Zemlys-Balevičius <[email protected]> |
License: | GPL-2 | MIT + file LICENCE |
Version: | 0.8.2 |
Built: | 2025-02-10 04:45:04 UTC |
Source: | https://github.com/mpiktas/midasr |
Package for estimating, testing and forecasting MIDAS regression.
Methods and tools for mixed frequency time series data analysis. Allows estimation, model selection and forecasting for MIDAS regressions.
Virmantas Kvedaras [email protected], Vaidotas Zemlys (maintainer) [email protected]
lws_table
objectsCombines lws_table
objects
## S3 method for class 'lws_table' ... + check = TRUE
## S3 method for class 'lws_table' ... + check = TRUE
... |
|
check |
logical, if TRUE checks that the each |
The lws_table
objects have similar structure to table, i.e. it is a list with 3 elements which are the lists with the same number of elements. The base function c
would cbind
such tables. This function rbind
s them.
lws_table
object
Virmantas Kvedaras, Vaidotas Zemlys
nlmn <- expand_weights_lags("nealmon",0,c(4,8),1,start=list(nealmon=rep(0,3))) nbt <- expand_weights_lags("nbeta",0,c(4,8),1,start=list(nbeta=rep(0,4))) nlmn+nbt
nlmn <- expand_weights_lags("nealmon",0,c(4,8),1,start=list(nealmon=rep(0,3))) nbt <- expand_weights_lags("nbeta",0,c(4,8),1,start=list(nbeta=rep(0,4))) nlmn+nbt
Perform the test whether hyperparameters of normalized exponential Almon lag weights are zero
agk.test(x)
agk.test(x)
x |
MIDAS regression object of class |
a htest
object
Virmantas Kvedaras, Vaidotas Zemlys
Andreou E., Ghysels E., Kourtellos A. Regression models with mixed sampling frequencies Journal of Econometrics 158 (2010) 246-261
##' ##Load data data("USunempr") data("USrealgdp") y <- diff(log(USrealgdp)) x <- window(diff(USunempr),start=1949) t <- 1:length(y) mr <- midas_r(y~t+fmls(x,11,12,nealmon),start=list(x=c(0,0,0))) agk.test(mr)
##' ##Load data data("USunempr") data("USrealgdp") y <- diff(log(USrealgdp)) x <- window(diff(USunempr),start=1949) t <- 1:length(y) mr <- midas_r(y~t+fmls(x,11,12,nealmon),start=list(x=c(0,0,0))) agk.test(mr)
Calculate Almon polynomial MIDAS weights
almonp(p, d, m)
almonp(p, d, m)
p |
parameters for Almon polynomial weights |
d |
number of coefficients |
m |
the frequency ratio, currently ignored |
vector of coefficients
Virmantas Kvedaras, Vaidotas Zemlys
Calculate gradient for Almon polynomial MIDAS weights specification
almonp_gradient(p, d, m)
almonp_gradient(p, d, m)
p |
vector of parameters for Almon polynomial specification |
d |
number of coefficients |
m |
the frequency ratio, currently ignored |
vector of coefficients
Vaidotas Zemlys
Create weight and lag selection table for the aggregates based MIDAS regression model
amidas_table( formula, data, weights, wstart, type, start = NULL, from, to, IC = c("AIC", "BIC"), test = c("hAh_test"), Ofunction = "optim", weight_gradients = NULL, ... )
amidas_table( formula, data, weights, wstart, type, start = NULL, from, to, IC = c("AIC", "BIC"), test = c("hAh_test"), Ofunction = "optim", weight_gradients = NULL, ... )
formula |
the formula for MIDAS regression, the lag selection is performed for the last MIDAS lag term in the formula |
data |
a list containing data with mixed frequencies |
weights |
the names of weights used in Ghysels schema |
wstart |
the starting values for the weights of the firs low frequency lag |
type |
the type of Ghysels schema see amweights, can be a vector of types |
start |
the starting values for optimisation excluding the starting values for the last term |
from |
a named list, or named vector with high frequency (NB!) lag numbers which are the beginnings of MIDAS lag structures. The names should correspond to the MIDAS lag terms in the formula for which to do the lag selection. Value NA indicates lag start at zero |
to |
to a named list where each element is a vector with two elements. The first element is the low frequency lag number from which the lag selection starts, the second is the low frequency lag number at which the lag selection ends. NA indicates lowest (highest) lag numbers possible. |
IC |
the names of information criteria which should be calculated |
test |
the names of statistical tests to perform on restricted model, p-values are reported in the columns of model selection table |
Ofunction |
see midasr |
weight_gradients |
see midas_r |
... |
additional parameters to optimisation function, see midas_r |
This function estimates models sequentialy increasing the midas lag from kmin
to kmax
and varying the weights of the last term of the given formula
This function estimates models sequentially increasing the midas lag from kmin
to kmax
and varying the weights of the last term of the given formula
a midas_r_ic_table
object which is the list with the following elements:
table |
the table where each row contains calculated information criteria for both restricted and unrestricted MIDAS regression model with given lag structure |
candlist |
the list containing fitted models |
IC |
the argument IC |
test |
the argument test |
weights |
the names of weight functions |
lags |
the lags used in models |
Virmantas Kvedaras, Vaidotas Zemlys
data("USunempr") data("USrealgdp") y <- diff(log(USrealgdp)) x <- window(diff(USunempr),start=1949) trend <- 1:length(y) tb <- amidas_table(y~trend+fmls(x,12,12,nealmon), data=list(y=y,x=x,trend=trend), weights=c("nealmon"),wstart=list(nealmon=c(0,0,0)), start=list(trend=1),type=c("A"), from=0,to=c(1,2))
data("USunempr") data("USrealgdp") y <- diff(log(USrealgdp)) x <- window(diff(USunempr),start=1949) trend <- 1:length(y) tb <- amidas_table(y~trend+fmls(x,12,12,nealmon), data=list(y=y,x=x,trend=trend), weights=c("nealmon"),wstart=list(nealmon=c(0,0,0)), start=list(trend=1),type=c("A"), from=0,to=c(1,2))
Produces weights for aggregates based MIDAS regression
amweights(p, d, m, weight = nealmon, type = c("A", "B", "C"))
amweights(p, d, m, weight = nealmon, type = c("A", "B", "C"))
p |
parameters for weight functions, see details. |
d |
number of high frequency lags |
m |
the frequency |
weight |
the weight function |
type |
type of structure, a string, one of A, B or C. |
Suppose a weight function satisfies the following equation:
The following combinations are defined, corresponding to structure types
A
, B
and C
respectively:
where is the number of low frequency lags, i.e.
. If the latter
value is not whole number, the error is produced.
The starting values should be supplied then as follows:
a vector of weights
Virmantas Kvedaras, Vaidotas Zemlys
Average MIDAS model forecasts using specified weighting scheme. Produce in-sample and out-of-sample accuracy measures.
average_forecast( modlist, data, insample, outsample, type = c("fixed", "recursive", "rolling"), fweights = c("EW", "BICW", "MSFE", "DMSFE"), measures = c("MSE", "MAPE", "MASE"), show_progress = TRUE )
average_forecast( modlist, data, insample, outsample, type = c("fixed", "recursive", "rolling"), fweights = c("EW", "BICW", "MSFE", "DMSFE"), measures = c("MSE", "MAPE", "MASE"), show_progress = TRUE )
modlist |
a list of |
data |
a list with mixed frequency data |
insample |
the low frequency indexes for in-sample data |
outsample |
the low frequency indexes for out-of-sample data |
type |
a string indicating which type of forecast to use. |
fweights |
names of weighting schemes |
measures |
names of accuracy measures |
show_progress |
logical, TRUE to show progress bar, FALSE for silent evaluation |
Given the data, split it to in-sample and out-of-sample data. Then given the list of models, reestimate each model with in-sample data and produce out-of-sample forecast. Given the forecasts average them with the specified weighting scheme. Then calculate the accuracy measures for individual and average forecasts.
The forecasts can be produced in 3 ways. The "fixed"
forecast uses model estimated with in-sample data. The "rolling"
forecast reestimates model each time by increasing the in-sample by one low frequency observation and dropping the first low frequency observation. These reestimated models then are used to produce out-of-sample forecasts. The "recursive"
forecast differs from "rolling"
that it does not drop observations from the beginning of data.
a list containing forecasts and tables of accuracy measures
Virmantas Kvedaras, Vaidotas Zemlys
set.seed(1001) ## Number of low-frequency observations n<-250 ## Linear trend and higher-frequency explanatory variables (e.g. quarterly and monthly) trend<-c(1:n) x<-rnorm(4*n) z<-rnorm(12*n) ## Exponential Almon polynomial constraint-consistent coefficients fn.x <- nealmon(p=c(1,-0.5),d=8) fn.z <- nealmon(p=c(2,0.5,-0.1),d=17) ## Simulated low-frequency series (e.g. yearly) y<-2+0.1*trend+mls(x,0:7,4)%*%fn.x+mls(z,0:16,12)%*%fn.z+rnorm(n) mod1 <- midas_r(y ~ trend + mls(x, 4:14, 4, nealmon) + mls(z, 12:22, 12, nealmon), start=list(x=c(10,1,-0.1),z=c(2,-0.1))) mod2 <- midas_r(y ~ trend + mls(x, 4:20, 4, nealmon) + mls(z, 12:25, 12, nealmon), start=list(x=c(10,1,-0.1),z=c(2,-0.1))) ##Calculate average forecasts avgf <- average_forecast(list(mod1,mod2), data=list(y=y,x=x,z=z,trend=trend), insample=1:200,outsample=201:250, type="fixed", measures=c("MSE","MAPE","MASE"), fweights=c("EW","BICW","MSFE","DMSFE"))
set.seed(1001) ## Number of low-frequency observations n<-250 ## Linear trend and higher-frequency explanatory variables (e.g. quarterly and monthly) trend<-c(1:n) x<-rnorm(4*n) z<-rnorm(12*n) ## Exponential Almon polynomial constraint-consistent coefficients fn.x <- nealmon(p=c(1,-0.5),d=8) fn.z <- nealmon(p=c(2,0.5,-0.1),d=17) ## Simulated low-frequency series (e.g. yearly) y<-2+0.1*trend+mls(x,0:7,4)%*%fn.x+mls(z,0:16,12)%*%fn.z+rnorm(n) mod1 <- midas_r(y ~ trend + mls(x, 4:14, 4, nealmon) + mls(z, 12:22, 12, nealmon), start=list(x=c(10,1,-0.1),z=c(2,-0.1))) mod2 <- midas_r(y ~ trend + mls(x, 4:20, 4, nealmon) + mls(z, 12:25, 12, nealmon), start=list(x=c(10,1,-0.1),z=c(2,-0.1))) ##Calculate average forecasts avgf <- average_forecast(list(mod1,mod2), data=list(y=y,x=x,z=z,trend=trend), insample=1:200,outsample=201:250, type="fixed", measures=c("MSE","MAPE","MASE"), fweights=c("EW","BICW","MSFE","DMSFE"))
Given mixed frequency data check whether higher frequency data can be converted to the lowest frequency.
check_mixfreq(data)
check_mixfreq(data)
data |
a list containing mixed frequency data |
The number of observations in higher frequency data elements should have a common divisor with the number of observations in response variable. It is always assumed that the response variable is of the lowest frequency.
a boolean TRUE, if mixed frequency data is conformable, FALSE if it is not.
Virmantas Kvedaras, Vaidotas Zemlys
Extracts various coefficients of MIDAS regression
## S3 method for class 'midas_nlpr' coef(object, type = c("plain", "midas", "nlpr"), term_names = NULL, ...)
## S3 method for class 'midas_nlpr' coef(object, type = c("plain", "midas", "nlpr"), term_names = NULL, ...)
object |
|
type |
one of plain, midas, or nlpr. Returns appropriate coefficients. |
term_names |
a character vector with term names. Default is |
... |
not used currently |
MIDAS regression has two sets of cofficients. The first set is the coefficients associated with the parameters of weight functions associated with MIDAS regression terms. These are the coefficients of the NLS problem associated with MIDAS regression. The second is the coefficients of the linear model, i.e the values of weight functions of terms, or so called MIDAS coefficients. By default the function returns the first set of the coefficients.
a vector with coefficients
Vaidotas Zemlys
Extracts various coefficients of MIDAS regression
## S3 method for class 'midas_r' coef(object, midas = FALSE, term_names = NULL, ...)
## S3 method for class 'midas_r' coef(object, midas = FALSE, term_names = NULL, ...)
object |
|
midas |
logical, if |
term_names |
a character vector with term names. Default is |
... |
not used currently |
MIDAS regression has two sets of cofficients. The first set is the coefficients associated with the parameters of weight functions associated with MIDAS regression terms. These are the coefficients of the NLS problem associated with MIDAS regression. The second is the coefficients of the linear model, i.e the values of weight functions of terms, or so called MIDAS coefficients. By default the function returns the first set of the coefficients.
a vector with coefficients
Vaidotas Zemlys
#Simulate MIDAS regression n<-250 trend<-c(1:n) x<-rnorm(4*n) z<-rnorm(12*n) fn.x <- nealmon(p=c(1,-0.5),d=8) fn.z <- nealmon(p=c(2,0.5,-0.1),d=17) y<-2+0.1*trend+mls(x,0:7,4)%*%fn.x+mls(z,0:16,12)%*%fn.z+rnorm(n) eqr<-midas_r(y ~ trend + mls(x, 0:7, 4, nealmon) + mls(z, 0:16, 12, nealmon), start = list(x = c(1, -0.5), z = c(2, 0.5, -0.1))) coef(eqr) coef(eqr, term_names = "x") coef(eqr, midas = TRUE) coef(eqr, midas = TRUE, term_names = "x")
#Simulate MIDAS regression n<-250 trend<-c(1:n) x<-rnorm(4*n) z<-rnorm(12*n) fn.x <- nealmon(p=c(1,-0.5),d=8) fn.z <- nealmon(p=c(2,0.5,-0.1),d=17) y<-2+0.1*trend+mls(x,0:7,4)%*%fn.x+mls(z,0:16,12)%*%fn.z+rnorm(n) eqr<-midas_r(y ~ trend + mls(x, 0:7, 4, nealmon) + mls(z, 0:16, 12, nealmon), start = list(x = c(1, -0.5), z = c(2, 0.5, -0.1))) coef(eqr) coef(eqr, term_names = "x") coef(eqr, midas = TRUE) coef(eqr, midas = TRUE, term_names = "x")
Extracts various coefficients of MIDAS regression
## S3 method for class 'midas_sp' coef(object, type = c("plain", "midas", "bw"), term_names = NULL, ...)
## S3 method for class 'midas_sp' coef(object, type = c("plain", "midas", "bw"), term_names = NULL, ...)
object |
|
type |
one of plain, midas, or nlpr. Returns appropriate coefficients. |
term_names |
a character vector with term names. Default is |
... |
not used currently |
MIDAS regression has two sets of cofficients. The first set is the coefficients associated with the parameters of weight functions associated with MIDAS regression terms. These are the coefficients of the NLS problem associated with MIDAS regression. The second is the coefficients of the linear model, i.e the values of weight functions of terms, or so called MIDAS coefficients. By default the function returns the first set of the coefficients.
a vector with coefficients
Vaidotas Zemlys
Computes the gradient and hessian of the optimisation function of restricted MIDAS regression and checks whether the conditions of local optimum are met. Numerical estimates are used.
deriv_tests(x, tol = 1e-06) ## S3 method for class 'midas_r' deriv_tests(x, tol = 1e-06)
deriv_tests(x, tol = 1e-06) ## S3 method for class 'midas_r' deriv_tests(x, tol = 1e-06)
x |
|
tol |
a tolerance, values below the tolerance are considered zero |
a list with gradient, hessian of optimisation function and convergence message
Vaidotas Zemlys
midas_r
Returns the deviance of a fitted MIDAS regression object
## S3 method for class 'midas_nlpr' deviance(object, ...)
## S3 method for class 'midas_nlpr' deviance(object, ...)
object |
a |
... |
currently nothing |
The sum of squared residuals
Virmantas Kvedaras, Vaidotas Zemlys
Returns the deviance of a fitted MIDAS regression object
## S3 method for class 'midas_r' deviance(object, ...)
## S3 method for class 'midas_r' deviance(object, ...)
object |
a |
... |
currently nothing |
The sum of squared residuals
Virmantas Kvedaras, Vaidotas Zemlys
Returns the deviance of a fitted MIDAS regression object
## S3 method for class 'midas_sp' deviance(object, ...)
## S3 method for class 'midas_sp' deviance(object, ...)
object |
a |
... |
currently nothing |
The sum of squared residuals
Virmantas Kvedaras, Vaidotas Zemlys
Prepares MIDAS lag structure for unit root processes
dmls(x, k, m, ...)
dmls(x, k, m, ...)
x |
a vector |
k |
maximal lag order |
m |
frequency ratio |
... |
further arguments used in fitting MIDAS regression |
a matrix containing the first differences and the lag k+1.
Virmantas Kvedaras, Vaidotas Zemlys
Create table of weights, lags and starting values for Ghysels weight schema, see amweights
expand_amidas(weight, type = c("A", "B", "C"), from = 0, to, m, start)
expand_amidas(weight, type = c("A", "B", "C"), from = 0, to, m, start)
weight |
the names of weight functions |
type |
the type of Ghysels schema, |
from |
the high frequency lags from which to start the fitting |
to |
to a vector of length two, containing minimum and maximum lags, high frequency if |
m |
the frequency ratio |
start |
the starting values for the weights of the one low frequency lag |
Given weight function creates lags starting from kmin
to kmax
and replicates starting values for each low frequency lag.
a lws_table
object, a list with elements weights
, lags
and starts
Virmantas Kvedaras, Vaidotas Zemlys
expand_amidas("nealmon","A",0,c(1,2),12,c(0,0,0))
expand_amidas("nealmon","A",0,c(1,2),12,c(0,0,0))
Creates table of weights, lags and starting values
expand_weights_lags(weights, from = 0, to, m = 1, start)
expand_weights_lags(weights, from = 0, to, m = 1, start)
weights |
either a vector with names of the weight functions or a named list of weight functions |
from |
the high frequency lags from which to start the fitting |
to |
a vector of length two, containing minimum and maximum lags, high frequency if |
m |
the frequency ratio |
start |
a named list with the starting values for weight functions |
For each weight function creates lags starting from kmin
to kmax
. This is a convenience function for easier work with the function midas_r_ic_table.
a lws_table
object, a list with elements weights
, lags
and starts
.
Virmantas Kvedaras, Vaidotas Zemlys
expand_weights_lags(c("nealmon","nbeta"),0,c(4,8),1,start=list(nealmon=rep(0,3),nbeta=rep(0,4))) nlmn <- expand_weights_lags("nealmon",0,c(4,8),1,start=list(nealmon=rep(0,3))) nbt <- expand_weights_lags("nbeta",0,c(4,8),1,start=list(nbeta=rep(0,4))) nlmn+nbt
expand_weights_lags(c("nealmon","nbeta"),0,c(4,8),1,start=list(nealmon=rep(0,3),nbeta=rep(0,4))) nlmn <- expand_weights_lags("nealmon",0,c(4,8),1,start=list(nealmon=rep(0,3))) nbt <- expand_weights_lags("nbeta",0,c(4,8),1,start=list(nbeta=rep(0,4))) nlmn+nbt
Extract coefficients and GOF measures from MIDAS regression object
extract.midas_r( model, include.rsquared = TRUE, include.nobs = TRUE, include.rmse = TRUE, ... )
extract.midas_r( model, include.rsquared = TRUE, include.nobs = TRUE, include.rmse = TRUE, ... )
model |
a MIDAS regression object |
include.rsquared |
If available: should R-squared be reported? |
include.nobs |
If available: should the number of observations be reported? |
include.rmse |
If available: should the root-mean-square error (= residual standard deviation) be reported? |
... |
additional parameters passed to summary |
texreg object
Virmantas Kvedaras, Vaidotas Zemlys
Returns the fitted values of a fitted non-linear parametric MIDAS regression object
## S3 method for class 'midas_nlpr' fitted(object, ...)
## S3 method for class 'midas_nlpr' fitted(object, ...)
object |
a |
... |
currently nothing |
the vector of fitted values
Virmantas Kvedaras, Vaidotas Zemlys
Returns the fitted values of a fitted semi-parametric MIDAS regression object
## S3 method for class 'midas_sp' fitted(object, ...)
## S3 method for class 'midas_sp' fitted(object, ...)
object |
a |
... |
currently nothing |
the vector of fitted values
Virmantas Kvedaras, Vaidotas Zemlys
Create a matrix of MIDAS lags, including contemporaneous lag up to selected order.
fmls(x, k, m, ...)
fmls(x, k, m, ...)
x |
a vector |
k |
maximum lag order |
m |
frequency ratio |
... |
further arguments |
This is a convenience function, it calls link{mls}
to perform actual calculations.
a matrix containing the lags
Virmantas Kvedaras, Vaidotas Zemlys
mls
Forecasts MIDAS regression given the future values of regressors. For dynamic models (with lagged response variable) there is an option to calculate dynamic forecast, when forecasted values of response variable are substituted into the lags of response variable.
## S3 method for class 'midas_r' forecast( object, newdata = NULL, se = FALSE, level = c(80, 95), fan = FALSE, npaths = 999, method = c("static", "dynamic"), insample = get_estimation_sample(object), show_progress = TRUE, add_ts_info = FALSE, ... )
## S3 method for class 'midas_r' forecast( object, newdata = NULL, se = FALSE, level = c(80, 95), fan = FALSE, npaths = 999, method = c("static", "dynamic"), insample = get_estimation_sample(object), show_progress = TRUE, add_ts_info = FALSE, ... )
object |
midas_r object |
newdata |
a named list containing future values of mixed frequency regressors. The default is |
se |
logical, if |
level |
confidence level for prediction intervals |
fan |
if TRUE, level is set to seq(50,99,by=1). This is suitable for fan plots |
npaths |
the number of samples for simulating prediction intervals |
method |
the forecasting method, either |
insample |
a list containing the historic mixed frequency data |
show_progress |
logical, if |
add_ts_info |
logical, if |
... |
additional arguments to |
Given future values of regressors this function combines the historical values used in the fitting the MIDAS regression model and calculates the forecasts.
an object of class "forecast"
, a list containing following elements:
method |
the name of forecasting method: MIDAS regression, static or dynamic |
model |
original object of class |
mean |
point forecasts |
lower |
lower limits for prediction intervals |
upper |
upper limits for prediction intervals |
fitted |
fitted values, one-step forecasts |
residuals |
residuals from the fitted model |
x |
the original response variable |
The methods print
, summary
and plot
from package forecast
can be used on the object.
Vaidotas Zemlys
data("USrealgdp") data("USunempr") y <- diff(log(USrealgdp)) x <- window(diff(USunempr), start = 1949) trend <- 1:length(y) ##24 high frequency lags of x included mr <- midas_r(y ~ trend + fmls(x, 23, 12, nealmon), start = list(x = rep(0, 3))) ##Forecast horizon h <- 3 ##Declining unemployment xn <- rep(-0.1, 12*h) ##New trend values trendn <- length(y) + 1:h ##Static forecasts combining historic and new high frequency data forecast(mr, list(trend = trendn, x = xn), method = "static") ##Dynamic AR* model mr.dyn <- midas_r(y ~ trend + mls(y, 1:2, 1, "*") + fmls(x, 11, 12, nealmon), start = list(x = rep(0, 3))) forecast(mr.dyn, list(trend = trendn, x = xn), method = "dynamic") ##Use print, summary and plot methods from package forecast fmr <- forecast(mr, list(trend = trendn, x = xn), method = "static") fmr summary(fmr) plot(fmr)
data("USrealgdp") data("USunempr") y <- diff(log(USrealgdp)) x <- window(diff(USunempr), start = 1949) trend <- 1:length(y) ##24 high frequency lags of x included mr <- midas_r(y ~ trend + fmls(x, 23, 12, nealmon), start = list(x = rep(0, 3))) ##Forecast horizon h <- 3 ##Declining unemployment xn <- rep(-0.1, 12*h) ##New trend values trendn <- length(y) + 1:h ##Static forecasts combining historic and new high frequency data forecast(mr, list(trend = trendn, x = xn), method = "static") ##Dynamic AR* model mr.dyn <- midas_r(y ~ trend + mls(y, 1:2, 1, "*") + fmls(x, 11, 12, nealmon), start = list(x = rep(0, 3))) forecast(mr.dyn, list(trend = trendn, x = xn), method = "dynamic") ##Use print, summary and plot methods from package forecast fmr <- forecast(mr, list(trend = trendn, x = xn), method = "static") fmr summary(fmr) plot(fmr)
Calculates the MIDAS coefficients for generalized exponential MIDAS lag specification
genexp(p, d, m)
genexp(p, d, m)
p |
a vector of parameters |
d |
number of coefficients |
m |
the frequency, currently ignored |
Generalized exponential MIDAS lag specification is a generalization of exponential Almon lag. It is defined as a product of first order polynomial with exponent of the second order polynomial. This spefication was used by V. Kvedaras and V. Zemlys (2012).
a vector of coefficients
Virmantas Kvedaras, Vaidotas Zemlys
Kvedaras V., Zemlys, V. Testing the functional constraints on parameters in regressions with variables of different frequency Economics Letters 116 (2012) 250-254
Calculates the gradient of generalized exponential MIDAS lag specification
genexp_gradient(p, d, m)
genexp_gradient(p, d, m)
p |
a vector of parameters |
d |
number of coefficients |
m |
the frequency, currently ignored |
Generalized exponential MIDAS lag specification is a generalization of exponential Almon lag. It is defined as a product of first order polynomial with exponent of the second order polynomial. This spefication was used by V. Kvedaras and V. Zemlys (2012).
a vector of coefficients
Virmantas Kvedaras, Vaidotas Zemlys
Kvedaras V., Zemlys, V. Testing the functional constraints on parameters in regressions with variables of different frequency Economics Letters 116 (2012) 250-254
Gets the data which was used to estimate MIDAS regression
get_estimation_sample(object)
get_estimation_sample(object)
object |
|
A helper function.
a named list with mixed frequency data
Vaidotas Zemlys
Calculate MIDAS weights according to normalized Gompertz probability density function specification
gompertzp(p, d, m)
gompertzp(p, d, m)
p |
parameters for normalized Gompertz probability density function |
d |
number of coefficients |
m |
the frequency ratio, currently ignored |
vector of coefficients
Julius Vainora
Calculate gradient function for normalized Gompertz probability density function specification of MIDAS weights.
gompertzp_gradient(p, d, m)
gompertzp_gradient(p, d, m)
p |
parameters for normalized Gompertz probability density function |
d |
number of coefficients |
m |
the frequency ratio, currently ignored |
vector of coefficients
Julius Vainora
Perform a test whether the restriction on MIDAS regression coefficients holds.
hAh_test(x)
hAh_test(x)
x |
MIDAS regression model with restricted coefficients, estimated with |
Given MIDAS regression:
test the null hypothesis that the following restriction holds:
where .
a htest
object
Virmantas Kvedaras, Vaidotas Zemlys
Kvedaras V., Zemlys, V. Testing the functional constraints on parameters in regressions with variables of different frequency Economics Letters 116 (2012) 250-254
hAhr_test
##The parameter function theta_h0 <- function(p, dk, ...) { i <- (1:dk-1) (p[1] + p[2]*i)*exp(p[3]*i + p[4]*i^2) } ##Generate coefficients theta0 <- theta_h0(c(-0.1,0.1,-0.1,-0.001),4*12) ##Plot the coefficients plot(theta0) ##Generate the predictor variable set.seed(13) xx <- ts(arima.sim(model = list(ar = 0.6), 600 * 12), frequency = 12) ##Simulate the response variable y <- midas_sim(500, xx, theta0) x <- window(xx, start=start(y)) ##Fit restricted model mr <- midas_r(y~fmls(x,4*12-1,12,theta_h0)-1,list(y=y,x=x), start=list(x=c(-0.1,0.1,-0.1,-0.001))) ##Perform test (the expected result should be the acceptance of null) hAh_test(mr) ##Fit using gradient function ##The gradient function theta_h0_gradient<-function(p, dk,...) { i <- (1:dk-1) a <- exp(p[3]*i + p[4]*i^2) cbind(a, a*i, a*i*(p[1]+p[2]*i), a*i^2*(p[1]+p[2]*i)) } mr <- midas_r(y~fmls(x,4*12-1,12,theta_h0)-1,list(y=y,x=x), start=list(x=c(-0.1,0.1,-0.1,-0.001)), weight_gradients=list()) ##The test will use an user supplied gradient of weight function. See the ##help of midas_r on how to supply the gradient. hAh_test(mr)
##The parameter function theta_h0 <- function(p, dk, ...) { i <- (1:dk-1) (p[1] + p[2]*i)*exp(p[3]*i + p[4]*i^2) } ##Generate coefficients theta0 <- theta_h0(c(-0.1,0.1,-0.1,-0.001),4*12) ##Plot the coefficients plot(theta0) ##Generate the predictor variable set.seed(13) xx <- ts(arima.sim(model = list(ar = 0.6), 600 * 12), frequency = 12) ##Simulate the response variable y <- midas_sim(500, xx, theta0) x <- window(xx, start=start(y)) ##Fit restricted model mr <- midas_r(y~fmls(x,4*12-1,12,theta_h0)-1,list(y=y,x=x), start=list(x=c(-0.1,0.1,-0.1,-0.001))) ##Perform test (the expected result should be the acceptance of null) hAh_test(mr) ##Fit using gradient function ##The gradient function theta_h0_gradient<-function(p, dk,...) { i <- (1:dk-1) a <- exp(p[3]*i + p[4]*i^2) cbind(a, a*i, a*i*(p[1]+p[2]*i), a*i^2*(p[1]+p[2]*i)) } mr <- midas_r(y~fmls(x,4*12-1,12,theta_h0)-1,list(y=y,x=x), start=list(x=c(-0.1,0.1,-0.1,-0.001)), weight_gradients=list()) ##The test will use an user supplied gradient of weight function. See the ##help of midas_r on how to supply the gradient. hAh_test(mr)
Perform a test whether the restriction on MIDAS regression coefficients holds.
hAhr_test(x, PHI = vcovHAC(x$unrestricted, sandwich = FALSE))
hAhr_test(x, PHI = vcovHAC(x$unrestricted, sandwich = FALSE))
x |
MIDAS regression model with restricted coefficients, estimated with |
PHI |
the "meat" covariance matrix, defaults to |
Given MIDAS regression:
test the null hypothesis that the following restriction holds:
where .
a htest
object
Virmantas Kvedaras, Vaidotas Zemlys
Kvedaras V., Zemlys, V. The statistical content and empirical testing of the MIDAS restrictions
hAh_test
##The parameter function theta_h0 <- function(p, dk, ...) { i <- (1:dk-1) (p[1] + p[2]*i)*exp(p[3]*i + p[4]*i^2) } ##Generate coefficients theta0 <- theta_h0(c(-0.1,0.1,-0.1,-0.001),4*12) ##Plot the coefficients plot(theta0) ##Generate the predictor variable set.seed(13) xx <- ts(arima.sim(model = list(ar = 0.6), 600 * 12), frequency = 12) ##Simulate the response variable y <- midas_sim(500, xx, theta0) x <- window(xx, start=start(y)) ##Fit restricted model mr <- midas_r(y~fmls(x,4*12-1,12,theta_h0)-1, list(y=y,x=x), start=list(x=c(-0.1,0.1,-0.1,-0.001))) ##The gradient function theta_h0_gradient <-function(p, dk,...) { i <- (1:dk-1) a <- exp(p[3]*i + p[4]*i^2) cbind(a, a*i, a*i*(p[1]+p[2]*i), a*i^2*(p[1]+p[2]*i)) } ##Perform test (the expected result should be the acceptance of null) hAhr_test(mr) mr <- midas_r(y~fmls(x,4*12-1,12,theta_h0)-1, list(y=y,x=x), start=list(x=c(-0.1,0.1,-0.1,-0.001)), weight_gradients=list()) ##Use exact gradient. Note the hAhr_test(mr)
##The parameter function theta_h0 <- function(p, dk, ...) { i <- (1:dk-1) (p[1] + p[2]*i)*exp(p[3]*i + p[4]*i^2) } ##Generate coefficients theta0 <- theta_h0(c(-0.1,0.1,-0.1,-0.001),4*12) ##Plot the coefficients plot(theta0) ##Generate the predictor variable set.seed(13) xx <- ts(arima.sim(model = list(ar = 0.6), 600 * 12), frequency = 12) ##Simulate the response variable y <- midas_sim(500, xx, theta0) x <- window(xx, start=start(y)) ##Fit restricted model mr <- midas_r(y~fmls(x,4*12-1,12,theta_h0)-1, list(y=y,x=x), start=list(x=c(-0.1,0.1,-0.1,-0.001))) ##The gradient function theta_h0_gradient <-function(p, dk,...) { i <- (1:dk-1) a <- exp(p[3]*i + p[4]*i^2) cbind(a, a*i, a*i*(p[1]+p[2]*i), a*i^2*(p[1]+p[2]*i)) } ##Perform test (the expected result should be the acceptance of null) hAhr_test(mr) mr <- midas_r(y~fmls(x,4*12-1,12,theta_h0)-1, list(y=y,x=x), start=list(x=c(-0.1,0.1,-0.1,-0.001)), weight_gradients=list()) ##Use exact gradient. Note the hAhr_test(mr)
HAR(3)-RV model MIDAS weights specification
harstep(p, d, m)
harstep(p, d, m)
p |
parameters for Almon lag |
d |
number of the coefficients |
m |
the frequency, currently ignored. |
MIDAS weights for Heterogeneous Autoregressive model of Realized Volatilty (HAR-RV). It is assumed that month has 20 days.
vector of coefficients
Virmantas Kvedaras, Vaidotas Zemlys
Corsi, F., A Simple Approximate Long-Memory Model of Realized Volatility, Journal of Financial Econometrics Vol. 7 No. 2 (2009) 174-196
Gradient function for HAR(3)-RV model MIDAS weights specification
harstep_gradient(p, d, m)
harstep_gradient(p, d, m)
p |
parameters for Almon lag |
d |
number of the coefficients |
m |
the frequency, currently ignored. |
MIDAS weights for Heterogeneous Autoregressive model of Realized Volatilty (HAR-RV). It is assumed that month has 20 days.
vector of coefficients
Virmantas Kvedaras, Vaidotas Zemlys
Corsi, F., A Simple Approximate Long-Memory Model of Realized Volatility, Journal of Financial Econometrics Vol. 7 No. 2 (2009) 174-196
Creates a high frequency lag selection table for MIDAS regression model with given information criteria and minimum and maximum lags.
hf_lags_table( formula, data, start, from, to, IC = c("AIC", "BIC"), test = c("hAh_test"), Ofunction = "optim", weight_gradients = NULL, ... )
hf_lags_table( formula, data, start, from, to, IC = c("AIC", "BIC"), test = c("hAh_test"), Ofunction = "optim", weight_gradients = NULL, ... )
formula |
the formula for MIDAS regression, the lag selection is performed for the last MIDAS lag term in the formula |
data |
a list containing data with mixed frequencies |
start |
the starting values for optimisation |
from |
a named list, or named vector with lag numbers which are the beginings of MIDAS lag structures. The names should correspond to the MIDAS lag terms in the formula for which to do the lag selection. Value NA indicates lag start at zero |
to |
a named list where each element is a vector with two elements. The first element is the lag number from which the lag selection starts, the second is the lag number at which the lag selection ends. NA indicates lowest (highest) lag numbers possible. |
IC |
the information criteria which to compute |
test |
the names of statistical tests to perform on restricted model, p-values are reported in the columns of model selection table |
Ofunction |
see midasr |
weight_gradients |
see midas_r |
... |
additional parameters to optimisation function, see midas_r |
This function estimates models sequentially increasing the midas lag from kmin
to kmax
of the last term of the given formula
a midas_r_iclagtab
object which is the list with the following elements:
table |
the table where each row contains calculated information criteria for both restricted and unrestricted MIDAS regression model with given lag structure |
candlist |
the list containing fitted models |
IC |
the argument IC |
Virmantas Kvedaras, Vaidotas Zemlys
data("USunempr") data("USrealgdp") y <- diff(log(USrealgdp)) x <- window(diff(USunempr),start=1949) trend <- 1:length(y) mlr <- hf_lags_table(y ~ trend + fmls(x, 12, 12,nealmon), start = list(x=rep(0,3)), data = list(y = y, x = x, trend = trend), from=c(x=0),to=list(x=c(4,4))) mlr
data("USunempr") data("USrealgdp") y <- diff(log(USrealgdp)) x <- window(diff(USunempr),start=1949) trend <- 1:length(y) mlr <- hf_lags_table(y ~ trend + fmls(x, 12, 12,nealmon), start = list(x=rep(0,3)), data = list(y = y, x = x, trend = trend), from=c(x=0),to=list(x=c(4,4))) mlr
Estimate restricted MIDAS regression using non-linear least squares, when the regressor is I(1)
imidas_r( formula, data, start, Ofunction = "optim", weight_gradients = NULL, ... )
imidas_r( formula, data, start, Ofunction = "optim", weight_gradients = NULL, ... )
formula |
formula for restricted MIDAS regression. Formula must include |
data |
a named list containing data with mixed frequencies |
start |
the starting values for optimisation. Must be a list with named elements |
Ofunction |
the list with information which R function to use for optimisation
The list must have element named |
weight_gradients |
a named list containing gradient functions of weights. The weight gradient
function must return the matrix with dimensions |
... |
additional arguments supplied to optimisation function |
Given MIDAS regression:
estimate the parameters of the restriction
where , together with coefficients
corresponding to additional
low frequency regressors.
It is assumed that is a I(1) process, hence the special transformation is made.
After the transformation midas_r is used for estimation.
MIDAS regression involves times series with different frequencies.
The restriction function must return the restricted coefficients of the MIDAS regression.
a midas_r
object which is the list with the following elements:
coefficients |
the estimates of parameters of restrictions |
midas_coefficients |
the estimates of MIDAS coefficients of MIDAS regression |
model |
model data |
unrestricted |
unrestricted regression estimated using |
term_info |
the named list. Each element is a list with the information about the term, such as its frequency, function for weights, gradient function of weights, etc. |
fn0 |
optimisation function for non-linear least squares problem solved in restricted MIDAS regression |
rhs |
the function which evaluates the right-hand side of the MIDAS regression |
gen_midas_coef |
the function which generates the MIDAS coefficients of MIDAS regression |
opt |
the output of optimisation procedure |
argmap_opt |
the list containing the name of optimisation function together with arguments for optimisation function |
start_opt |
the starting values used in optimisation |
start_list |
the starting values as a list |
call |
the call to the function |
terms |
terms object |
gradient |
gradient of NLS objective function |
hessian |
hessian of NLS objective function |
gradD |
gradient function of MIDAS weight functions |
z_env |
the environment in which data is placed |
use_gradient |
TRUE if user supplied gradient is used, FALSE otherwise |
nobs |
the number of effective observations |
convergence |
the convergence message |
fitted.values |
the fitted values of MIDAS regression |
residuals |
the residuals of MIDAS regression |
Virmantas Kvedaras, Vaidotas Zemlys
midas_r.midas_r
theta.h0 <- function(p, dk) { i <- (1:dk-1)/100 pol <- p[3]*i + p[4]*i^2 (p[1] + p[2]*i)*exp(pol) } theta0 <- theta.h0(c(-0.1,10,-10,-10),4*12) xx <- ts(cumsum(rnorm(600*12)), frequency = 12) ##Simulate the response variable y <- midas_sim(500, xx, theta0) x <- window(xx, start=start(y)) imr <- imidas_r(y~fmls(x,4*12-1,12,theta.h0)-1,start=list(x=c(-0.1,10,-10,-10)))
theta.h0 <- function(p, dk) { i <- (1:dk-1)/100 pol <- p[3]*i + p[4]*i^2 (p[1] + p[2]*i)*exp(pol) } theta0 <- theta.h0(c(-0.1,10,-10,-10),4*12) xx <- ts(cumsum(rnorm(600*12)), frequency = 12) ##Simulate the response variable y <- midas_sim(500, xx, theta0) x <- window(xx, start=start(y)) imr <- imidas_r(y~fmls(x,4*12-1,12,theta.h0)-1,start=list(x=c(-0.1,10,-10,-10)))
Calculate MIDAS weights according to normalized log-Cauchy probability density function specification
lcauchyp(p, d, m)
lcauchyp(p, d, m)
p |
parameters for normalized log-Cauchy probability density function |
d |
number of coefficients |
m |
the frequency ratio, currently ignored |
vector of coefficients
Julius Vainora
Calculate gradient function for normalized log-Cauchy probability density function specification of MIDAS weights.
lcauchyp_gradient(p, d, m)
lcauchyp_gradient(p, d, m)
p |
parameters for normalized log-Cauchy probability density function |
d |
number of coefficients |
m |
the frequency ratio, currently ignored |
vector of coefficients
Julius Vainora
Creates a low frequency lag selection table for MIDAS regression model with given information criteria and minimum and maximum lags.
lf_lags_table( formula, data, start, from, to, IC = c("AIC", "BIC"), test = c("hAh_test"), Ofunction = "optim", weight_gradients = NULL, ... )
lf_lags_table( formula, data, start, from, to, IC = c("AIC", "BIC"), test = c("hAh_test"), Ofunction = "optim", weight_gradients = NULL, ... )
formula |
the formula for MIDAS regression, the lag selection is performed for the last MIDAS lag term in the formula |
data |
a list containing data with mixed frequencies |
start |
the starting values for optimisation |
from |
a named list, or named vector with high frequency (NB!) lag numbers which are the beginnings of MIDAS lag structures. The names should correspond to the MIDAS lag terms in the formula for which to do the lag selection. Value NA indicates lag start at zero |
to |
a named list where each element is a vector with two elements. The first element is the low frequency lag number from which the lag selection starts, the second is the low frequency lag number at which the lag selection ends. NA indicates lowest (highest) lag numbers possible. |
IC |
the information criteria which to compute |
test |
the names of statistical tests to perform on restricted model, p-values are reported in the columns of model selection table |
Ofunction |
see midasr |
weight_gradients |
see midas_r |
... |
additional parameters to optimisation function, see midas_r |
This function estimates models sequentially increasing the midas lag from kmin
to kmax
of the last term of the given formula
a midas_r_ic_table
object which is the list with the following elements:
table |
the table where each row contains calculated information criteria for both restricted and unrestricted MIDAS regression model with given lag structure |
candlist |
the list containing fitted models |
IC |
the argument IC |
Virmantas Kvedaras, Vaidotas Zemlys
data("USunempr") data("USrealgdp") y <- diff(log(USrealgdp)) x <- window(diff(USunempr),start=1949) trend <- 1:length(y) mlr <- lf_lags_table(y~trend+fmls(x,12,12,nealmon), start=list(x=rep(0,3)), from=c(x=0),to=list(x=c(3,4))) mlr
data("USunempr") data("USrealgdp") y <- diff(log(USrealgdp)) x <- window(diff(USunempr),start=1949) trend <- 1:length(y) mlr <- lf_lags_table(y~trend+fmls(x,12,12,nealmon), start=list(x=rep(0,3)), from=c(x=0),to=list(x=c(3,4))) mlr
Compute LSTR term for high frequency variable
lstr(X, theta, beta, sd_x = sd(c(X), na.rm = TRUE))
lstr(X, theta, beta, sd_x = sd(c(X), na.rm = TRUE))
X |
matrix, high frequency variable embedded in low frequency, output of mls |
theta |
vector, restriction coefficients for high frequency variable |
beta |
vector of length 4, parameters for LSTR term, slope and 3 LSTR parameters |
sd_x |
vector of length 1, defaults to standard deviation of X. |
a vector
Given the predictor variable, the weights and autoregressive coefficients, simulate MIDAS regression response variable.
midas_auto_sim( n, alpha, x, theta, rand_gen = rnorm, innov = rand_gen(n, ...), n_start = NA, ... )
midas_auto_sim( n, alpha, x, theta, rand_gen = rnorm, innov = rand_gen(n, ...), n_start = NA, ... )
n |
sample size. |
alpha |
autoregressive coefficients. |
x |
a high frequency predictor variable. |
theta |
a vector with MIDAS weights for predictor variable. |
rand_gen |
a function to generate the innovations, default is the normal distribution. |
innov |
an optional time series of innovations. |
n_start |
number of observations to omit for the burn.in. |
... |
additional arguments to function |
a ts
object
Virmantas Kvedaras, Vaidotas Zemlys
theta_h0 <- function(p, dk) { i <- (1:dk-1)/100 pol <- p[3]*i + p[4]*i^2 (p[1] + p[2]*i)*exp(pol) } ##Generate coefficients theta0 <- theta_h0(c(-0.1,10,-10,-10),4*12) ##Generate the predictor variable xx <- ts(arima.sim(model = list(ar = 0.6), 1000 * 12), frequency = 12) y <- midas_auto_sim(500, 0.5, xx, theta0, n_start = 200) x <- window(xx, start=start(y)) midas_r(y ~ mls(y, 1, 1) + fmls(x, 4*12-1, 12, theta_h0), start = list(x = c(-0.1, 10, -10, -10)))
theta_h0 <- function(p, dk) { i <- (1:dk-1)/100 pol <- p[3]*i + p[4]*i^2 (p[1] + p[2]*i)*exp(pol) } ##Generate coefficients theta0 <- theta_h0(c(-0.1,10,-10,-10),4*12) ##Generate the predictor variable xx <- ts(arima.sim(model = list(ar = 0.6), 1000 * 12), frequency = 12) y <- midas_auto_sim(500, 0.5, xx, theta0, n_start = 200) x <- window(xx, start=start(y)) midas_r(y ~ mls(y, 1, 1) + fmls(x, 4*12-1, 12, theta_h0), start = list(x = c(-0.1, 10, -10, -10)))
Function for fitting LSTR MIDAS regression without the formula interface
midas_lstr_plain( y, X, z = NULL, weight, start_lstr, start_x, start_z = NULL, method = c("Nelder-Mead"), ... )
midas_lstr_plain( y, X, z = NULL, weight, start_lstr, start_x, start_z = NULL, method = c("Nelder-Mead"), ... )
y |
model response |
X |
prepared matrix of high frequency variable lags for LSTR term |
z |
additional low frequency variables |
weight |
the weight function |
start_lstr |
the starting values for lstr term |
start_x |
the starting values for weight function |
start_z |
the starting values for additional low frequency variables |
method |
a method passed to optimx |
... |
additional parameters to optimx |
an object similar to midas_r
object
Virmantas Kvedaras, Vaidotas Zemlys
Simulate LSTR MIDAS regression model
midas_lstr_sim( n, m, theta, intercept, plstr, ar.x, ar.y, rand.gen = rnorm, n.start = NA, ... )
midas_lstr_sim( n, m, theta, intercept, plstr, ar.x, ar.y, rand.gen = rnorm, n.start = NA, ... )
n |
number of observations to simulate. |
m |
integer, frequency ratio |
theta |
vector, restriction coefficients for high frequency variable |
intercept |
vector of length 1, intercept for the model. |
plstr |
vector of length 4, slope for the LSTR term and LSTR parameters |
ar.x |
vector, AR parameters for simulating high frequency variable |
ar.y |
vector, AR parameters for AR part of the model |
rand.gen |
function, a function for generating the regression innovations, default is |
n.start |
integer, length of a 'burn-in' period. If NA, the default, a reasonable value is computed. |
... |
additional parameters to rand.gen |
a list
nnbeta <- function(p, k) nbeta(c(1, p), k) dgp <- midas_lstr_sim(250, m = 12, theta = nnbeta(c(2, 4), 24), intercept = c(1), plstr = c(1.5, 1, log(1), 1), ar.x = 0.9, ar.y = 0.5, n.start = 100 ) z <- cbind(1, mls(dgp$y, 1:2, 1)) colnames(z) <- c("Intercept", "y1", "y2") X <- mls(dgp$x, 0:23, 12) lstr_mod <- midas_lstr_plain(dgp$y, X, z, nnbeta, start_lstr = c(1.5, 1, 1, 1), start_x = c(2, 4), start_z = c(1, 0.5, 0) ) coef(lstr_mod)
nnbeta <- function(p, k) nbeta(c(1, p), k) dgp <- midas_lstr_sim(250, m = 12, theta = nnbeta(c(2, 4), 24), intercept = c(1), plstr = c(1.5, 1, log(1), 1), ar.x = 0.9, ar.y = 0.5, n.start = 100 ) z <- cbind(1, mls(dgp$y, 1:2, 1)) colnames(z) <- c("Intercept", "y1", "y2") X <- mls(dgp$x, 0:23, 12) lstr_mod <- midas_lstr_plain(dgp$y, X, z, nnbeta, start_lstr = c(1.5, 1, 1, 1), start_x = c(2, 4), start_z = c(1, 0.5, 0) ) coef(lstr_mod)
Function for fitting MMM MIDAS regression without the formula interface
midas_mmm_plain( y, X, z = NULL, weight, start_mmm, start_x, start_z = NULL, method = c("Nelder-Mead"), ... )
midas_mmm_plain( y, X, z = NULL, weight, start_mmm, start_x, start_z = NULL, method = c("Nelder-Mead"), ... )
y |
model response |
X |
prepared matrix of high frequency variable lags for MMM term |
z |
additional low frequency variables |
weight |
the weight function |
start_mmm |
the starting values for MMM term |
start_x |
the starting values for weight function |
start_z |
the starting values for additional low frequency variables |
method |
a method passed to optimx |
... |
additional parameters to optimx |
an object similar to midas_r
object
Virmantas Kvedaras, Vaidotas Zemlys
Simulate MMM MIDAS regression model
midas_mmm_sim( n, m, theta, intercept, pmmm, ar.x, ar.y, rand.gen = rnorm, n.start = NA, ... )
midas_mmm_sim( n, m, theta, intercept, pmmm, ar.x, ar.y, rand.gen = rnorm, n.start = NA, ... )
n |
number of observations to simulate. |
m |
integer, frequency ratio |
theta |
vector, restriction coefficients for high frequency variable |
intercept |
vector of length 1, intercept for the model. |
pmmm |
vector of length 2, slope for the MMM term and MMM parameter |
ar.x |
vector, AR parameters for simulating high frequency variable |
ar.y |
vector, AR parameters for AR part of the model |
rand.gen |
function, a function for generating the regression innovations, default is |
n.start |
integer, length of a 'burn-in' period. If NA, the default, a reasonable value is computed. |
... |
additional parameters to rand.gen |
a list
nnbeta <- function(p, k) nbeta(c(1, p), k) dgp <- midas_mmm_sim(250, m = 12, theta = nnbeta(c(2, 4), 24), intercept = c(1), pmmm = c(1.5, 1), ar.x = 0.9, ar.y = 0.5, n.start = 100 ) z <- cbind(1, mls(dgp$y, 1:2, 1)) colnames(z) <- c("Intercept", "y1", "y2") X <- mls(dgp$x, 0:23, 12) mmm_mod <- midas_mmm_plain(dgp$y, X, z, nnbeta, start_mmm = c(1.5, 1), start_x = c(2, 4), start_z = c(1, 0.5, 0) ) coef(mmm_mod)
nnbeta <- function(p, k) nbeta(c(1, p), k) dgp <- midas_mmm_sim(250, m = 12, theta = nnbeta(c(2, 4), 24), intercept = c(1), pmmm = c(1.5, 1), ar.x = 0.9, ar.y = 0.5, n.start = 100 ) z <- cbind(1, mls(dgp$y, 1:2, 1)) colnames(z) <- c("Intercept", "y1", "y2") X <- mls(dgp$x, 0:23, 12) mmm_mod <- midas_mmm_plain(dgp$y, X, z, nnbeta, start_mmm = c(1.5, 1), start_x = c(2, 4), start_z = c(1, 0.5, 0) ) coef(mmm_mod)
Estimate restricted MIDAS regression using non-linear least squares.
midas_nlpr(formula, data, start, Ofunction = "optim", ...)
midas_nlpr(formula, data, start, Ofunction = "optim", ...)
formula |
formula for restricted MIDAS regression or |
data |
a named list containing data with mixed frequencies |
start |
the starting values for optimisation. Must be a list with named elements. |
Ofunction |
the list with information which R function to use for optimisation. The list must have element named |
... |
additional arguments supplied to optimisation function |
Given MIDAS regression:
estimate the parameters of the restriction
Such model is a generalisation of so called ADL-MIDAS regression. It is not required that all the coefficients should be restricted, i.e the function
might be an identity function. Model with no restrictions is called U-MIDAS model. The regressors
must be of higher
(or of the same) frequency as the dependent variable
.
a midas_r
object which is the list with the following elements:
coefficients |
the estimates of parameters of restrictions |
midas_coefficients |
the estimates of MIDAS coefficients of MIDAS regression |
model |
model data |
unrestricted |
unrestricted regression estimated using |
term_info |
the named list. Each element is a list with the information about the term, such as its frequency, function for weights, gradient function of weights, etc. |
fn0 |
optimisation function for non-linear least squares problem solved in restricted MIDAS regression |
rhs |
the function which evaluates the right-hand side of the MIDAS regression |
gen_midas_coef |
the function which generates the MIDAS coefficients of MIDAS regression |
opt |
the output of optimisation procedure |
argmap_opt |
the list containing the name of optimisation function together with arguments for optimisation function |
start_opt |
the starting values used in optimisation |
start_list |
the starting values as a list |
call |
the call to the function |
terms |
terms object |
gradient |
gradient of NLS objective function |
hessian |
hessian of NLS objective function |
gradD |
gradient function of MIDAS weight functions |
Zenv |
the environment in which data is placed |
nobs |
the number of effective observations |
convergence |
the convergence message |
fitted.values |
the fitted values of MIDAS regression |
residuals |
the residuals of MIDAS regression |
Virmantas Kvedaras, Vaidotas Zemlys
Workhorse function for fitting restricted MIDAS regression
midas_nlpr.fit(x)
midas_nlpr.fit(x)
x |
|
midas_r
object
Vaidotas Zemlys
Function for fitting PL MIDAS regression without the formula interface
midas_pl_plain( y, X, z, p.ar = NULL, weight, degree = 1, start_bws, start_x, start_ar = NULL, method = c("Nelder-Mead"), ... )
midas_pl_plain( y, X, z, p.ar = NULL, weight, degree = 1, start_bws, start_x, start_ar = NULL, method = c("Nelder-Mead"), ... )
y |
model response |
X |
prepared matrix of high frequency variable lags for MMM term |
z |
a vector, data for the non-parametric part |
p.ar |
length of AR part |
weight |
the weight function |
degree |
the degree of local polynomial |
start_bws |
the starting values bandwith |
start_x |
the starting values for weight function |
start_ar |
the starting values for AR part. Should be the same length as |
method |
a method passed to optim |
... |
additional parameters to optim |
an object similar to midas_r
object
Virmantas Kvedaras, Vaidotas Zemlys
Simulate PL MIDAS regression model
midas_pl_sim( n, m, theta, gfun, ar.x, ar.y, rand.gen = rnorm, n.start = NA, ... )
midas_pl_sim( n, m, theta, gfun, ar.x, ar.y, rand.gen = rnorm, n.start = NA, ... )
n |
number of observations to simulate. |
m |
integer, frequency ratio |
theta |
vector, restriction coefficients for high frequency variable |
gfun |
function, a function which takes a single index |
ar.x |
vector, AR parameters for simulating high frequency variable |
ar.y |
vector, AR parameters for AR part of the model |
rand.gen |
function, a function for generating the regression innovations, default is |
n.start |
integer, length of a 'burn-in' period. If NA, the default, a reasonable value is computed. |
... |
additional parameters to rand.gen |
a list
nnbeta <- function(p, k) nbeta(c(1, p), k) dgp <- midas_pl_sim(250, m = 12, theta = nnbeta(c(2, 4), 24), gfun = function(x) 0.25 * x^3, ar.x = 0.9, ar.y = 0.5, n.start = 100 )
nnbeta <- function(p, k) nbeta(c(1, p), k) dgp <- midas_pl_sim(250, m = 12, theta = nnbeta(c(2, 4), 24), gfun = function(x) 0.25 * x^3, ar.x = 0.9, ar.y = 0.5, n.start = 100 )
Estimate restricted MIDAS quantile regression using nonlinear quantile regression
midas_qr( formula, data, tau = 0.5, start, Ofunction = "nlrq", weight_gradients = NULL, guess_start = TRUE, ... )
midas_qr( formula, data, tau = 0.5, start, Ofunction = "nlrq", weight_gradients = NULL, guess_start = TRUE, ... )
formula |
formula for restricted MIDAS regression or |
data |
a named list containing data with mixed frequencies |
tau |
quantile |
start |
the starting values for optimisation. Must be a list with named elements. |
Ofunction |
the list with information which R function to use for optimisation. The list must have element named |
weight_gradients |
a named list containing gradient functions of weights. The weight gradient function must return the matrix with dimensions
|
guess_start |
logical, if TRUE tries certain strategy to improve starting values |
... |
additional arguments supplied to optimisation function |
a midas_r
object which is the list with the following elements:
coefficients |
the estimates of parameters of restrictions |
midas_coefficients |
the estimates of MIDAS coefficients of MIDAS regression |
model |
model data |
unrestricted |
unrestricted regression estimated using |
term_info |
the named list. Each element is a list with the information about the term, such as its frequency, function for weights, gradient function of weights, etc. |
fn0 |
optimisation function for non-linear least squares problem solved in restricted MIDAS regression |
rhs |
the function which evaluates the right-hand side of the MIDAS regression |
gen_midas_coef |
the function which generates the MIDAS coefficients of MIDAS regression |
opt |
the output of optimisation procedure |
argmap_opt |
the list containing the name of optimisation function together with arguments for optimisation function |
start_opt |
the starting values used in optimisation |
start_list |
the starting values as a list |
call |
the call to the function |
terms |
terms object |
gradient |
gradient of NLS objective function |
hessian |
hessian of NLS objective function |
gradD |
gradient function of MIDAS weight functions |
Zenv |
the environment in which data is placed |
use_gradient |
TRUE if user supplied gradient is used, FALSE otherwise |
nobs |
the number of effective observations |
convergence |
the convergence message |
fitted.values |
the fitted values of MIDAS regression |
residuals |
the residuals of MIDAS regression |
Vaidotas Zemlys-Balevicius
##Take the same example as in midas_r theta_h0 <- function(p, dk, ...) { i <- (1:dk-1)/100 pol <- p[3]*i + p[4]*i^2 (p[1] + p[2]*i)*exp(pol) } ##Generate coefficients theta0 <- theta_h0(c(-0.1,10,-10,-10),4*12) ##Plot the coefficients plot(theta0) ##Generate the predictor variable xx <- ts(arima.sim(model = list(ar = 0.6), 600 * 12), frequency = 12) ##Simulate the response variable y <- midas_sim(500, xx, theta0) x <- window(xx, start=start(y)) ##Fit quantile regression. All the coefficients except intercept should be constant. ##Intercept coefficient should correspond to quantile function of regression errors. mr <- midas_qr(y~fmls(x,4*12-1,12,theta_h0), tau = c(0.1, 0.5, 0.9), list(y=y,x=x), start=list(x=c(-0.1,10,-10,-10))) mr
##Take the same example as in midas_r theta_h0 <- function(p, dk, ...) { i <- (1:dk-1)/100 pol <- p[3]*i + p[4]*i^2 (p[1] + p[2]*i)*exp(pol) } ##Generate coefficients theta0 <- theta_h0(c(-0.1,10,-10,-10),4*12) ##Plot the coefficients plot(theta0) ##Generate the predictor variable xx <- ts(arima.sim(model = list(ar = 0.6), 600 * 12), frequency = 12) ##Simulate the response variable y <- midas_sim(500, xx, theta0) x <- window(xx, start=start(y)) ##Fit quantile regression. All the coefficients except intercept should be constant. ##Intercept coefficient should correspond to quantile function of regression errors. mr <- midas_qr(y~fmls(x,4*12-1,12,theta_h0), tau = c(0.1, 0.5, 0.9), list(y=y,x=x), start=list(x=c(-0.1,10,-10,-10))) mr
Estimate restricted MIDAS regression using non-linear least squares.
midas_r( formula, data, start, Ofunction = "optim", weight_gradients = NULL, ... )
midas_r( formula, data, start, Ofunction = "optim", weight_gradients = NULL, ... )
formula |
formula for restricted MIDAS regression or |
data |
a named list containing data with mixed frequencies |
start |
the starting values for optimisation. Must be a list with named elements. |
Ofunction |
the list with information which R function to use for optimisation. The list must have element named |
weight_gradients |
a named list containing gradient functions of weights. The weight gradient function must return the matrix with dimensions
|
... |
additional arguments supplied to optimisation function |
Given MIDAS regression:
estimate the parameters of the restriction
Such model is a generalisation of so called ADL-MIDAS regression. It is not required that all the coefficients should be restricted, i.e the function
might be an identity function. Model with no restrictions is called U-MIDAS model. The regressors
must be of higher
(or of the same) frequency as the dependent variable
.
MIDAS-AR* (a model with a common factor, see (Clements and Galvao, 2008)) can be estimated by specifying additional argument, see an example.
The restriction function must return the restricted coefficients of the MIDAS regression.
a midas_r
object which is the list with the following elements:
coefficients |
the estimates of parameters of restrictions |
midas_coefficients |
the estimates of MIDAS coefficients of MIDAS regression |
model |
model data |
unrestricted |
unrestricted regression estimated using |
term_info |
the named list. Each element is a list with the information about the term, such as its frequency, function for weights, gradient function of weights, etc. |
fn0 |
optimisation function for non-linear least squares problem solved in restricted MIDAS regression |
rhs |
the function which evaluates the right-hand side of the MIDAS regression |
gen_midas_coef |
the function which generates the MIDAS coefficients of MIDAS regression |
opt |
the output of optimisation procedure |
argmap_opt |
the list containing the name of optimisation function together with arguments for optimisation function |
start_opt |
the starting values used in optimisation |
start_list |
the starting values as a list |
call |
the call to the function |
terms |
terms object |
gradient |
gradient of NLS objective function |
hessian |
hessian of NLS objective function |
gradD |
gradient function of MIDAS weight functions |
Zenv |
the environment in which data is placed |
use_gradient |
TRUE if user supplied gradient is used, FALSE otherwise |
nobs |
the number of effective observations |
convergence |
the convergence message |
fitted.values |
the fitted values of MIDAS regression |
residuals |
the residuals of MIDAS regression |
Virmantas Kvedaras, Vaidotas Zemlys
Clements, M. and Galvao, A., Macroeconomic Forecasting With Mixed-Frequency Data: Forecasting Output Growth in the United States, Journal of Business and Economic Statistics, Vol.26 (No.4), (2008) 546-554
##The parameter function theta_h0 <- function(p, dk, ...) { i <- (1:dk-1)/100 pol <- p[3]*i + p[4]*i^2 (p[1] + p[2]*i)*exp(pol) } ##Generate coefficients theta0 <- theta_h0(c(-0.1,10,-10,-10),4*12) ##Plot the coefficients plot(theta0) ##Generate the predictor variable xx <- ts(arima.sim(model = list(ar = 0.6), 600 * 12), frequency = 12) ##Simulate the response variable y <- midas_sim(500, xx, theta0) x <- window(xx, start=start(y)) ##Fit restricted model mr <- midas_r(y~fmls(x,4*12-1,12,theta_h0)-1, list(y=y,x=x), start=list(x=c(-0.1,10,-10,-10))) ##Include intercept and trend in regression mr_it <- midas_r(y~fmls(x,4*12-1,12,theta_h0)+trend, list(data.frame(y=y,trend=1:500),x=x), start=list(x=c(-0.1,10,-10,-10))) data("USrealgdp") data("USunempr") y.ar <- diff(log(USrealgdp)) xx <- window(diff(USunempr), start = 1949) trend <- 1:length(y.ar) ##Fit AR(1) model mr_ar <- midas_r(y.ar ~ trend + mls(y.ar, 1, 1) + fmls(xx, 11, 12, nealmon), start = list(xx = rep(0, 3))) ##First order MIDAS-AR* restricted model mr_arstar <- midas_r(y.ar ~ trend + mls(y.ar, 1, 1, "*") + fmls(xx, 11, 12, nealmon), start = list(xx = rep(0, 3)))
##The parameter function theta_h0 <- function(p, dk, ...) { i <- (1:dk-1)/100 pol <- p[3]*i + p[4]*i^2 (p[1] + p[2]*i)*exp(pol) } ##Generate coefficients theta0 <- theta_h0(c(-0.1,10,-10,-10),4*12) ##Plot the coefficients plot(theta0) ##Generate the predictor variable xx <- ts(arima.sim(model = list(ar = 0.6), 600 * 12), frequency = 12) ##Simulate the response variable y <- midas_sim(500, xx, theta0) x <- window(xx, start=start(y)) ##Fit restricted model mr <- midas_r(y~fmls(x,4*12-1,12,theta_h0)-1, list(y=y,x=x), start=list(x=c(-0.1,10,-10,-10))) ##Include intercept and trend in regression mr_it <- midas_r(y~fmls(x,4*12-1,12,theta_h0)+trend, list(data.frame(y=y,trend=1:500),x=x), start=list(x=c(-0.1,10,-10,-10))) data("USrealgdp") data("USunempr") y.ar <- diff(log(USrealgdp)) xx <- window(diff(USunempr), start = 1949) trend <- 1:length(y.ar) ##Fit AR(1) model mr_ar <- midas_r(y.ar ~ trend + mls(y.ar, 1, 1) + fmls(xx, 11, 12, nealmon), start = list(xx = rep(0, 3))) ##First order MIDAS-AR* restricted model mr_arstar <- midas_r(y.ar ~ trend + mls(y.ar, 1, 1, "*") + fmls(xx, 11, 12, nealmon), start = list(xx = rep(0, 3)))
Creates a weight and lag selection table for MIDAS regression model with given information criteria and minimum and maximum lags.
midas_r_ic_table( formula, data = NULL, start = NULL, table, IC = c("AIC", "BIC"), test = c("hAh_test"), Ofunction = "optim", weight_gradients = NULL, show_progress = TRUE, ... )
midas_r_ic_table( formula, data = NULL, start = NULL, table, IC = c("AIC", "BIC"), test = c("hAh_test"), Ofunction = "optim", weight_gradients = NULL, show_progress = TRUE, ... )
formula |
the formula for MIDAS regression, the lag selection is performed for the last MIDAS lag term in the formula |
data |
a list containing data with mixed frequencies |
start |
the starting values for optimisation excluding the starting values for the last term |
table |
an wls_table object, see expand_weights_lags |
IC |
the names of information criteria which to compute |
test |
the names of statistical tests to perform on restricted model, p-values are reported in the columns of model selection table |
Ofunction |
see midasr |
weight_gradients |
see midas_r |
show_progress |
logical, TRUE to show progress bar, FALSE for silent evaluation |
... |
additional parameters to optimisation function, see midas_r |
This function estimates models sequentially increasing the midas lag from kmin
to kmax
and varying the weights of the last term of the given formula
a midas_r_ic_table
object which is the list with the following elements:
table |
the table where each row contains calculated information criteria for both restricted and unrestricted MIDAS regression model with given lag structure |
candlist |
the list containing fitted models |
IC |
the argument IC |
Virmantas Kvedaras, Vaidotas Zemlys
data("USunempr") data("USrealgdp") y <- diff(log(USrealgdp)) x <- window(diff(USunempr),start=1949) trend <- 1:length(y) mwlr <- midas_r_ic_table(y~trend+fmls(x,12,12,nealmon), table=list(x=list(weights= as.list(c("nealmon","nealmon","nbeta")), lags=list(0:4,0:5,0:6), starts=list(rep(0,3),rep(0,3,),c(1,1,1,0))))) mwlr
data("USunempr") data("USrealgdp") y <- diff(log(USrealgdp)) x <- window(diff(USunempr),start=1949) trend <- 1:length(y) mwlr <- midas_r_ic_table(y~trend+fmls(x,12,12,nealmon), table=list(x=list(weights= as.list(c("nealmon","nealmon","nbeta")), lags=list(0:4,0:5,0:6), starts=list(rep(0,3),rep(0,3,),c(1,1,1,0))))) mwlr
Estimates non-parametric MIDAS regression
midas_r_np(formula, data, lambda = NULL)
midas_r_np(formula, data, lambda = NULL)
formula |
formula specifying MIDAS regression |
data |
a named list containing data with mixed frequencies |
lambda |
smoothing parameter, defaults to |
Estimates non-parametric MIDAS regression accodring Breitung et al.
a midas_r_np
object
Vaidotas Zemlys
Breitung J, Roling C, Elengikal S (2013). Forecasting inflation rates using daily data: A nonparametric MIDAS approach Working paper, URL http://www.ect.uni-bonn.de/mitarbeiter/joerg-breitung/npmidas.
data("USunempr") data("USrealgdp") y <- diff(log(USrealgdp)) x <- window(diff(USunempr),start=1949) trend <- 1:length(y) midas_r_np(y~trend+fmls(x,12,12))
data("USunempr") data("USrealgdp") y <- diff(log(USrealgdp)) x <- window(diff(USunempr),start=1949) trend <- 1:length(y) midas_r_np(y~trend+fmls(x,12,12))
Function for fitting MIDAS regression without the formula interface
midas_r_plain( y, X, z = NULL, weight, grw = NULL, startx, startz = NULL, method = c("Nelder-Mead", "BFGS"), ... )
midas_r_plain( y, X, z = NULL, weight, grw = NULL, startx, startz = NULL, method = c("Nelder-Mead", "BFGS"), ... )
y |
model response |
X |
prepared matrix of high frequency variable lags |
z |
additional low frequency variables |
weight |
the weight function |
grw |
the gradient of weight function |
startx |
the starting values for weight function |
startz |
the starting values for additional low frequency variables |
method |
a method passed to optimx |
... |
additional parameters to optimx |
an object similar to midas_r
object
Virmantas Kvedaras, Vaidotas Zemlys
data("USunempr") data("USrealgdp") y <- diff(log(USrealgdp)) x <- window(diff(USunempr),start=1949) trend <- 1:length(y) X<-fmls(x,11,12) midas_r_plain(y,X,trend,weight=nealmon,startx=c(0,0,0))
data("USunempr") data("USrealgdp") y <- diff(log(USrealgdp)) x <- window(diff(USunempr),start=1949) trend <- 1:length(y) X<-fmls(x,11,12) midas_r_plain(y,X,trend,weight=nealmon,startx=c(0,0,0))
Workhorse function for fitting restricted MIDAS regression
midas_r.fit(x)
midas_r.fit(x)
x |
|
midas_r
object
Vaidotas Zemlys
Function for fitting SI MIDAS regression without the formula interface
midas_si_plain( y, X, p.ar = NULL, weight, degree = 1, start_bws, start_x, start_ar = NULL, method = "Nelder-Mead", ... )
midas_si_plain( y, X, p.ar = NULL, weight, degree = 1, start_bws, start_x, start_ar = NULL, method = "Nelder-Mead", ... )
y |
model response |
X |
prepared matrix of high frequency variable lags for MMM term |
p.ar |
length of AR part |
weight |
the weight function |
degree |
the degree of local polynomial |
start_bws |
the starting values bandwith |
start_x |
the starting values for weight function |
start_ar |
the starting values for AR part. Should be the same length as |
method |
a method passed to optim, defaults to Nelder-Mead |
... |
additional parameters to optim |
an object similar to midas_r
object
Virmantas Kvedaras, Vaidotas Zemlys
Simulate SI MIDAS regression model
midas_si_sim( n, m, theta, gfun, ar.x, ar.y, rand.gen = rnorm, n.start = NA, ... )
midas_si_sim( n, m, theta, gfun, ar.x, ar.y, rand.gen = rnorm, n.start = NA, ... )
n |
number of observations to simulate. |
m |
integer, frequency ratio |
theta |
vector, restriction coefficients for high frequency variable |
gfun |
function, a function which takes a single index |
ar.x |
vector, AR parameters for simulating high frequency variable |
ar.y |
vector, AR parameters for AR part of the model |
rand.gen |
function, a function for generating the regression innovations, default is |
n.start |
integer, length of a 'burn-in' period. If NA, the default, a reasonable value is computed. |
... |
additional parameters to rand.gen |
a list
nnbeta <- function(p, k) nbeta(c(1, p), k) dgp <- midas_si_sim(250, m = 12, theta = nnbeta(c(2, 4), 24), gfun = function(x) 0.03 * x^3, ar.x = 0.9, ar.y = 0.5, n.start = 100 )
nnbeta <- function(p, k) nbeta(c(1, p), k) dgp <- midas_si_sim(250, m = 12, theta = nnbeta(c(2, 4), 24), gfun = function(x) 0.03 * x^3, ar.x = 0.9, ar.y = 0.5, n.start = 100 )
Given the predictor variable and the coefficients simulate MIDAS regression response variable.
midas_sim(n, x, theta, rand_gen = rnorm, innov = rand_gen(n, ...), ...)
midas_sim(n, x, theta, rand_gen = rnorm, innov = rand_gen(n, ...), ...)
n |
The sample size |
x |
a |
theta |
a vector with MIDAS regression coefficients |
rand_gen |
the function which generates the sample of innovations, the default is |
innov |
the vector with innovations, the default is NULL, i.e. innovations are generated using argument |
... |
additional arguments to |
MIDAS regression with one predictor variable has the following form:
where is the frequency ratio and
is the number of high frequency lags included in the regression.
MIDAS regression involves times series with different frequencies. In R
the frequency property is set when creating time series objects
ts
. Hence the frequency ratio which figures in MIDAS regression is calculated from frequency property of time series objects supplied.
a ts
object
Virmantas Kvedaras, Vaidotas Zemlys
##The parameter function theta_h0 <- function(p, dk) { i <- (1:dk-1)/100 pol <- p[3]*i + p[4]*i^2 (p[1] + p[2]*i)*exp(pol) } ##Generate coefficients theta0 <- theta_h0(c(-0.1,10,-10,-10),4*12) ##Plot the coefficients plot(theta0) ##Generate the predictor variable, leave 4 low frequency lags of data for burn-in. xx <- ts(arima.sim(model = list(ar = 0.6), 600 * 12), frequency = 12) ##Simulate the response variable y <- midas_sim(500, xx, theta0) x <- window(xx, start=start(y)) midas_r(y ~ mls(y, 1, 1) + fmls(x, 4*12-1, 12, theta_h0), start = list(x = c(-0.1, 10, -10, -10)))
##The parameter function theta_h0 <- function(p, dk) { i <- (1:dk-1)/100 pol <- p[3]*i + p[4]*i^2 (p[1] + p[2]*i)*exp(pol) } ##Generate coefficients theta0 <- theta_h0(c(-0.1,10,-10,-10),4*12) ##Plot the coefficients plot(theta0) ##Generate the predictor variable, leave 4 low frequency lags of data for burn-in. xx <- ts(arima.sim(model = list(ar = 0.6), 600 * 12), frequency = 12) ##Simulate the response variable y <- midas_sim(500, xx, theta0) x <- window(xx, start=start(y)) midas_r(y ~ mls(y, 1, 1) + fmls(x, 4*12-1, 12, theta_h0), start = list(x = c(-0.1, 10, -10, -10)))
Estimate semi-parametric MIDAS regression using non-linear least squares.
midas_sp(formula, data, bws, start, degree = 1, Ofunction = "optim", ...)
midas_sp(formula, data, bws, start, degree = 1, Ofunction = "optim", ...)
formula |
formula for restricted MIDAS regression or |
data |
a named list containing data with mixed frequencies |
bws |
a bandwith specification. Note you need to supply logarithm value of the bandwith. |
start |
the starting values for optimisation. Must be a list with named elements. |
degree |
the degree of local polynomial. 0 corresponds to local-constant, 1 local-linear. For univariate models higher values can be provided. |
Ofunction |
the list with information which R function to use for optimisation. The list must have element named |
... |
additional arguments supplied to optimisation function |
Given MIDAS regression:
estimate the parameters of the restriction
Such model is a generalisation of so called ADL-MIDAS regression. It is not required that all the coefficients should be restricted, i.e the function
might be an identity function. The regressors
must be of higher
(or of the same) frequency as the dependent variable
.
a midas_sp
object which is the list with the following elements:
coefficients |
the estimates of parameters of restrictions |
midas_coefficients |
the estimates of MIDAS coefficients of MIDAS regression |
model |
model data |
unrestricted |
unrestricted regression estimated using |
term_info |
the named list. Each element is a list with the information about the term, such as its frequency, function for weights, gradient function of weights, etc. |
fn0 |
optimisation function for non-linear least squares problem solved in restricted MIDAS regression |
rhs |
the function which evaluates the right-hand side of the MIDAS regression |
gen_midas_coef |
the function which generates the MIDAS coefficients of MIDAS regression |
opt |
the output of optimisation procedure |
argmap_opt |
the list containing the name of optimisation function together with arguments for optimisation function |
start_opt |
the starting values used in optimisation |
start_list |
the starting values as a list |
call |
the call to the function |
terms |
terms object |
gradient |
gradient of NLS objective function |
hessian |
hessian of NLS objective function |
gradD |
gradient function of MIDAS weight functions |
Zenv |
the environment in which data is placed |
nobs |
the number of effective observations |
convergence |
the convergence message |
fitted.values |
the fitted values of MIDAS regression |
residuals |
the residuals of MIDAS regression |
Virmantas Kvedaras, Vaidotas Zemlys-Balevičius
Estimate unrestricted MIDAS regression using OLS. This function is a wrapper for lm
.
midas_u(formula, data, ...)
midas_u(formula, data, ...)
formula |
MIDAS regression model formula |
data |
a named list containing data with mixed frequencies |
... |
further arguments, which could be passed to |
MIDAS regression has the following form:
where ,
are regressors of higher (or similar) frequency than
.
Given certain assumptions the coefficients can be estimated using usual OLS and they have the familiar properties associated with simple linear regression.
lm
object.
Virmantas Kvedaras, Vaidotas Zemlys
Kvedaras V., Zemlys, V. Testing the functional constraints on parameters in regressions with variables of different frequency Economics Letters 116 (2012) 250-254
##The parameter function theta_h0 <- function(p, dk, ...) { i <- (1:dk-1)/100 pol <- p[3]*i + p[4]*i^2 (p[1] + p[2]*i)*exp(pol) } ##Generate coefficients theta0 <- theta_h0(c(-0.1,10,-10,-10),4*12) ##Plot the coefficients ##Do not run #plot(theta0) ##' ##Generate the predictor variable xx <- ts(arima.sim(model = list(ar = 0.6), 600 * 12), frequency = 12) ##Simulate the response variable y <- midas_sim(500, xx, theta0) x <- window(xx, start=start(y)) ##Create low frequency data.frame ldt <- data.frame(y=y,trend=1:length(y)) ##Create high frequency data.frame hdt <- data.frame(x=window(x, start=start(y))) ##Fit unrestricted model mu <- midas_u(y~fmls(x,2,12)-1, list(ldt, hdt)) ##Include intercept and trend in regression mu_it <- midas_u(y~fmls(x,2,12)+trend, list(ldt, hdt)) ##Pass data as partialy named list mu_it <- midas_u(y~fmls(x,2,12)+trend, list(ldt, x=hdt$x))
##The parameter function theta_h0 <- function(p, dk, ...) { i <- (1:dk-1)/100 pol <- p[3]*i + p[4]*i^2 (p[1] + p[2]*i)*exp(pol) } ##Generate coefficients theta0 <- theta_h0(c(-0.1,10,-10,-10),4*12) ##Plot the coefficients ##Do not run #plot(theta0) ##' ##Generate the predictor variable xx <- ts(arima.sim(model = list(ar = 0.6), 600 * 12), frequency = 12) ##Simulate the response variable y <- midas_sim(500, xx, theta0) x <- window(xx, start=start(y)) ##Create low frequency data.frame ldt <- data.frame(y=y,trend=1:length(y)) ##Create high frequency data.frame hdt <- data.frame(x=window(x, start=start(y))) ##Fit unrestricted model mu <- midas_u(y~fmls(x,2,12)-1, list(ldt, hdt)) ##Include intercept and trend in regression mu_it <- midas_u(y~fmls(x,2,12)+trend, list(ldt, hdt)) ##Pass data as partialy named list mu_it <- midas_u(y~fmls(x,2,12)+trend, list(ldt, x=hdt$x))
Create a matrix of selected MIDAS lags
mls(x, k, m, ...)
mls(x, k, m, ...)
x |
a vector |
k |
a vector of lag orders, zero denotes contemporaneous lag. |
m |
frequency ratio |
... |
further arguments used in fitting MIDAS regression |
The function checks whether high frequency data is complete, i.e. m
must divide length(x)
.
a matrix containing the lags
Virmantas Kvedaras, Vaidotas Zemlys
## Quarterly frequency data x <- 1:16 ## Create MIDAS lag for use with yearly data mls(x,0:3,4) ## Do not use contemporaneous lag mls(x,1:3,4) ## Compares with embed when m=1 embed(x,2) mls(x,0:1,1)
## Quarterly frequency data x <- 1:16 ## Create MIDAS lag for use with yearly data mls(x,0:3,4) ## Do not use contemporaneous lag mls(x,1:3,4) ## Compares with embed when m=1 embed(x,2) mls(x,0:1,1)
MIDAS lag structure with dates
mlsd(x, k, y, ...)
mlsd(x, k, y, ...)
x |
a vector, of high frequency time series. Must be zoo or ts object |
k |
lags, a vector |
y |
a vector of low frequency time series. Must be zoo or ts object |
... |
further arguments used in fitting MIDAS regression |
High frequency time series is aligned with low frequency time series using date information. Then the high frequency lags are calculated.
To align the time series the low frequency series index needs to be extended by one low frequency period into the past and into the future. If supplied time series object does not support extending time index, a simple heuristic is used.
It is expected that time index for zoo objects can be converted to POSIXct format.
a matrix containing the lags
Virmantas Kvedaras, Vaidotas Zemlys-Balevičius
# Example with ts objects x <- ts(c(1:144), start = c(1980, 1), frequency = 12) y <- ts(c(1:12), start = 1980, frequency = 1) # msld and mls should give the same results m1 <- mlsd(x, 0:5, y) m2 <- mls(x, 0:5, 12) sum(abs(m1 - m2)) # Example with zooreg # Convert x to zooreg object using yearmon time index ## Not run: xz <- zoo::as.zooreg(x) yz <- zoo::zoo(as.numeric(y), order.by = as.Date(paste0(1980 + 0:11, "-01-01"))) # Heuristic works here m3 <- mlsd(xz, 0:5, yz) sum(abs(m3 - m1)) ## End(Not run)
# Example with ts objects x <- ts(c(1:144), start = c(1980, 1), frequency = 12) y <- ts(c(1:12), start = 1980, frequency = 1) # msld and mls should give the same results m1 <- mlsd(x, 0:5, y) m2 <- mls(x, 0:5, 12) sum(abs(m1 - m2)) # Example with zooreg # Convert x to zooreg object using yearmon time index ## Not run: xz <- zoo::as.zooreg(x) yz <- zoo::zoo(as.numeric(y), order.by = as.Date(paste0(1980 + 0:11, "-01-01"))) # Heuristic works here m3 <- mlsd(xz, 0:5, yz) sum(abs(m3 - m1)) ## End(Not run)
Compute MMM term for high frequency variable
mmm(X, theta, beta, ...)
mmm(X, theta, beta, ...)
X |
matrix, high frequency variable embedded in low frequency, output of mls |
theta |
vector, restriction coefficients for high frequency variable |
beta |
vector of length 2, parameters for MMM term, slope and MMM parameter. |
... |
currently not used |
a vector
Selects the model with minimum of given information criteria and model type
modsel( x, IC = x$IC[1], test = x$test[1], type = c("restricted", "unrestricted"), print = TRUE )
modsel( x, IC = x$IC[1], test = x$test[1], type = c("restricted", "unrestricted"), print = TRUE )
x |
a midas_r_ic_table object |
IC |
the name of information criteria to base the choosing of the model |
test |
the name of the test for which to print out the p-value |
type |
the type of MIDAS model, either restricted or unrestricted |
print |
logical, if TRUE, prints the summary of the best model. |
This function selects the model from the model selection table for which the chosen information criteria achieves the smallest value. The function works with model tables produced by functions lf_lags_table, hf_lags_table, amidas_table and midas_r_ic_table.
(invisibly) the best model based on information criteria, midas_r object
Virmantas Kvedaras, Vaidotas Zemlys
data("USunempr") data("USrealgdp") y <- diff(log(USrealgdp)) x <- window(diff(USunempr),start=1949) trend <- 1:length(y) mhfr <- hf_lags_table(y~trend+fmls(x,12,12,nealmon), start=list(x=rep(0,3)), from=list(x=0),to=list(x=c(4,6))) mlfr <- lf_lags_table(y~trend+fmls(x,12,12,nealmon), start=list(x=rep(0,3)), from=list(x=0),to=list(x=c(2,3))) modsel(mhfr,"BIC","unrestricted") modsel(mlfr,"BIC","unrestricted")
data("USunempr") data("USrealgdp") y <- diff(log(USrealgdp)) x <- window(diff(USunempr),start=1949) trend <- 1:length(y) mhfr <- hf_lags_table(y~trend+fmls(x,12,12,nealmon), start=list(x=rep(0,3)), from=list(x=0),to=list(x=c(4,6))) mlfr <- lf_lags_table(y~trend+fmls(x,12,12,nealmon), start=list(x=rep(0,3)), from=list(x=0),to=list(x=c(2,3))) modsel(mhfr,"BIC","unrestricted") modsel(mlfr,"BIC","unrestricted")
Calculate MIDAS weights according to normalized Nakagami probability density function specification
nakagamip(p, d, m)
nakagamip(p, d, m)
p |
parameters for normalized Nakagami probability density function |
d |
number of coefficients |
m |
the frequency ratio, currently ignored |
vector of coefficients
Julius Vainora
Calculate gradient function for normalized Nakagami probability density function specification of MIDAS weights.
nakagamip_gradient(p, d, m)
nakagamip_gradient(p, d, m)
p |
parameters for normalized Nakagami probability density function |
d |
number of coefficients |
m |
the frequency ratio, currently ignored |
vector of coefficients
Julius Vainora
Calculate MIDAS weights according to normalized beta probability density function specification
nbeta(p, d, m)
nbeta(p, d, m)
p |
parameters for normalized beta probability density function |
d |
number of coefficients |
m |
the frequency ratio, currently ignored |
vector of coefficients
Virmantas Kvedaras, Vaidotas Zemlys
Calculate gradient function for normalized beta probability density function specification of MIDAS weights.
nbeta_gradient(p, d, m)
nbeta_gradient(p, d, m)
p |
parameters for normalized beta probability density function |
d |
number of coefficients |
m |
the frequency ratio, currently ignored |
vector of coefficients
Virmantas Kvedaras, Vaidotas Zemlys
Calculate MIDAS weights according to normalized beta probability density function specification. Compatible with the specification in MATLAB toolbox.
nbetaMT(p, d, m)
nbetaMT(p, d, m)
p |
parameters for normalized beta probability density function |
d |
number of coefficients |
m |
the frequency ratio, currently ignored |
vector of coefficients
Virmantas Kvedaras, Vaidotas Zemlys
Calculate gradient function for normalized beta probability density function specification of MIDAS weights.
nbetaMT_gradient(p, d, m)
nbetaMT_gradient(p, d, m)
p |
parameters for normalized beta probability density function |
d |
number of coefficients |
m |
the frequency ratio, currently ignored |
vector of coefficients
Virmantas Kvedaras, Vaidotas Zemlys
Calculate normalized exponential Almon lag coefficients given the parameters and required number of coefficients.
nealmon(p, d, m)
nealmon(p, d, m)
p |
parameters for Almon lag |
d |
number of the coefficients |
m |
the frequency, currently ignored. |
Given unrestricted MIDAS regression
normalized exponential Almon lag restricts the coefficients in the following way:
The parameter should be the first element in vector
p
. The degree of
the polynomial is then decided by the number of the remaining parameters.
vector of coefficients
Virmantas Kvedaras, Vaidotas Zemlys
##Load data data("USunempr") data("USrealgdp") y <- diff(log(USrealgdp)) x <- window(diff(USunempr),start=1949) t <- 1:length(y) midas_r(y~t+fmls(x,11,12,nealmon),start=list(x=c(0,0,0)))
##Load data data("USunempr") data("USrealgdp") y <- diff(log(USrealgdp)) x <- window(diff(USunempr),start=1949) t <- 1:length(y) midas_r(y~t+fmls(x,11,12,nealmon),start=list(x=c(0,0,0)))
Gradient function for normalized exponential Almon lag weights
nealmon_gradient(p, d, m)
nealmon_gradient(p, d, m)
p |
hyperparameters for Almon lag |
d |
number of coefficients |
m |
the frequency ratio, currently ignored |
the gradient matrix
Vaidotas Zemlys
The code in the example generates the out-of-sample prediction precision data for correctly and incorrectly constrained MIDAS regression model compared to unconstrained MIDAS regression model.
A data.frame
object with four columns. The first column indicates the sample size, the second the type of constraint, the third the value of the precision measure and the fourth the type of precision measure.
## Do not run: ## set.seed(1001) ## gendata<-function(n) { ## trend<-c(1:n) ## z<-rnorm(12*n) ## fn.z <- nealmon(p=c(2,0.5,-0.1),d=17) ## y<-2+0.1*trend+mls(z,0:16,12)%*%fn.z+rnorm(n) ## list(y=as.numeric(y),z=z,trend=trend) ## } ## nn <- c(50,100,200,300,500,750,1000) ## data_sets <- lapply(n,gendata) ## mse <- function(x) { ## mean(residuals(x)^2) ## } ## bnorm <- function(x) { ## sqrt(sum((coef(x, midas = TRUE)-c(2,0.1,nealmon(p=c(2,0.5,-0.1),d=17)))^2)) ## } ## rep1 <- function(n) { ## dt <- gendata(round(1.25*n)) ## ni <- n ## ind <- 1:ni ## mind <- 1:(ni*12) ## indt<-list(y=dt$y[ind],z=dt$z[mind],trend=dt$trend[ind]) ## outdt <- list(y=dt$y[-ind],z=dt$z[-mind],trend=dt$trend[-ind]) ## um <- midas_r(y~trend+mls(z,0:16,12),data=indt,start=NULL) ## nm <- midas_r(y~trend+mls(z,0:16,12,nealmon),data=indt,start=list(z=c(1,-1,0))) ## am <- midas_r(y~trend+mls(z,0:16,12,almonp),data=indt,start=list(z=c(1,0,0,0))) ## modl <- list(um,nm,am) ## names(modl) <- c("um","nm","am") ## list(norms=sapply(modl,bnorm), ## mse=sapply(modl,function(mod)mean((forecast(mod,newdata=outdt)-outdt$y)^2))) ## } ## repr <- function(n,R) { ## cc <- lapply(1:R,function(i)rep1(n)) ## list(norms=t(sapply(cc,"[[","norms")),mse=t(sapply(cc,"[[","mse"))) ## } ## res <- lapply(nn,repr,R=1000) ## norms <- data.frame(nn,t(sapply(lapply(res,"[[","norms"),function(l)apply(l,2,mean)))) ## mses <- data.frame(nn,t(sapply(lapply(res,"[[","mse"),function(l)apply(l,2,mean)))) ## msd <- melt(mses[-1,],id=1) ## colnames(msd)[2] <- "Constraint" ## nmd <- melt(norms[-1,],id=1) ## colnames(nmd)[2] <- "Constraint" ## msd$Type <- "Mean squared error" ## nmd$Type <- "Distance from true values" ## oos_prec <- rbind(msd,nmd) ## oos_prec$Type <- factor(oos_prec$Type,levels=c("Mean squared error","Distance from true values"))
## Do not run: ## set.seed(1001) ## gendata<-function(n) { ## trend<-c(1:n) ## z<-rnorm(12*n) ## fn.z <- nealmon(p=c(2,0.5,-0.1),d=17) ## y<-2+0.1*trend+mls(z,0:16,12)%*%fn.z+rnorm(n) ## list(y=as.numeric(y),z=z,trend=trend) ## } ## nn <- c(50,100,200,300,500,750,1000) ## data_sets <- lapply(n,gendata) ## mse <- function(x) { ## mean(residuals(x)^2) ## } ## bnorm <- function(x) { ## sqrt(sum((coef(x, midas = TRUE)-c(2,0.1,nealmon(p=c(2,0.5,-0.1),d=17)))^2)) ## } ## rep1 <- function(n) { ## dt <- gendata(round(1.25*n)) ## ni <- n ## ind <- 1:ni ## mind <- 1:(ni*12) ## indt<-list(y=dt$y[ind],z=dt$z[mind],trend=dt$trend[ind]) ## outdt <- list(y=dt$y[-ind],z=dt$z[-mind],trend=dt$trend[-ind]) ## um <- midas_r(y~trend+mls(z,0:16,12),data=indt,start=NULL) ## nm <- midas_r(y~trend+mls(z,0:16,12,nealmon),data=indt,start=list(z=c(1,-1,0))) ## am <- midas_r(y~trend+mls(z,0:16,12,almonp),data=indt,start=list(z=c(1,0,0,0))) ## modl <- list(um,nm,am) ## names(modl) <- c("um","nm","am") ## list(norms=sapply(modl,bnorm), ## mse=sapply(modl,function(mod)mean((forecast(mod,newdata=outdt)-outdt$y)^2))) ## } ## repr <- function(n,R) { ## cc <- lapply(1:R,function(i)rep1(n)) ## list(norms=t(sapply(cc,"[[","norms")),mse=t(sapply(cc,"[[","mse"))) ## } ## res <- lapply(nn,repr,R=1000) ## norms <- data.frame(nn,t(sapply(lapply(res,"[[","norms"),function(l)apply(l,2,mean)))) ## mses <- data.frame(nn,t(sapply(lapply(res,"[[","mse"),function(l)apply(l,2,mean)))) ## msd <- melt(mses[-1,],id=1) ## colnames(msd)[2] <- "Constraint" ## nmd <- melt(norms[-1,],id=1) ## colnames(nmd)[2] <- "Constraint" ## msd$Type <- "Mean squared error" ## nmd$Type <- "Distance from true values" ## oos_prec <- rbind(msd,nmd) ## oos_prec$Type <- factor(oos_prec$Type,levels=c("Mean squared error","Distance from true values"))
Plots logistic function for LSTR MIDAS regression
plot_lstr(x, term_name, title = NULL, compare = NULL, ...)
plot_lstr(x, term_name, title = NULL, compare = NULL, ...)
x |
|
term_name |
the term name for which the coefficients are plotted. Default is |
title |
the title string of the graph. The default is |
compare |
the parameters for weight function to compare with the model, default is NULL |
... |
not used |
Plots logistic function for LSTR MIDSAS regression of unrestricted MIDAS regression
a data frame with restricted MIDAS coefficients, unrestricted MIDAS coefficients and lower and upper confidence interval limits. The data frame is returned invisibly.
Virmantas Kvedaras, Vaidotas Zemlys
Plots MIDAS coefficients of a MIDAS regression for a selected term.
plot_midas_coef(x, term_name, title, ...) ## S3 method for class 'midas_r' plot_midas_coef( x, term_name = NULL, title = NULL, vcov. = sandwich, unrestricted = x$unrestricted, ... )
plot_midas_coef(x, term_name, title, ...) ## S3 method for class 'midas_r' plot_midas_coef( x, term_name = NULL, title = NULL, vcov. = sandwich, unrestricted = x$unrestricted, ... )
x |
|
term_name |
the term name for which the coefficients are plotted. Default is |
title |
the title string of the graph. The default is |
... |
additional arguments passed to |
vcov. |
the covariance matrix to calculate the standard deviation of the cofficients |
unrestricted |
the unrestricted model, the default is unrestricted model from the |
Plots MIDAS coefficients of a selected MIDAS regression term together with corresponding MIDAS coefficients and their confidence intervals of unrestricted MIDAS regression
a data frame with restricted MIDAS coefficients, unrestricted MIDAS coefficients and lower and upper confidence interval limits. The data frame is returned invisibly.
Virmantas Kvedaras, Vaidotas Zemlys
data("USrealgdp") data("USunempr") y <- diff(log(USrealgdp)) x <- window(diff(USunempr), start = 1949) trend <- 1:length(y) ##24 high frequency lags of x included mr <- midas_r(y ~ trend + fmls(x, 23, 12, nealmon), start = list(x = rep(0, 3))) plot_midas_coef(mr)
data("USrealgdp") data("USunempr") y <- diff(log(USrealgdp)) x <- window(diff(USunempr), start = 1949) trend <- 1:length(y) ##24 high frequency lags of x included mr <- midas_r(y ~ trend + fmls(x, 23, 12, nealmon), start = list(x = rep(0, 3))) plot_midas_coef(mr)
Plots MIDAS coefficients of a MIDAS regression for a selected term.
## S3 method for class 'midas_nlpr' plot_midas_coef( x, term_name = NULL, title = NULL, compare = NULL, normalize = FALSE, ... )
## S3 method for class 'midas_nlpr' plot_midas_coef( x, term_name = NULL, title = NULL, compare = NULL, normalize = FALSE, ... )
x |
|
term_name |
the term name for which the coefficients are plotted. Default is |
title |
the title string of the graph. The default is |
compare |
the parameters for weight function to compare with the model, default is NULL |
normalize |
logical, if FALSE use the weight from the model, if TRUE, set the normalization coefficient of the weight function to 1. |
... |
not used |
Plots MIDAS coefficients of a selected MIDAS regression term together with corresponding MIDAS coefficients and their confidence intervals of unrestricted MIDAS regression
a data frame with restricted MIDAS coefficients, unrestricted MIDAS coefficients and lower and upper confidence interval limits. The data frame is returned invisibly.
Virmantas Kvedaras, Vaidotas Zemlys
Plot non-parametric part of the single index MIDAS regression of unrestricted MIDAS regression
plot_sp(x, term_name, title = NULL, compare = NULL, ...)
plot_sp(x, term_name, title = NULL, compare = NULL, ...)
x |
|
term_name |
the term name for which the coefficients are plotted. Default is |
title |
the title string of the graph. The default is |
compare |
the parameters for weight function to compare with the model, default is NULL |
... |
not used |
a data frame with restricted MIDAS coefficients, unrestricted MIDAS coefficients and lower and upper confidence interval limits. The data frame is returned invisibly.
Virmantas Kvedaras, Vaidotas Zemlys
Step function specification for MIDAS weights
polystep(p, d, m, a)
polystep(p, d, m, a)
p |
vector of parameters |
d |
number of coefficients |
m |
the frequency ratio, currently ignored |
a |
vector of increasing positive integers indicating the steps |
vector of coefficients
Vaidotas Zemlys
Gradient of step function specification for MIDAS weights
polystep_gradient(p, d, m, a)
polystep_gradient(p, d, m, a)
p |
vector of parameters |
d |
number of coefficients |
m |
the frequency ratio, currently ignored |
a |
vector of increasing positive integers indicating the steps |
vector of coefficients
Vaidotas Zemlys
Predicted values based on midas_nlpr
object.
## S3 method for class 'midas_nlpr' predict(object, newdata, na.action = na.omit, ...)
## S3 method for class 'midas_nlpr' predict(object, newdata, na.action = na.omit, ...)
object |
|
newdata |
a named list containing data for mixed frequencies. If omitted, the in-sample values are used. |
na.action |
function determining what should be done with missing values in |
... |
additional arguments, not used |
predict.midas_nlpr
produces predicted values, obtained by evaluating regression function in the frame newdata
. This means that the appropriate model matrix is constructed using only the data in newdata
. This makes this function not very convenient for forecasting purposes. If you want to supply the new data for forecasting horizon only use the function forecast.midas_r. Also this function produces only static predictions, if you want dynamic forecasts use the forecast.midas_r.
a vector of predicted values
Virmantas Kvedaras, Vaidotas Zemlys
Predicted values based on midas_r
object.
## S3 method for class 'midas_r' predict(object, newdata, na.action = na.omit, ...)
## S3 method for class 'midas_r' predict(object, newdata, na.action = na.omit, ...)
object |
|
newdata |
a named list containing data for mixed frequencies. If omitted, the in-sample values are used. |
na.action |
function determining what should be done with missing values in |
... |
additional arguments, not used |
predict.midas_r
produces predicted values, obtained by evaluating regression function in the frame newdata
. This means that the appropriate model matrix is constructed using only the data in newdata
. This makes this function not very convenient for forecasting purposes. If you want to supply the new data for forecasting horizon only use the function forecast.midas_r. Also this function produces only static predictions, if you want dynamic forecasts use the forecast.midas_r.
a vector of predicted values
Virmantas Kvedaras, Vaidotas Zemlys
data("USrealgdp") data("USunempr") y <- diff(log(USrealgdp)) x <- window(diff(USunempr), start = 1949) ##24 high frequency lags of x included mr <- midas_r(y ~ fmls(x, 23, 12, nealmon), start = list(x = rep(0, 3))) ##Declining unemployment xn <- rnorm(2 * 12, -0.1, 0.1) ##Only one predicted value, historical values discarded predict(mr, list(x = xn)) ##Historical values taken into account forecast(mr, list(x = xn))
data("USrealgdp") data("USunempr") y <- diff(log(USrealgdp)) x <- window(diff(USunempr), start = 1949) ##24 high frequency lags of x included mr <- midas_r(y ~ fmls(x, 23, 12, nealmon), start = list(x = rep(0, 3))) ##Declining unemployment xn <- rnorm(2 * 12, -0.1, 0.1) ##Only one predicted value, historical values discarded predict(mr, list(x = xn)) ##Historical values taken into account forecast(mr, list(x = xn))
Predicted values based on midas_sp
object.
## S3 method for class 'midas_sp' predict(object, newdata, na.action = na.omit, ...)
## S3 method for class 'midas_sp' predict(object, newdata, na.action = na.omit, ...)
object |
|
newdata |
a named list containing data for mixed frequencies. If omitted, the in-sample values are used. |
na.action |
function determining what should be done with missing values in |
... |
additional arguments, not used |
predict.midas_sp
produces predicted values, obtained by evaluating regression function in the frame newdata
. This means that the appropriate model matrix is constructed using only the data in newdata
. This makes this function not very convenient for forecasting purposes. If you want to supply the new data for forecasting horizon only use the function forecast.midas_r. Also this function produces only static predictions, if you want dynamic forecasts use the forecast.midas_r.
a vector of predicted values
Virmantas Kvedaras, Vaidotas Zemlys-Balevičius
Workhorse function for calculating necessary matrices for hAh_test and hAhr_test. Takes the same parameters as hAh_test
prep_hAh(x)
prep_hAh(x)
x |
|
a list with necessary matrices
Virmantas Kvedaras, Vaidotas Zemlys
hAh_test, hAhr_test
Realized volatility of S&P500(Live) index of the period 2000 01 03 - 2013 11 22
A data.frame
object with two columns. First column contains date id, and the second the realized volatility for S&P500 index.
https://realized.oxford-man.ox.ac.uk/images/oxfordmanrealizedvolatilityindices-0.2-final.zip
Heber, Gerd and Lunde, Asger, and Shephard, Neil and Sheppard, Kevin Oxford-Man Institute's realized library, Oxford-Man Institute, University of Oxford (2009)
## Do not run: ## Download the data from ## https://realized.oxford-man.ox.ac.uk/images/oxfordmanrealizedvolatilityindices-0.2-final.zip ## It contains the file OxfordManRealizedVolatilityIndices.csv. ## rvi <- read.csv("OxfordManRealizedVolatilityIndices.csv",check.names=FALSE,skip=2) ## ii <- which(rvi$DateID=="20131112") ## rvsp500 <- na.omit(rvi[1:ii,c("DataID","SPX2.rv")]
## Do not run: ## Download the data from ## https://realized.oxford-man.ox.ac.uk/images/oxfordmanrealizedvolatilityindices-0.2-final.zip ## It contains the file OxfordManRealizedVolatilityIndices.csv. ## rvi <- read.csv("OxfordManRealizedVolatilityIndices.csv",check.names=FALSE,skip=2) ## ii <- which(rvi$DateID=="20131112") ## rvsp500 <- na.omit(rvi[1:ii,c("DataID","SPX2.rv")]
Creates tables for different forecast horizons and table for combined forecasts
select_and_forecast( formula, data, from, to, insample, outsample, weights, wstart, start = NULL, IC = "AIC", seltype = c("restricted", "unrestricted"), test = "hAh_test", ftype = c("fixed", "recursive", "rolling"), measures = c("MSE", "MAPE", "MASE"), fweights = c("EW", "BICW", "MSFE", "DMSFE"), ... )
select_and_forecast( formula, data, from, to, insample, outsample, weights, wstart, start = NULL, IC = "AIC", seltype = c("restricted", "unrestricted"), test = "hAh_test", ftype = c("fixed", "recursive", "rolling"), measures = c("MSE", "MAPE", "MASE"), fweights = c("EW", "BICW", "MSFE", "DMSFE"), ... )
formula |
initial formula for the |
data |
list of data |
from |
a named list of starts of lags from where to fit. Denotes the horizon |
to |
a named list for lag selections |
insample |
the low frequency indexes for in-sample data |
outsample |
the low frequency indexes for out-of-sample data |
weights |
names of weight function candidates |
wstart |
starting values for weight functions |
start |
other starting values |
IC |
name of information criteria to choose model from |
seltype |
argument to modsel, |
test |
argument to modsel |
ftype |
which type of forecast to use. |
measures |
the names of goodness of fit measures |
fweights |
names of weighting schemes |
... |
additional arguments for optimisation method, see midas_r |
Divide data into in-sample and out-of-sample. Fit different forecasting horizons for in-sample data. Calculate accuracy measures for individual and average forecasts.
a list containing forecasts, tables of accuracy measures and the list with selected models
Virmantas Kvedaras, Vaidotas Zemlys
### Sets a seed for RNG ### set.seed(1001) ## Number of low-frequency observations n<-250 ## Linear trend and higher-frequency explanatory variables (e.g. quarterly and monthly) trend<-c(1:n) x<-rnorm(4*n) z<-rnorm(12*n) ## Exponential Almon polynomial constraint-consistent coefficients fn.x <- nealmon(p=c(1,-0.5),d=8) fn.z <- nealmon(p=c(2,0.5,-0.1),d=17) ## Simulated low-frequency series (e.g. yearly) y<-2+0.1*trend+mls(x,0:7,4)%*%fn.x+mls(z,0:16,12)%*%fn.z+rnorm(n) ##Do not run ## cbfc<-select_and_forecast(y~trend+mls(x,0,4)+mls(z,0,12), ## from=list(x=c(4,8,12),z=c(12,24,36)), ## to=list(x=rbind(c(14,19),c(18,23),c(22,27)),z=rbind(c(22,27),c(34,39),c(46,51))), ## insample=1:200,outsample=201:250, ## weights=list(x=c("nealmon","almonp"),z=c("nealmon","almonp")), ## wstart=list(nealmon=rep(1,3),almonp=rep(1,3)), ## IC="AIC", ## seltype="restricted", ## ftype="fixed", ## measures=c("MSE","MAPE","MASE"), ## fweights=c("EW","BICW","MSFE","DMSFE") ## )
### Sets a seed for RNG ### set.seed(1001) ## Number of low-frequency observations n<-250 ## Linear trend and higher-frequency explanatory variables (e.g. quarterly and monthly) trend<-c(1:n) x<-rnorm(4*n) z<-rnorm(12*n) ## Exponential Almon polynomial constraint-consistent coefficients fn.x <- nealmon(p=c(1,-0.5),d=8) fn.z <- nealmon(p=c(2,0.5,-0.1),d=17) ## Simulated low-frequency series (e.g. yearly) y<-2+0.1*trend+mls(x,0:7,4)%*%fn.x+mls(z,0:16,12)%*%fn.z+rnorm(n) ##Do not run ## cbfc<-select_and_forecast(y~trend+mls(x,0,4)+mls(z,0,12), ## from=list(x=c(4,8,12),z=c(12,24,36)), ## to=list(x=rbind(c(14,19),c(18,23),c(22,27)),z=rbind(c(22,27),c(34,39),c(46,51))), ## insample=1:200,outsample=201:250, ## weights=list(x=c("nealmon","almonp"),z=c("nealmon","almonp")), ## wstart=list(nealmon=rep(1,3),almonp=rep(1,3)), ## IC="AIC", ## seltype="restricted", ## ftype="fixed", ## measures=c("MSE","MAPE","MASE"), ## fweights=c("EW","BICW","MSFE","DMSFE") ## )
Simulates one or more responses from the distribution corresponding to a fitted MIDAS regression object.
## S3 method for class 'midas_r' simulate( object, nsim = 999, seed = NULL, future = TRUE, newdata = NULL, insample = NULL, method = c("static", "dynamic"), innov = NULL, show_progress = TRUE, ... )
## S3 method for class 'midas_r' simulate( object, nsim = 999, seed = NULL, future = TRUE, newdata = NULL, insample = NULL, method = c("static", "dynamic"), innov = NULL, show_progress = TRUE, ... )
object |
|
nsim |
number of simulations |
seed |
either NULL or an integer that will be used in a call to set.seed before simulating the time series. The default, NULL will not change the random generator state. |
future |
logical, if |
newdata |
a named list containing future values of mixed frequency regressors. The default is |
insample |
a list containing the historic mixed frequency data |
method |
the simulation method, if |
innov |
a matrix containing the simulated innovations. The default is |
show_progress |
logical, TRUE to show progress bar, FALSE for silent evaluation |
... |
not used currently |
Only the regression innovations are simulated, it is assumed that the predictor variables and coefficients are fixed. The innovation distribution is simulated via bootstrap.
a matrix of simulated responses. Each row contains a simulated response.
Virmantas Kvedaras, Vaidotas Zemlys
data("USrealgdp") data("USunempr") y <- diff(log(USrealgdp)) x <- window(diff(USunempr), start = 1949) trend <- 1:length(y) ##24 high frequency lags of x included mr <- midas_r(y ~ trend + fmls(x, 23, 12, nealmon), start = list(x = rep(0, 3))) simulate(mr, nsim=10, future=FALSE) ##Forecast horizon h <- 3 ##Declining unemployment xn <- rep(-0.1, 12*3) ##New trend values trendn <- length(y) + 1:h simulate(mr, nsim = 10, future = TRUE, newdata = list(trend = trendn, x = xn))
data("USrealgdp") data("USunempr") y <- diff(log(USrealgdp)) x <- window(diff(USunempr), start = 1949) trend <- 1:length(y) ##24 high frequency lags of x included mr <- midas_r(y ~ trend + fmls(x, 23, 12, nealmon), start = list(x = rep(0, 3))) simulate(mr, nsim=10, future=FALSE) ##Forecast horizon h <- 3 ##Declining unemployment xn <- rep(-0.1, 12*3) ##New trend values trendn <- length(y) + 1:h simulate(mr, nsim = 10, future = TRUE, newdata = list(trend = trendn, x = xn))
Splits mixed frequency data into in-sample and out-of-sample datasets given the indexes of the low frequency data
split_data(data, insample, outsample)
split_data(data, insample, outsample)
data |
a list containing mixed frequency data |
insample |
the low frequency indexes for in-sample data |
outsample |
the low frequency indexes for out-of-sample data |
It is assumed that data is a list containing mixed frequency data. Then given the indexes of the low frequency data the function splits the data into two subsets.
a list with elements indata
and outdata
containing respectively in-sample and out-of-sample data sets
Virmantas Kvedaras, Vaidotas Zemlys
#Monthly data x <- 1:24 #Quartely data z <- 1:8 #Yearly data y <- 1:2 split_data(list(y=y,x=x,z=z),insample=1,outsample=2)
#Monthly data x <- 1:24 #Quartely data z <- 1:8 #Yearly data y <- 1:2 split_data(list(y=y,x=x,z=z),insample=1,outsample=2)
Updates weights in a expression with MIDAS term
update_weights(expr, tb)
update_weights(expr, tb)
expr |
expression with MIDAS term |
tb |
a named list with redefined weights |
For a MIDAS term fmls(x, 6, 1, nealmon)
change weight nealmon
to another weight.
an expression with changed weights
Vaidotas Zemlys
update_weights(y~trend+mls(x,0:7,4,nealmon)+mls(z,0:16,12,nealmon),list(x = "nbeta", z = ""))
update_weights(y~trend+mls(x,0:7,4,nealmon)+mls(z,0:16,12,nealmon),list(x = "nbeta", z = ""))
US quarterly CPI from 1960Q1 to 2017Q3s. Seasonaly adjusted, Index 2015=1
A data.frame
object.
US weekly effective federal funds rate from 1954-07-07 to 2017-12-13
A data.frame
object.
United States total employment non-farms payroll, monthly, seasonally adjusted. Retrieved from FRED, symbol "PAYEMS" at 2014-04-25.
A ts
object.
FRED, Federal Reserve Economic Data, from the Federal Reserve Bank of St. Louis
## Do not run: ## library(quantmod) ## USpayems <- ts(getSymbols("PAYEMS",src="FRED",auto.assign=FALSE),start=c(1939,1),frequency=12)
## Do not run: ## library(quantmod) ## USpayems <- ts(getSymbols("PAYEMS",src="FRED",auto.assign=FALSE),start=c(1939,1),frequency=12)
United States gross domestic product, quarterly, seasonaly adjusted annual rate. Retrieved from FRED, symbol "GDP" at 2014-04-25.
A ts
object.
FRED, Federal Reserve Economic Data, from the Federal Reserve Bank of St. Louis
## Do not run: ## library(quantmod) ## USqgdp <- ts(getSymbols("GDP",src="FRED",auto.assign=FALSE),start=c(1947,1),frequency=4)
## Do not run: ## library(quantmod) ## USqgdp <- ts(getSymbols("GDP",src="FRED",auto.assign=FALSE),start=c(1947,1),frequency=4)
The annual gross domestic product in billions of chained 2005 dollars for US from 1948 to 2011. This data is kept for historical purposes, newer data is in 2012 chained dollars.
A ts
object.
U.S. Department of Commerce, Bureau of Economic Analysis
The monthly unemployment rate for United States from 1948 to 2011.
A ts
object.
Creates a weight function selection table for MIDAS regression model with given information criteria and weight functions.
weights_table( formula, data, start = NULL, IC = c("AIC", "BIC"), test = c("hAh_test"), Ofunction = "optim", weight_gradients = NULL, ... )
weights_table( formula, data, start = NULL, IC = c("AIC", "BIC"), test = c("hAh_test"), Ofunction = "optim", weight_gradients = NULL, ... )
formula |
the formula for MIDAS regression, the lag selection is performed for the last MIDAS lag term in the formula |
data |
a list containing data with mixed frequencies |
start |
the starting values for optimisation |
IC |
the information criteria which to compute |
test |
the names of statistical tests to perform on restricted model, p-values are reported in the columns of model selection table |
Ofunction |
see midasr |
weight_gradients |
see midas_r |
... |
additional parameters to optimisation function, see midas_r |
This function estimates models sequentially increasing the midas lag from kmin
to kmax
of the last term of the given formula
a midas_r_ic_table
object which is the list with the following elements:
table |
the table where each row contains calculated information criteria for both restricted and unrestricted MIDAS regression model with given lag structure |
candlist |
the list containing fitted models |
IC |
the argument IC |
Virmantas Kvedaras, Vaidotas Zemlys
data("USunempr") data("USrealgdp") y <- diff(log(USrealgdp)) x <- window(diff(USunempr),start=1949) trend <- 1:length(y) mwr <- weights_table(y~trend+fmls(x,12,12,nealmon), start=list(x=list(nealmon=rep(0,3), nbeta=c(1,1,1,0)))) mwr
data("USunempr") data("USrealgdp") y <- diff(log(USrealgdp)) x <- window(diff(USunempr),start=1949) trend <- 1:length(y) mwr <- weights_table(y~trend+fmls(x,12,12,nealmon), start=list(x=list(nealmon=rep(0,3), nbeta=c(1,1,1,0)))) mwr