# [S] S+ negative eigenvalue from eigen(), not from svd()

Tom Burr (tburr@lanl.gov)
Fri, 01 May 1998 10:59:34 -0600

Hello,
Can someone tell me how to modify var() in S+ so that it always
produces a positive definite matrix when applied to any
n-by-p matrix with n>p. Or, maybe someone can tell me that var() already
does that, but that eigen() can fail to produce the "true"
eigenvalues. Below you'll see that I get a negative eigenvalue
using eigen() but all postive eigenvalues using svd()--
I suppose I'm asking something in the "numerical stability"
area where I get uncomfortable pretty quickly.

Here is an 8 by 7 matrix, say temp, that is
very poorly conditioned.

temp:
0.0 1.0 2.0 3.0 4.0 5.0 6.0
0.0 1.0 2.0 3.0 4.0 5.0 5.0
0.0 1.0 2.0 3.0 4.0 4.0 4.0
6.0 5.0 4.0 3.0 2.0 1.0 0.0
6.0 5.0 4.0 3.0 2.0 1.0 1.0
6.0 5.0 4.0 3.0 2.0 2.0 2.0
1.0 1.0 1.0 1.0 1.0 1.0 1.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0

> var(temp)
[,1] [,2] [,3] [,4] [,5] [,6]
[,7]
[1,] 9.125000 6.5535714 3.98214286 1.410714 -1.1607143 -2.87500000
-3.7321429
[2,] 6.553571 4.8392857 3.12500000 1.410714 -0.3035714 -1.44642857
-2.0178571
[3,] 3.982143 3.1250000 2.26785714 1.410714 0.5535714 -0.01785714
-0.3035714
[4,] 1.410714 1.4107143 1.41071429 1.410714 1.4107143 1.41071429
1.4107143
[5,] -1.160714 -0.3035714 0.55357143 1.410714 2.2678571 2.83928571
3.1250000
[6,] -2.875000 -1.4464286 -0.01785714 1.410714 2.8392857 3.98214286
4.5535714
[7,] -3.732143 -2.0178571 -0.30357143 1.410714 3.1250000 4.55357143
5.4107143
> eigen(var(temp))
\$values:
[1] 1.907736e+001 9.930884e+000 2.622073e-001 3.311722e-002
9.583994e-016 1.843151e-016 -2.367552e-016

alternate using svd:
svd(var(temp))
\$d:
[1] 1.907736e+001 9.930884e+000 2.622073e-001 3.311722e-002 7.682346e-016
5.022829e-016 1.477306e-019

THANKS!!!!

Tom Burr

PS. I do recover var(temp) using the output (eigenvectors and values)
of either eigen() or svd()
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news