Reputation: 103
I deperately need help with this midas package. My low frequency y variable is measured on a monthly basis, whereas x is measured daily. For some reason I cannot get it work. I try to run this regression...
reg_s = midas_r(partial_y ~ partial_x + fmls(partial_com, (COMMODITY_OBSERVATIONS - 1), COMMODITY_OBSERVATIONS), start = NULL)
... but I get the following error message:
Error in eval(expr, envir, enclos) :
..1 used in an incorrect context, no ... to look in
The traceback() output is the following:
13: eval(expr, envir, enclos)
12: eval(predvars, data, env)
11: model.frame.default(formula = y ~ ., data = data.frame(cbind(y,
X[, -1]), check.names = FALSE), drop.unused.levels = TRUE)
10: stats::model.frame(formula = y ~ ., data = data.frame(cbind(y,
X[, -1]), check.names = FALSE), drop.unused.levels = TRUE)
9: eval(expr, envir, enclos)
8: eval(mf, parent.frame())
7: lm(y ~ ., data = data.frame(cbind(y, X[, -1]), check.names = FALSE))
6: prepmidas_r(y, X, mt, Zenv, cl, args, start, Ofunction, weight_gradients,
itr$lagsTable)
5: midas_r(partial_y ~ partial_x + fmls(partial_com, (COMMODITY_OBSERVATIONS -
1), COMMODITY_OBSERVATIONS), start = NULL) at taylor.r#193
4: eval(expr, envir, enclos)
3: eval(ei, envir)
2: withVisible(eval(ei, envir))
1: source("M:/semester6/r_taylor/taylor.r", echo = TRUE)
I tried to google this error message but I cannot make sense of it. Also, I have to provide a start valueo for the optimization algorithm that I know. In the midas user guide I found in some regressions start=NULL, so I thought I use that because it doesn't say how this start value should look like, how many values, ... Honestly, I'm a bit clueless about this package. Any suggestions?
Upvotes: 0
Views: 417
Reputation: 103
Alright, so I changed a couple of things and now I don't get an error message anymore. So here is what I did wrong:
Since I work with time series, partial_y and partial_x were the return values of xts(...) and as soon as I got rid of that, I had another error message, but something more reasonable.
I tried now the following: I took an example code from the user guide, because I knew that that one works for sure and tailored it slowly to my situation. I ended up with a piece of code that runs, but just uses dummy data. So here is what I would like to do.
My y variable are exchange rates, for instance, CAD to USD measured at the beginning of each month. Actually, it's the first difference, but I guess that doesn't matter. My x variable is a commodity price, measured at the end of a day. Since not every month has exactly the same amount of trading days, I simply modeled it as if and said that every month has 22 trading days. This is the piece of code that I'm experimenting with (which works fine):
x <- rnorm(22 * 5)
y <- rnorm(5, mean = 25, sd = 10)
eq_r <- midas_r(y ~ mls(x, 0:21, 22, nealmon), start = list(x = c(1, -0.5)))
summary(eq_r)
There are however a few things that I don't understand:
I also have troubles understanding this lag parameter. In my mind, what I would like to do is, I have data for example from January to May, estimate the coefficients with these data, and then use the commodity prices from June to make a new forecast. But then this lag parameter should be 0:21 right, because I want to include the prices of an entire month, yes, no?? Also, why is it that when I say
print(mls(x, 0:21, 22, nealmon))
in order to check how my data have been transformed into a matrix I get this
X.0/m X.1/m X.2/m X.3/m X.4/m X.5/m X.6/m X.7/m X.8/m X.9/m X.10/m X.11/m X.12/m X.13/m X.14/m X.15/m X.16/m X.17/m
[1,] 1.1863644 0.97481199 -1.7895747 0.2906128 0.30075201 0.80857324 2.3186506 -0.5170817 -0.46055538 0.7891047 0.03949783 0.6177602 -0.38369815 -1.8622837 0.8625135 -0.1611756 1.39612918 -1.1885719
[2,] -0.3704454 0.08822043 2.1020095 -0.5169749 -1.96695998 -1.49962934 -0.8678474 0.1140645 0.04114274 -1.5937239 2.08863098 2.2263487 -0.09925308 -0.6669605 0.4944246 -2.4027642 0.71116241 -0.4254720
[3,] 1.2154540 -0.64055638 -0.6437271 -0.7642743 0.66235172 -0.84262287 -1.4775039 0.6878486 0.65197942 0.1240311 0.23134023 0.1009972 -0.06475785 -0.2241584 -0.8032010 2.4843914 -0.54894487 0.0101310
[4,] 0.3305061 -1.13876511 -2.0092376 -0.1567246 0.96004744 0.34776469 0.5117166 0.4924779 -0.82728326 -0.6207466 0.17207811 1.6144863 -1.37304172 0.4901677 0.7561634 1.5870672 -1.38699189 0.1791196
[5,] 0.5310172 0.66979364 -1.2017408 -1.1030746 0.09164862 -0.04114568 -0.2157249 -1.2534833 -0.48547301 0.1006999 1.31309691 0.1150372 -1.53933091 0.2683860 -0.7282090 0.9481647 -0.01427574 -0.3786454
X.18/m X.19/m X.20/m X.21/m
[1,] 0.02344737 0.5336673 -0.2537367 1.4706220
[2,] -0.65971232 -1.3297581 -0.8318354 0.8438351
[3,] -0.51675173 1.7251156 -0.4394516 1.8223571
[4,] -0.29855743 0.5747885 0.1104557 -0.9217548
[5,] 1.97389817 -0.4466169 -0.9891151 -0.8422436
which seems reasonable to me, but then when I look at the output of the regression, I only have two coefficient estimates for x1 and x2??
MIDAS regression model
model: y ~ mls(x, 0:21, 22, nealmon)
(Intercept) x1 x2
23.8385 0.2915 -0.6891
When I used midas_u I got an estimate for each X.0/m ... X.21/m. Has that something to do with the fact that midas_u is bascially lm so an unrestriced estimation and midas_r is restricted, even though I'm not entirely sure what that means?
I just encountered something really weird. After estimating the model, I want to use the forecast command to make a prediction. Now if I use the number 22 in the midas_r function, everything works out fine. However, if I use instead of 22, the variable COMMODITY_OBSERVATIONS, which contains the value 22, I get the following error message:
Error in length(outsample[[firstno]])%/%freqinfo[firstno] :
non-numeric argument to binary operator
I already see the grey hairs growing...
Upvotes: 0