Re: Principal component analysis [message #57133] |
Wed, 05 December 2007 08:13  |
Haje Korth
Messages: 651 Registered: May 1997
|
Senior Member |
|
|
Mort,
thanks for validating this. I tend to just go with PCOMP since I don't
really know what the IMSL routine actually does. As I wrote in the response
to David I just got thrown off by not being able to reconcile the output
from the different routines.
Thanks,
Haje
"mort canty" <m.canty@fz-juelich.de> wrote in message
news:fj6fp9$4jl8$1@zam602.zam.kfa-juelich.de...
> Haje Korth schrieb:
>> Hi,
>> I am puzzled by principal component analysis. I calculated the
>> eigenvalues using both PCOMP and IMSP_PRINC_COMP routines. Could someone
>> enlighten me why the results are completely different? I have tried
>> different keywords to see whether I can match them by trial and error,
>> but I had no success. There must be someone out there who undertstands
>> this much better than I do.
>>
>> Thanks so much,
>> Haje
>>
>>
>> IDL> a=[[1,-2,-6],[-2,1,-3],[-6,-3,5]]
>> IDL> pca=pcomp(a,eigenvalues=ev) & print,transpose(ev)
>> 2.24227 0.757732 0.000000
>> IDL> ev=imsl_princ_comp(a) & print,ev
>> 9.53359 -5.19751 2.66392
>
> Haven't the foggiest what imsl_princ_comp() does, but pcomp() is correct:
>
> pro pca
> a=[[1,-2,-6],[-2,1,-3],[-6,-3,5]]
> ; covariance matrix
> s1 = correlate(a,/covariance)
> print, s1, ' '
> ; correlation matrix
> s2 = correlate(a)
> print, s2, ' '
> ; diagonalize
> print, eigenql(s1)
> print, eigenql(s2), ' '
> ; compare
> pca=pcomp(a,eigenvalues=ev,/covariance) & print,transpose(ev)
> pca=pcomp(a,eigenvalues=ev) & print,transpose(ev)
> end
>
> 12.3333 2.33333 -19.6667
> 2.33333 4.33333 -5.66667
> -19.6667 -5.66667 32.3333
>
> 1.00000 0.319173 -0.984839
> 0.319173 1.00000 -0.478731
> -0.984839 -0.478731 1.00000
>
> 45.2906 3.70938-1.52795e-006
> 2.24227 0.757732-5.49480e-008
>
> 45.2906 3.70938-1.52795e-006
> 2.24227 0.757732 0.000000
>
> Mort
|
|
|