mpiktas / midasr

R package for mixed frequency time series data analysis.
http://mpiktas.github.io/midasr/
Other
74 stars 34 forks source link

Cannot get results using midas_r_ic_table or amidas_table #64

Closed sweetmoniker closed 6 years ago

sweetmoniker commented 6 years ago

Seeing as how these functions seem similar, I thought I would include both in one post.

quarterly data

Total_Awareness = c(85.67389,83.73669,83.65297,84.76374,80.57971,83.22083,81.82683,81.32184,79.56274,79.72576,79.07425,82.846,82,83,76.29268,77.16535,77.09552,78.93204,80.90909,75.12488)

monthly_data

Media_Spend = c(17193086,32947666,29262070,29486631,33475267,28219665,22935567,26779942,25258960,30494461,28438473,24888718,20452819,27356705,32082797,26213567,29189109,38414443,24152757,24604058,31203673,30448447,32973852,38122113,26349194,23269488,33612603,34207088,39782039,32473905,27981750,30868345,33642342,14196500,33810488,44801873,36672459,25980964,32928433,27210885,36953913,33079694,26439694,28865621,30237017,37000968,40805857,40967196,26480604,19392615,23849638,41637600,31285923,44788926,37801566,33794789,39494529,56545023,47309407,42768781)

The following, summary(midas_r(y ~ 0 + fmls(x,2,3), data = list(y = Total_Awareness, x= Media_Spend), start = list(x=c(0,0,0)))) works great:

MIDAS regression model with "numeric" data:
Start = 1, End = 20

 Formula y ~ 0 + fmls(x, 2, 3) 

 Parameters:
        Estimate    Std. Error t value Pr(>|t|)
x1  0.0000014106  0.0000009674   1.458    0.163
x2  0.0000010923  0.0000009602   1.138    0.271
x3 -0.0000001285  0.0000005525  -0.233    0.819

 Residual standard error: 15.74 on 17 degrees of freedom

The following, however, midas_r_ic_table(y ~ 0 + fmls(x,2,3), data = list(y = Total_Awareness, x= Media_Spend), table = expand_weights_lags(weights = "almonp", from = 0, to = c(0,1), m = 1, start = list(almonp=rep(0,3)))) results in the following error:

Error in `*tmp*`[[term.no]] : 
  attempt to select less than one element in get1index

I have checked that my expand_weights_lags function is working properly. Since I feel confident with the midas syntax and can't decipher the error code, I am unsure how to proceed.

Likewise, using amidas_table I have amidas_table(y ~ 0 + fmls(x,2,3), data = list(y = Total_Awareness, x= Media_Spend), weights = c("almonp"), wstart = list(almonp=c(0,0,0)), start = list(x=c(0,0,0)), type = c("A"), from = 0, to=c(1,2)) with result

Error in last.term[[5]] : subscript out of bounds

I have pared this function down to just the following, amidas_table(y ~ 0 + fmls(x,2,3), data = list(y = Total_Awareness, x= Media_Spend)) and I still get

Error in last.term[[5]] : subscript out of bounds

Like I said, since I am fairly confident in the formula, I am unsure how to troubleshoot to proceed. Am I missing something?

vzemlys commented 6 years ago

The problem is the number of lags. You pick only 3. You do not need any restrictions for that.

sweetmoniker commented 6 years ago

Thanks for the response. I guess I don't understand what that means though. I am trying to use MIDAS to regress monthly data on quarterly data. Is there some way to do that and not use a frequency ratio of 3 (lags of 2)? Are the amidas_table and midas_r_ic_table functions incompatible with 3-lag monthly/quarterly data then? Or am I not understanding what those function do?

vzemlys commented 6 years ago

Yes frequency ratio 3 is ok. The number of lags is too small. You call fmls(x,2,3), this means that you use only 3 lags, i.e. 3 months. For that number of lags U-MIDAS is better.

sweetmoniker commented 6 years ago

I feel like that conclusion is not so cut and dried, at least not according to Foroni, Marcellino, and Schumacher,

We suggest to consider U-MIDAS as a potential alternative to the existing MIDAS approach in particular for mixing monthly and quarterly variables. In practice, the choice between the two approaches should be made on a case-by-case basis, depending on their relative performance.

But if you're telling me that those functions are incompatible with quarterly/monthly data, then I guess there's nothing I can do.

vzemlys commented 6 years ago

These functions work perfectly with quarterly monthly data, look at the examples in JSS article. Only your selected model has too few lags. There is no point in using MIDAS lag function for so few lags.

sweetmoniker commented 6 years ago

I must apologize because I don't understand what you mean. Can you be more explicit in your response? You've already said there are "too few lags." You seem to be implying that fmls(x,2,3) is not correct despite (from what I can tell) no clear examples to indicate as much, but if that's the case, what should it be? Is an n x 3 matrix somehow not a correct conversion of monthly data to quarterly? Whatever it is that I'm missing or not doing correctly here isn't obvious to me.

vzemlys commented 6 years ago

If your only goal is to convert monthly data to quarterly then you do not need MIDAS regression. Please check the JSS article for what is a MIDAS regression and the examples of applications.

On Mon, 7 May 2018 at 21:28 sweetmoniker notifications@github.com wrote:

I must apologize because I don't understand what you mean. Can you be more explicit in your response? You've already said there are "too few lags." You seem to be implying that fmls(x,2,3) is not correct despite (from what I can tell) no clear examples to indicate as much, but if that's the case, what should it be? Is an n x 3 matrix somehow not a correct conversion of monthly data to quarterly? Whatever it is that I'm missing or not doing correctly here isn't obvious to me.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/mpiktas/midasr/issues/64#issuecomment-387158462, or mute the thread https://github.com/notifications/unsubscribe-auth/AATlZ4VCvWi-7WTUpLHaNs7OriGbwoB9ks5twJI5gaJpZM4Tq2tV .

sweetmoniker commented 6 years ago

My goal, as stated above, is to use these functions. But so far this has been a waste of time. Unless you can indicate some way that I can get get midas_r_ic_table and/or amidas_table to function with quarterly/monthly data (any way - I don't care how) my take away is that they will not work with such data. So far you have given no indication that this is possible. I want my data in a 20 x 3 matrix because I have 60 observations, which seems extremely intuitive to me. (Otherwise what possible shape could the data have?). There are no examples in your paper about this - none. Unless you can show what it is that I am doing wrong, then these functions do not work on quarterly/monthly data.

vzemlys commented 6 years ago

Have you really read the article? The 4.1 section gives an example with quarterly and monthly data. Midasr is a open source software, it costs nothing to use it. If you do not like it then you always have an option of not using it. I try to support the users of the package on my own free time. This means that there is implied expectation that the user has do some work, i.e. read the examples, the article, etc. From the discussion I see that you are not interested in doing any work yourself and expect that somebody else would do that. Do not expect my help in that.

sweetmoniker commented 6 years ago

You're right. The paper does. But none of the lag structures in the examples are the same as mine. There are exactly 9 references to midas_r_ic_table (2 in examples) and 1 reference to amidas_table (0 in examples) in your paper. They have mls(x,0,4) and mls(rv, 1:20, 1, nealmon), which does not seem compatible with my requirements. I know what MIDAS is. There is no need to be condescending. I'm sorry if I offended you, but being a programmer also means taking ownership of your work, which so far you have failed to do. I keep asking the same question over and over again and all you say is there are "too few lags." That is not constructive. It does not give me any indication of what is wrong. I have a quarterly dependent variable and monthly independent variable. I want to shape my independent variable into an n x 3 matrix because that makes sense to me. Indicate where it is in that logic that I have gone wrong and I am happy to change my formula. You have given no indication what is wrong with either my syntax or logic - just that there are "too few lags." How is that even possible given my data structure? How can I possibly have MORE than the contemporaneous observation and 2 lags in each row of the matrix with quarterly/monthly data? It seems to me like you are trying to avoid answering/investigating this issue and are just making vague references and accusations because you know the package will not work with this data structure.

vzemlys commented 6 years ago

This discussion evolved into argument your word against mine. I wrote the package, I wrote the article, I am the expert here. If I say that your model have too few lags, I mean it. If you do not understand why, I can only come to conclusion that you do not understand what MIDAS regression really is. That is my professional opinion and I stand beside it.

sweetmoniker commented 6 years ago

Thanks for the response. My only takeaway from all this then is that these functions are incompatible with this data since you continue to not address the issue. Good luck with your work and have a great day.