Em 24 de agosto de 2017, Ioannis Venetis escreveu:
(...)
I stick to real symmetric matrices. I think the eigengen and eigensym use
different algorithms to compute eigenvectors that's why there might be
differences in sign for some eigenvectors.
I do not know the intrinsics of the algorithms so i cannot tell why
patricular eigenvecs have the same and some have different sign.
However, due to sign being non-identified "it does not matter". You must
have extra information to identify depending on your purposes.
The pca does not know what sign to assign. I think (correct me if i am
wrong)
pca uses princomp which uses eigensym and not eigengen.
(...)
Dear Yiannis,
Thanks a lot! I replaced the eigengen for eigensym and now the signals
are just fine. Please take a look at the new (and complete) code:
<hansl>
set echo off
set messages off
open AWM.gdt --quiet
list L = CAN COMPR EEN FDD HICP ITN KSR
smpl ok(L) --restrict
printf "\n########## Gretl's native PCA ##########\n\n"
pca L
printf "\n########## Alternative 2: PCA (using 'eigensym' function)
##########\n\n"
matrix X = {L}
matrix C = mcorr(X)
matrix Eigenvector = {}
matrix Eigenvalue = mreverse(eigensym(C, &Eigenvector))
matrix Eigenvector = mreverse(Eigenvector')'
matrix Proportion = zeros(rows(Eigenvalue), 1)
matrix Cumulative = zeros(rows(Eigenvalue), 1)
loop i = 1..rows(Eigenvalue) --quiet
Proportion[i, 1] = Eigenvalue[i, 1]/sumc(Eigenvalue)
Cumulative[i, 1] = sumc(Proportion[1:i])
endloop
matrix Eigenvalue = Eigenvalue ~ Proportion ~ Cumulative
rownames(Eigenvalue, "1 2 3 4 5 6 7")
colnames(Eigenvalue, "Eigenvalue Proportion Cumulative")
rownames(Eigenvector, "CAN COMPR EEN FDD HICP ITN KSR")
colnames(Eigenvector, "PC1 PC2 PC3 PC4 PC5 PC6 PC7")
printf "Principal Components Analysis\nn = %d\n\n", rows(X)
printf "Eigenanalysis of the Correlation Matrix\n\n"
printf "%15.4f\n", Eigenvalue
printf "Eigenvectors (component loadings)\n\n"
printf "%10.3f\n", Eigenvector
</hansl>
Um abraço,
Henrique Andrade