Open vzemlys opened 11 years ago
As of today it is still not straight forward to to fit models with leads, right? (I'm thinking of the MIDAS with leads equation of the paper accompanying this package).
A workaround I found to do that could be the following just using lags and reinterpreting the information:
For example, assuming x is the high frequency variable and that it has frequency m = 3.
If just two leads are available, so J = 2, then
mls(x, 1:5, 3, nealmon)
(if we use the same constraints for all)
or
mls(x, 1:2, 3, almonp) + mls(x, 3:5, 3, nealmon)
(in case we use different weighting functions for leads and lags)
However, this implementation, necessarily drops degrees of freedom because it has to compute lags first (and that means dropping observations in the beginning of the sample) that can be reinterpreted as leads.
Is there some other workaround or trick to generate actual leads yet?
The way midasr works it is possible to fit any MIDAS model, with the caveat that some of the models might require more data rearrangement.
Concerning MIDAS with leads in JSS paper (5th formula in section 2.6 in page 12) the specification would be the following
midas_r(y~mls(y, 1:py, 1) + mls(x,(m-J):(m-1),m) + mls(x, m:((px+2)*m-1),m, data=list(y=y,x=x),start=NULL)
Here is the example (the data comes from midas_r
help page):
##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))
py <- 2
m <- 12
px <- 1
J <- 6
mm <- midas_r(y~mls(y,1:py,1)+mls(x,(m-J):(m-1),m)+mls(x,m:((px+2)*m-1),m), list(y=y,x=x),start=NULL)
This fits the model where we try to forecast the yearly variable given the first 6 months of monthly data. Given the year t the model fits the year t+1 on years t and t-1 for variable y, first 6 months of the year t for x variable, and full months for years t, t-1 for the x variable.
You can check that this is the case by inspecting mm$model
and first three years of $x$ and $y$. The first line of mm$model
will contain y and years three, two and one. and then the 2 years and 6 months of x going from June of the year 3 and to the January of year 1.
Since the variable x is split in two terms in this model, I would advise to rename one of the terms, so that the coefficient names are unique, i.e. the following works too:
mm <- midas_r(y~mls(y,1:py,1)+mls(z,(m-J):(m-1),m)+mls(x,m:((px+2)*m-1),m), list(y=y,x=x,z=x),start=NULL)
Hallo, I have a related question here concerning the intra-period forecast. In the JSS article (pp 24) you explained two ways to use the estimated MIDAS model for forecasting. In both ways you however provided either the full range of intra period values or NAs of the HF variable that is equivalent to the required LF forecast horizon. 1- having the full intra-period information: newx <- rnorm(4) forecast(eq_rb, newdata = list(x = newx, trend = 251)) 2- having nothing from the intra-period information: eq_f <- midas_r(y ~ trend + mls(x, 4 + 0:7, 4, nealmon) + start = list(x = c(1, -0.5)) R> forecast(eq_f, newdata = list(x = rep(NA, 4), trend = 251))
However, one might have only a partial set of these intra-period observations. Have only one additional month. Applying the same logic does not work so far. The program asks me to provide the full range of the intra period observations. eq_f <- midas_r(y ~ trend + mls(x, 1+ 0:7, 4, nealmon) + start = list(x = c(1, -0.5)) R> forecast(eq_f, newdata = list(x = rep(NA, 1), trend = 251))
Thanks and sorry for the long post. Thanks
Would be helpful to form forecasting models of the type
mls(y,-1,1)~y+fmls(x,11,12,nealmon)