bfast2 / bfast2/strucchangeRcpp
mefp: Error in root.matrix(crossprod(X)): matrix is not positive semidefinite
- Dominant language
- R
- Stars
- 6
- Forks
- 5
- PR merge metrics
- No merged PRs in 30d
Description
I have run into a (rare) case where the root of a matrix cannot be found because it's indefinite. Here's a reprex using the bfast package:
``` r
library(bfast)
BugTS = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NA, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NA, NA, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NA, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, NA, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NA, 2, 2, 3, 5, NA, NA, 3, 2, 3, 2, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, NA, 0, 1, NA, 0, 1)
BugTS = ts(BugTS, start=2009, frequency = 23)
bfastmonitor(BugTS, start=2016, type = "ME")
#> Error in root.matrix(crossprod(X)): matrix is not positive semidefinite
```
Created on 2020-04-07 by the [reprex package](https://reprex.tidyverse.org) (v0.3.0)
Using @appelmar's C++ code, the same error is rendered as:
```r
Error in .sc_cpp_efp_process_me(X, y, rescale, h) :
sqrtmat_sympd(): transformation failed
```
This fails when `type` is set to `ME`, but it works with any other `mefp` types.
Is there a way to detect that this would happen, and then fall back to some other fluctuation process type instead?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.