-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Labels
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:
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 semidefiniteCreated on 2020-04-07 by the reprex package (v0.3.0)
Using @appelmar's C++ code, the same error is rendered as:
Error in .sc_cpp_efp_process_me(X, y, rescale, h) :
sqrtmat_sympd(): transformation failedThis 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?