Skip to content

mefp: Error in root.matrix(crossprod(X)): matrix is not positive semidefinite #22

@GreatEmerald

Description

@GreatEmerald

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 semidefinite

Created 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 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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions