[R] matrix bending
Patrick Burns
pburns at pburns.seanet.com
Mon Dec 1 19:30:39 CET 2003
Here is a function that I use for symmetric matrices:
make.positive.definite <-
function(x, tol=1e-6) {
eig <- eigen(x, symmetric=TRUE)
rtol <- tol * eig$values[1]
if(min(eig$values) < rtol) {
vals <- eig$values
vals[vals < rtol} <- rtol
srev <- eig$vectors %*% (vals * t(eig$vectors))
dimnames(srev) <- dimnames(x)
return(srev)
} else {
return(x)
}
}
Patrick Burns
Burns Statistics
patrick at burns-stat.com
+44 (0)20 8525 0696
http://www.burns-stat.com
(home of S Poetry and "A Guide for the Unwilling S User")
jarrod.hadfield at imperial.ac.uk wrote:
> Dear All,
>
> I was wondering whether any one knows of a matrix bending function in
> R that can turn non-positive definite matrices into the nearest
> positive definite matrix. I was hoping there would be something akin
> to John Henshall's flbend program
> (http://agbu.une.edu.au/~kmeyer/pdmatrix.html), which allows the
> standard errors of the estimated matrix elements to be considered in
> the bending process.
>
> Thanks,
>
> Jarrod.
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>
>
More information about the R-help
mailing list