[GRASS-user] i.pca vs. r.covar/m.eigensystem/r.mapcalc
Nikos Alexandris
nikos.alexandris at felis.uni-freiburg.de
Sat Oct 11 18:20:20 EDT 2008
I wanted to check/verify some i.pca results so I calculated 2 principal
components using r.covar, m.eigensystem and r.mapcalc. The results are
not the same with i.pca's output.
(Maybe this post http://www.nabble.com/Eigen-vectors-tt15686112.html was
about the same issue)
# i.pca performed on (3) modis surface reflectance bands (2, 6 and 7 -
500m spatial resolution)
r.info pca.2007.242.500.b267.1 -h
[...]
Eigen vectors:
( -0.64 -0.65 -0.42 )
( -0.71 0.29 0.64 )
( 0.29 -0.70 0.65 )
[...]
# calculating "by hand"
## (a) based on covariance
r.covar
map=MOD2007_242_500_sur_refl_b02,MOD2007_242_500_sur_refl_b06,MOD2007_242_500_sur_refl_b07 > covariance_b67
# eigenvalues and eigenvectors
(echo 3; cat covariance_b67) | m.eigensystem
E 193252.2225840657 0.0000000000 19.81
V 0.8480879794 0.0000000000
V -0.0973632655 0.0000000000
V -0.5621384304 0.0000000000
N 0.8297330080 0.0000000000
N -0.0952560549 0.0000000000
N -0.5499721988 0.0000000000
W 364.7544643092 0.0000000000
W -41.8750018841 0.0000000000
W -241.7703198653 0.0000000000
E 770286.8983235050 0.0000000000 78.97
V 0.5123041585 0.0000000000
V 0.8425333994 0.0000000000
V 0.6269758062 0.0000000000
N 0.4384249584 0.0000000000
N 0.7210319581 0.0000000000
N 0.5365598486 0.0000000000
W 384.7880047100 0.0000000000
W 632.8208355692 0.0000000000
W 470.9170625750 0.0000000000
E 11834.0908624288 0.0000000000 1.21
V 0.2892235465 0.0000000000
V -0.5746367180 0.0000000000
V 0.5358742690 0.0000000000
N 0.3454369570 0.0000000000
N -0.6863229556 0.0000000000
N 0.6400266474 0.0000000000
W 37.5782238381 0.0000000000
W -74.6613734450 0.0000000000
W 69.6250477264 0.0000000000
## (b) based on correlation
r.covar -r
map=MOD2007_242_500_sur_refl_b02,MOD2007_242_500_sur_refl_b06,MOD2007_242_500_sur_refl_b07 > correlation_b267
# eigenvalues and eigenvectors
(echo 3; cat correlation_b267) | m.eigensystem
E 2.2858261608 0.0000000000 76.19
V -0.5735822577 0.0000000000
V -0.7657536915 0.0000000000
V -0.6794534712 0.0000000000
N -0.4887914931 0.0000000000
N -0.6525548605 0.0000000000
N -0.5790121159 0.0000000000
W -0.7390013610 0.0000000000
W -0.9865943596 0.0000000000
W -0.8754054597 0.0000000000
E 0.6796466529 0.0000000000 22.65
V 0.8645087622 0.0000000000
V -0.1090761065 0.0000000000
V -0.6068722494 0.0000000000
N 0.8141383928 0.0000000000
N -0.1027208167 0.0000000000
N -0.5715130018 0.0000000000
W 0.6711812672 0.0000000000
W -0.0846837448 0.0000000000
W -0.4711592330 0.0000000000
E 0.0345271863 0.0000000000 1.15
V 0.2515640507 0.0000000000
V -0.6024904816 0.0000000000
V 0.4666495170 0.0000000000
N 0.3134669897 0.0000000000
N -0.7507466869 0.0000000000
N 0.5814790267 0.0000000000
W 0.0582468451 0.0000000000
W -0.1394999392 0.0000000000
W 0.1080474816 0.0000000000
# range for i.pca's pc 1
r.info pca.2007.242.500.b267.1 -r
min=-7713.335449
max=-21.046232
# range for i.pca's pc 2
r.info pca.2007.242.500.b267.2 -r
min=-2313.784484
max=1838.939406
# calculating PC 1 and 2 "by hand"
# pc 1
r.mapcalc testpca1="(-0.64)*MOD2007_242_500_sur_refl_b02 +
(-0.65)*MOD2007_242_500_sur_refl_b06 +
(-0.42)*MOD2007_242_500_sur_refl_b07"
# range of testpca1
min=-7743.680000
max=-87.370000
# pc 2
r.mapcalc testpca2="(-0.71)*MOD2007_242_500_sur_refl_b02 +
0.29*MOD2007_242_500_sur_refl_b06 + 0.64*MOD2007_242_500_sur_refl_b07"
# range of testpca2
min=-2283.720000
max=1866.570000
Can someone explain which values (V or N or W) correspond to the
eigenvectors reported by i.pca? I don't think they coincide. But, as far
as I understand the PCA concept, they should or they should be close
enough.
Kind regards, Nikos
More information about the grass-user
mailing list