Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for negative lags in mls function #30

Open
vzemlys opened this issue Aug 21, 2013 · 3 comments
Open

Add support for negative lags in mls function #30

vzemlys opened this issue Aug 21, 2013 · 3 comments
Labels

Comments

@vzemlys
Copy link
Member

vzemlys commented Aug 21, 2013

Would be helpful to form forecasting models of the type

mls(y,-1,1)~y+fmls(x,11,12,nealmon)

@jarser
Copy link

jarser commented Aug 3, 2017

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?

@vzemlys
Copy link
Member Author

vzemlys commented Aug 4, 2017

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) 

@mynameisahmed
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants