8000 CovEst.hardPD does not give positive definite matrix? · Issue #3 · kisungyou/CovTools · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
CovEst.hardPD does not give positive definite matrix? #3
Open
@MatthieuStigler

Description

@MatthieuStigler

CovEst.hardPD() does not give a matrix that is positive definite? See code below

I believe this comes from the second search, which searches within the "first non pd" (Cvec1[iter]) to the last "pd" (Cvec1[iter-1]). It starts from the lowest, and then see if it is non pd. So this will stop at the first value (first non pd), and hence returns a non-pd value!?

Solution is probably either to inverse the line: Cvec2 = seq(from=Cvec1[iter], to=Cvec1[iter-1], length.out=20), or to change the sign in the second if ((min(eigen(tmpS, only.values=TRUE)$values)) < sqrt(.Machine$double.eps)){ to stop at the first pd?

Thanks!

library(CovTools)

pdim <- 20
data <- matrix(rnorm(10*pdim), ncol=pdim)

out4 <- CovEst.hardPD(data) 
min(eigen(out4$S, only.values = TRUE)$values)
#> [1] -0.2785753

## verify with matrixcalc
matrixcalc::is.positive.definite(out4$S)
#> [1] FALSE

Created on 2021-05-05 by the reprex package (v2.0.0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0