mpiktas / midasr

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

Normalized beta fuction #49

Closed gussarnro closed 7 years ago

gussarnro commented 7 years ago

Maybe I have understood the normalized beta function that is being modeled in the package but I cannot seem to understand why it is using three paramters. The beta weighttning function used by Ghysels, Santa-Clara and Valkanov (2004, 2005 and 2006) only use two parameters. This is the ordinary normalized beta function built from standard gamma function. Is this specification also included in the package and am I perhaps missing something?

Thanks for a great package!

gussarnro commented 7 years ago

capture1 capture2

vzemlys commented 7 years ago

Did you read the JSS article? The normalized beta function is defined in the table 1 in page 8. It has two parameters. The normalized beta function is implemented as nbeta. This function has 3 arguments, the first contains the parameters of normalized beta together with the normalized constant, the second is the k_max defined in your formula and the third is ignored.

gussarnro commented 7 years ago

Thank you very much for the quick response. I read the article and this is the only area where I have had any trouble so far. I am fairly new to MIDAS modeling and relatively new to R in general so I might be doing some obvious mistake. I am trying to do rolling forecasts using the midasr pckage. When I use the exponential almon function I specify it as:

ModelSpec=midas_r(y~mls(x,0:(11+12*19),12, nealmon), start=list(x=c(1,-0.5))) RollingModel=average_forecast(list(ModelSpec), data=list(y=y, x=x), insample = 1:25, outsample=26:length(y), type="rolling") RollingModel$forecast

Here I put in two paramters for the exponential almon function c(1,-0.5), and leave k empty to be collected from the mls which is 11+12 19. Thus k is 11+12 19 as I understand it. This works well.

Next I try to do the same with exponential beta function: ModelSpec=midas_r(y~mls(x,0:(11+12 * 19),12, nbeta), start=list(x=c(1,3))) RollingModel=average_forecast(list(ModelSpec), data=list(y=y, x=x), insample = 1:25, outsample=26:length(y), type="rolling")

This gives me the error message:

Error in prepmidas_r(y, X, mt, Zenv, cl, args, start, Ofunction, weight_gradients, : Check your starting values, NA in midas coefficients

If I put in start=list(x=c(1,1,1))) (with three parameter values) I get no error message.

vzemlys commented 7 years ago

Yes this is perfectly normal. The normalizing constant is a part of lag specification in midasr package. The relevant documentation is in section 2.3 of JSS article. So you need to pass three parameters for nbeta, the first one is the normalizing constant, the second and third are the ones in your formula.

gussarnro commented 7 years ago

Ok. I believe I understand. So in the example I gave above: ModelSpec=midas_r(y~mls(x,0:(11+12*19),12, nealmon), start=list(x=c(1,-0.5))) I am actually only estimating a single shape parameter? 1 is normalizing constant and -0.5 is shape parameter.

Thank you very much for taking your time to clarify this to me. Its truly a wonderful r-package that makes something fairly complex very accessible.

vzemlys commented 7 years ago

Yes you are correct. It is always a good idea to test the midas lag specification function for the default parameters. In this case you get:

nbeta(c(1,-0.5),length(0:(11+12*19)))
[1] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
 [25] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
 [49] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
 [73] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
 [97] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
[121] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
[145] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
[169] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
[193] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
[217] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA

I'll add the warning to nbeta, so that if too few parameters are passed, the warning is issued.