Closed mynameisahmed closed 6 years ago
Can you produce the reproducible example? I would guess from the error message, that the optimization procedure did not converge, or that you data has linearly dependent columns.
Thanks for the prompt reply and being that gentle. Please find here the minimal code plus the data. I do appreciate your help.
Ok, your midas coefficient function has some issues. First of all what does p[1]:p[2]
suppose to mean? If we rewrite it by removing weird code:
beta_fn <- function(p,d) {
i <- 1:d
num <- (i/d)^(p[1]-1)*(1-(i/d))^(p[2]-1)*gamma(p[1]+p[2])
den <- gamma(p[1])*gamma(p[2])
fun_fn <- num/den
fun_fn/sum(fun_fn)
}
we have the following problem:
library(numDeriv)
apply(jacobian(beta_fn0,c(0.5,2.5),d=130),2,function(x)sum(abs(x)))
[1] 0.8302462 0.0000000
which basically means, that your midas coefficient function does not depend on the second parameter.
This naturally causes all sorts of problems. Check your code and your calculations. It might be that division makes second parameter to disappear. Your parameter function looks very similar to normalized beta function, try to use it instead.
Thanks a lot. For the function, I am pretty sure that this is the exact function used by Eric in several papers. Because I have tried it with the same hyperparameters and no of lags and I got the same results. Why I want to use that specific weighting polynomial because when I try built in normalized beta, the minimum no of hyperparameters that worked for me is three. The first one is weakly significant and the third one always is insignificant. For my application, It is necessary to show that the HF variable can significantly explain the LF variable. Thanks
Sorry, bit of a mix-up on my part. The jacobian was calculated for the older version of your function, which had bugs and that is why the second parameter was not relevant.
The following code works:
beta_fn <- function(p,d) {
i <- 1:d
num <- (i/d)^(p[1]-1)*(1-(i/d))^(p[2]-1)
num/sum(num)
}
beta_1 <- midas_r(yy ~ l.yy + mls(xx, 25:155, 65, beta_fn), start = list(xx = c(0.5, 2.5)),method="Nelder-Mead")
summary(beta_1)
Note however, that you probably want to add another parameter, multiplicative constant. Compare your fixed beta_fn
with nbetaMT
from the package. Also the JSS article mentions the issues with multiplicative constants.
Thanks a lot. Could you please just explain more about how to include this multiplicative constant and why the inclusion of that constant improves the significance of the hyperparameter because I noticed that but I did not get how that works. thanks
Please read the JSS article.
Thanks many. I will read it again more carefully in detail and then I will ask all my questions at once. I do appreciate you kind help and wish you a happy and decent life. Best regards, Ahmed
Thanks Dr. Zemlys, now it works.
Hallo, first, thank you so much for your great efforts and for making this package available.
I have a little problem here, I wrote the code for the two parameter beta function used by Eric in several publications. see pp 11 (https://www.federalreserve.gov/pubs/feds/2006/200610/200610pap.pdf)
But I get this message each time i try to run my midas_r command. Error in base::chol2inv(x, ...) : element (4, 4) is zero, so the inverse cannot be computed
What does this mean and how should i handle it. thank you