hac results vary bewteen MATLAB R2015b and MATLAB R2016b
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi, my problem was related to the matlab function "hac". I used the same code last year (with R2015b version) and obtained the heteroscedasticity and serial correlation consistent standard errors (StdErr* 7.9709 0.0321 3.7480 0.0404 2.9265 10.7310 )and pvalues (pValue* 1.89E-01 1.49E-02 8.13E-21 3.30E-02 0.0033 0.0414), shown as below. Under R2016b version, the function now reports error message: "Error using hac (line 559) Matrix must be positive definite." Can you help me to figure out what happened? thanks a lot. Note: df_ttest = 27
1 Commento
Walter Roberson
il 6 Gen 2017
Note: df_ttest is not defined in your .mat or your code.
However, that line of your code is not reached until after hac() has worked, so it is not a primary problem.
Risposte (2)
Hang Qian
il 6 Gen 2017
Hi Lucia,
Thank you for reporting this edge case.
The codes work on my Windows computer both in R2016a and R2016b. The results are the same as what you reported. Your hardware and software platforms might be different than mine. Occasionally, the results could be different in edge cases. It appears that the error message comes from the Cholesky decomposition of a matrix (named PhiHat in line 557). When I run the codes, I saw that matrix is ill-conditioned, and thus it is possible that Cholesky decomposition fails on your computer.
The predictor matrix X has some problems in this case. The values of the third variable are all zeros except for a single observation being one. Meanwhile, a constant term is included as the first predictor. The data have strong collinearity. A regression might not work well for that dataset.
Also, try to adjust the scale of the regressors, either by the data scale or the OLS estimator scale. It may help improve conditioning and overcome the edge case.
Regards,
Hang Qian
Walter Roberson
il 6 Gen 2017
A model is constructed fitting the data. The 5th row of the data is predicted exactly, residual 0. That leads to a u matrix that contains a 0, which leads to a scores matrix, V, which contains a row of 0, which leads to a covariance matrix PhiHat which is not full rank, which requires there to be an eigenvalue of 0. The matrix is not positive definite, only positive semi-definite, so chol() fails. Due to round-off error if you eig(PhiHat) you might see a slightly negative eigenvalue (around 1E-18) but if you compute the eigenvalue symbolically you can find it is exactly 0.
I do not know why it happens to be the 5th row which is predicted exactly. Hang Qian's discussion of the third row might be the key point.
4 Commenti
Walter Roberson
il 6 Gen 2017
This issue traces back to different outputs from qr() for the same inputs. I do not see a Release Note related to qr or anything numeric; the closest I see is the R2016b release note,
Performance is improved for MATLAB code that is dominated by tight loops, straightforward indexing, and simple math.
which does not apply for qr()
Walter Roberson
il 7 Gen 2017
I created a service request about the undocumented change to qr() as of R2016a.
Vedere anche
Categorie
Scopri di più su Testing Frameworks in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!