<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://grasswiki.osgeo.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=%E2%9A%A0%EF%B8%8FEdzerPebesma</id>
	<title>GRASS-Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://grasswiki.osgeo.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=%E2%9A%A0%EF%B8%8FEdzerPebesma"/>
	<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/wiki/Special:Contributions/%E2%9A%A0%EF%B8%8FEdzerPebesma"/>
	<updated>2026-05-10T05:55:11Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=Principal_Components_Analysis&amp;diff=8576</id>
		<title>Principal Components Analysis</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=Principal_Components_Analysis&amp;diff=8576"/>
		<updated>2009-03-31T14:26:28Z</updated>

		<summary type="html">&lt;p&gt;⚠️EdzerPebesma: /* Using R's princomp() function */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Under Construction'''&lt;br /&gt;
&lt;br /&gt;
This page is a short and practical introduction in Principal Component Analysis. It aims to highlight the importance of the values returned by PCA. In addition, it addresses numerical accuracy issues with respect to the default implementation of PCA in GRASS through the ''i.pca'' module.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Principal Component Analysis =&lt;br /&gt;
&lt;br /&gt;
Principal Component Analysis (PCA) is a dimensionality reduction technique used extensively in Remote Sensing studies (e.g. in change detection studies, image enhancement tasks and more). PCA is in fact a linear transformation applied on (usually) highly correlated multidimensional (e.g. multispectral) data. The input dimensions are transformed in a new coordinate system in which the produced dimensions (called principal components) contain, in decreasing order, the greatest variance related with unchanged landscape features.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PCA has two algebraic solutions:&lt;br /&gt;
&lt;br /&gt;
* '''Eigenvectors of Covariance''' (or Correlation)&lt;br /&gt;
* '''Singular Value Decomposition'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The '''SVD''' method is used for numerical accuracy [R Documentation]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
The basic steps of the transformation are:&lt;br /&gt;
&lt;br /&gt;
# '''organizing a dataset in a matrix'''&lt;br /&gt;
# '''data centering''' (that is: subtracting the dimensions means from themself so each of the dimensions in the dataset has zero mean)&lt;br /&gt;
# calculate&lt;br /&gt;
#* the '''covariance matrix''' ('''non-standardised PCA''') or&lt;br /&gt;
#* the '''correlation matrix''' ('''standardised PCA''', also known as scaling)&lt;br /&gt;
# calculate either&lt;br /&gt;
#* the '''eigenvectors''' and '''eigenvalues''' of the covariance (or the correlation) matrix or&lt;br /&gt;
#* the '''SVD''' of the data matrix&lt;br /&gt;
# '''sort variances in decreasing order''' (decreasing eigenvalues; this is default in eigenvalue analysis)&lt;br /&gt;
# '''project original dataset ''signals''''' (PC's or PC scores: eigenvector * input-data) to get&lt;br /&gt;
&lt;br /&gt;
== Solutions to PCA ==&lt;br /&gt;
&lt;br /&gt;
The '''Eigenvector''' solution to PCA involves:&lt;br /&gt;
&lt;br /&gt;
# calculation of&lt;br /&gt;
#* the covariance matrix of the given multidimensional dataset (non-standardised PCA) '''''or'''''&lt;br /&gt;
#* the correlation matrix of the given multidimensional dataset (standardised PCA)&lt;br /&gt;
# calculation of the eigenvalues and eigenvectors of the covariance (or correlation) matrix&lt;br /&gt;
# transformation of the input dataset using the eigenvalues as weighting coefficients&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
&lt;br /&gt;
'''eigenvalues''' represent either the variance of the original data contained in each principal component (in case they were computed from the covariance matrix), or the amount of correlation captured by the respective principle components (in case they were computed from the correlation matrix).&lt;br /&gt;
&lt;br /&gt;
'''eigenvectors''' act as weighting coefficients / represent the contribution of each original dimension the principal components / tell how the principle components relate to the the data variables (dimensions). Suppose an eigenvector is (0, 0, 1, 0), this indicates that the corresponding principle component is equal to dimension 3 and perpendicular to dimensions 1, 3 and 4. If it is (0.7, 0.7, 0, 0) the PC is equally determined by dimension 1 and 2 (it averages them), and not determined by dimensions 3 and 4. If it is (0.7, 0, -0.7, 0) it is the difference between dimension 1 and 3. Eigenvectors are normalized, meaning that the sum of its squared elements equals 1. &lt;br /&gt;
&lt;br /&gt;
'''loadings''' The individual numbers in an eigenvector are called loadings.&lt;br /&gt;
&lt;br /&gt;
'''scores''' When the original data are projected onto the eigenvectors, the resulting new variables are called the principle components; the new data values are called PC scores.&lt;br /&gt;
&lt;br /&gt;
== Performing PCA with GRASS ==&lt;br /&gt;
&lt;br /&gt;
* '''''m.eigensystem'''''&lt;br /&gt;
&lt;br /&gt;
The ''m.eigensystem'' module implements the eigenvector solution to PCA. The respective function in R is ''princomp()''. A comparison of their results confirms their almost identical performance. Specifically,&lt;br /&gt;
&lt;br /&gt;
# the standard deviations (sdev) reported by ''princomp()'' are (almost) identical with the variances (eigenvalues) reported by ''m.eigensystem''.&lt;br /&gt;
&lt;br /&gt;
# ''princomp()'' scales (also referred as normalization) the eigenvectors and so does ''m.eigensystem''. The scaled(=normalised) eigenvectors produced by m.eigensystem are marked with the capital letter N.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''''i.pca'''''&lt;br /&gt;
&lt;br /&gt;
The ''i.pca'' module performs PCA based on the SVD solution without data centering and/or scaling. A comparison of the results derived by ''i.pca'' and R's ''prcomp()'' function confirms this. Specifically, ''i.pca'' yields the same eigenvectors as R's ''prcomp()'' function does with the following options:&lt;br /&gt;
&lt;br /&gt;
 prcomp(x, center=FALSE, scale=FALSE)&lt;br /&gt;
&lt;br /&gt;
where x is a numeric or complex matrix (or data frame) which provides the data for the principal components analysis (R Documentation).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Issues concerning the ''i.pca'' module ==&lt;br /&gt;
&lt;br /&gt;
??? To add... ???&lt;br /&gt;
&lt;br /&gt;
== Issues concerning R's ''princomp()'' function ==&lt;br /&gt;
&lt;br /&gt;
If one computes principle components with R, the loadings are printed by default such that loadings close to 0 (between -.1 and .1, this can be controlled) are left out. This can be overriden (see the help page of function loadings). The reason for this is that for large loading tables, the real information is in loadings not close to 0; reading large loading tables is much easier when only important loadings are printed.&lt;br /&gt;
&lt;br /&gt;
= Examples using SPOT imagery =&lt;br /&gt;
Get the SPOT imagery from the Spearfish dataset: [http://grass.osgeo.org/sampledata/imagery60_grassdata.tar.gz SPOT images from the Spearfish dataset]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Eigenvectors solution ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Based on the covariance matrix ===&lt;br /&gt;
&lt;br /&gt;
==== Using '''''m.eigensystem''''' ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command in one line&lt;br /&gt;
&lt;br /&gt;
 (echo 3; r.covar spot.ms.1,spot.ms.2,spot.ms.3) | m.eigensystem&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
 r.covar: complete ...&lt;br /&gt;
  100%&lt;br /&gt;
 E      1159.7452017844          .0000000000    88.38&lt;br /&gt;
 V          .6910021591          .0000000000&lt;br /&gt;
 V          .7205280412          .0000000000&lt;br /&gt;
 V          .4805108400          .0000000000&lt;br /&gt;
 N          .6236808478          .0000000000&lt;br /&gt;
 N          .6503301526          .0000000000&lt;br /&gt;
 N          .4336967751          .0000000000&lt;br /&gt;
 W        21.2394712045          .0000000000&lt;br /&gt;
 W        22.1470141296          .0000000000&lt;br /&gt;
 W        14.7695575384          .0000000000&lt;br /&gt;
 E         5.9705414972          .0000000000      .45&lt;br /&gt;
 V          .7119385973          .0000000000&lt;br /&gt;
 V         -.6358200627          .0000000000&lt;br /&gt;
 V         -.0703936743          .0000000000&lt;br /&gt;
 N          .7438340890          .0000000000&lt;br /&gt;
 N         -.6643053754          .0000000000&lt;br /&gt;
 N         -.0735473745          .0000000000&lt;br /&gt;
 W         1.8175356507          .0000000000&lt;br /&gt;
 W        -1.6232096923          .0000000000&lt;br /&gt;
 W         -.1797107407          .0000000000&lt;br /&gt;
 E       146.5031967184          .0000000000    11.16&lt;br /&gt;
 V          .2265837636          .0000000000&lt;br /&gt;
 V          .3474697082          .0000000000&lt;br /&gt;
 V         -.8468727535          .0000000000&lt;br /&gt;
 N          .2402770238          .0000000000&lt;br /&gt;
 N          .3684685345          .0000000000&lt;br /&gt;
 N         -.8980522763          .0000000000&lt;br /&gt;
 W         2.9082771721          .0000000000&lt;br /&gt;
 W         4.4598880523          .0000000000&lt;br /&gt;
 W       -10.8698904856          .0000000000&lt;br /&gt;
&lt;br /&gt;
==== Using R's '''''princomp()''''' function ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Launch R from within GRASS&lt;br /&gt;
 R&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Load spgrass6() and projection information in R&lt;br /&gt;
 library(spgrass6)&lt;br /&gt;
 G &amp;lt;- gmeta6()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Read spot.ms bands&lt;br /&gt;
 spot.ms &amp;lt;- readRAST6(c('spot.ms.1', 'spot.ms.2', 'spot.ms.3'))&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Work around NA's&lt;br /&gt;
 spot.ms.nas &amp;lt;- which(is.na(spot.ms@data$spot.ms.1) &amp;amp; is.na(spot.ms@data$spot.ms.2) &amp;amp; is.na(spot.ms@data$spot.ms.3))&lt;br /&gt;
 spot.ms.values &amp;lt;- which(!is.na(spot.ms@data$spot.ms.1) &amp;amp; !is.na(spot.ms@data$spot.ms.2) &amp;amp; !is.na(spot.ms@data$spot.ms.3))&lt;br /&gt;
 spot.ms.nonas &amp;lt;- spot.ms.values@data[spot.ms.values, ]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 princomp(spot.ms.nonas)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Call:&lt;br /&gt;
 princomp(x = modis)&lt;br /&gt;
 Standard deviations:&lt;br /&gt;
   Comp.1   Comp.2   Comp.3&lt;br /&gt;
 34.055018 12.103846  2.443468&lt;br /&gt;
 &lt;br /&gt;
 3  variables and  1231860 observations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Get loadings&lt;br /&gt;
&lt;br /&gt;
 princomp(spot.ms.nonas)$loadings&lt;br /&gt;
 Loadings:&lt;br /&gt;
     Comp.1 Comp.2 Comp.3&lt;br /&gt;
 spot.ms.1 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.624'''&amp;lt;/span&amp;gt;  0.240  0.744&lt;br /&gt;
 spot.ms.2 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.650'''&amp;lt;/span&amp;gt; -0.368 -0.664&lt;br /&gt;
 spot.ms.3 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.434'''&amp;lt;/span&amp;gt;  0.898 &lt;br /&gt;
 &lt;br /&gt;
                Comp.1 Comp.2 Comp.3&lt;br /&gt;
 SS loadings     1.000  1.000  1.000&lt;br /&gt;
 Proportion Var  0.333  0.333  0.333&lt;br /&gt;
 Cumulative Var  0.333  0.667  1.000&lt;br /&gt;
&lt;br /&gt;
The '''bold''' and &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;red&amp;lt;/span&amp;gt; colored loadings, that is, the eigen vectors of the first principal component, ease of the comparison with the results derived from GRASS' ''m.eigensystem'' module above. Note the missing eigen value in row 3, column 3. It is omitted on purpose. You will appreciate how useful this is when you compute 20 PC's from 120 dimensions. It will be printed when you explicitly ask for showing loadings between -.1 and .1, by&lt;br /&gt;
&lt;br /&gt;
 print(princomp(spot.ms.nonas)$loadings, cutoff=0)&lt;br /&gt;
&lt;br /&gt;
=== Based on the correlation matrix ===&lt;br /&gt;
&lt;br /&gt;
==== Using '''''m.eigensystem'''''====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command in one line&lt;br /&gt;
&lt;br /&gt;
 (echo 3; r.covar -r spot.ms.1,spot.ms.2,spot.ms.3) | m.eigensystem&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 r.covar: complete ...&lt;br /&gt;
  100%&lt;br /&gt;
 E         2.5897901435          .0000000000    86.33&lt;br /&gt;
 V         -.7080795162          .0000000000&lt;br /&gt;
 V         -.6979341819          .0000000000&lt;br /&gt;
 V         -.6128387525          .0000000000&lt;br /&gt;
 N         -.6062688915          .0000000000&lt;br /&gt;
 N         -.5975822957          .0000000000&lt;br /&gt;
 N         -.5247222419          .0000000000&lt;br /&gt;
 W         -.9756579133          .0000000000&lt;br /&gt;
 W         -.9616787268          .0000000000&lt;br /&gt;
 W         -.8444263177          .0000000000&lt;br /&gt;
 E          .0123265666          .0000000000      .41&lt;br /&gt;
 V         -.6690685456          .0000000000&lt;br /&gt;
 V          .6302711261          .0000000000&lt;br /&gt;
 V          .0552608155          .0000000000&lt;br /&gt;
 N         -.7265842171          .0000000000&lt;br /&gt;
 N          .6844516242          .0000000000&lt;br /&gt;
 N          .0600112449          .0000000000&lt;br /&gt;
 W         -.0806690651          .0000000000&lt;br /&gt;
 W          .0759912909          .0000000000&lt;br /&gt;
 W          .0066627528          .0000000000&lt;br /&gt;
 E          .3978832898          .0000000000    13.26&lt;br /&gt;
 V          .3005969725          .0000000000&lt;br /&gt;
 V          .3883277727          .0000000000&lt;br /&gt;
 V         -.7895613377          .0000000000&lt;br /&gt;
 N          .3232853332          .0000000000&lt;br /&gt;
 N          .4176378502          .0000000000&lt;br /&gt;
 N         -.8491555920          .0000000000&lt;br /&gt;
 W          .2039218921          .0000000000&lt;br /&gt;
 W          .2634375639          .0000000000&lt;br /&gt;
 W         -.5356302845          .0000000000&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Using R's '''''princomp()''''' function ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Perform PCA&lt;br /&gt;
&lt;br /&gt;
 princomp(spot.ms.nonas, cor=TRUE)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Call:&lt;br /&gt;
 princomp(x = spot.ms.nonas, cor = TRUE)&lt;br /&gt;
 &lt;br /&gt;
 Standard deviations:&lt;br /&gt;
    Comp.1    Comp.2    Comp.3 &lt;br /&gt;
 1.6092826 0.6307795 0.1110256&lt;br /&gt;
 &lt;br /&gt;
 3  variables and  1231860 observations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Get loadings &lt;br /&gt;
&lt;br /&gt;
 princomp(spot.ms.nonas, cor=TRUE)$loadings&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Loadings:&lt;br /&gt;
           Comp.1 Comp.2 Comp.3&lt;br /&gt;
 spot.ms.1 -0.606 -0.323  0.727&lt;br /&gt;
 spot.ms.2 -0.598 -0.418 -0.684&lt;br /&gt;
 spot.ms.3 -0.525  0.849       &lt;br /&gt;
 &lt;br /&gt;
                Comp.1 Comp.2 Comp.3&lt;br /&gt;
 SS loadings     1.000  1.000  1.000&lt;br /&gt;
 Proportion Var  0.333  0.333  0.333&lt;br /&gt;
 Cumulative Var  0.333  0.667  1.000&lt;br /&gt;
&lt;br /&gt;
== SVD solution ==&lt;br /&gt;
&lt;br /&gt;
==== Using ''i.pca'' ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 i.pca input=spot.ms.1,spot.ms.2,spot.ms.3 out=pca.spot.ms rescale=0,0&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
  Eigen values, (vectors), and [percent importance]:&lt;br /&gt;
   PC1   '''1170.12''' (&amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.6251,-0.6536,-0.4268&amp;lt;/span&amp;gt;)[88.07%]&lt;br /&gt;
   PC2    152.49 ( 0.2328, 0.3658,-0.9011)[11.48%]&lt;br /&gt;
   PC3      6.01 ( 0.7450,-0.6626,-0.0765) [0.45%]&lt;br /&gt;
&lt;br /&gt;
==== Using R's ''prcomp()'' function ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following example replicates ''i.pca'''s solution using the same data '''with data centering and without scaling''' (options ''center=TRUE'' and ''scale=FALSE''). Note that these settings are the defaults.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 prcomp(spot.ms.nonas)&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Standard deviations:&lt;br /&gt;
 [1] 34.055032 12.103851  2.443469&lt;br /&gt;
 &lt;br /&gt;
 Rotation:&lt;br /&gt;
                  PC1        PC2         PC3&lt;br /&gt;
 spot.ms.1 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.6236808&amp;lt;/span&amp;gt;  0.2402770 -0.74383409&lt;br /&gt;
 spot.ms.2 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.6503302&amp;lt;/span&amp;gt;  0.3684685  0.66430538&lt;br /&gt;
 spot.ms.3 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.4336968&amp;lt;/span&amp;gt; -0.8980523  0.07354738&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Comments]]&lt;br /&gt;
&lt;br /&gt;
In this example ''i.pca'''s performance seems to be identical to R's ''prcomp()'' function which means that data centering is applied prior to the actual PCA.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The three SPOT bands used in this example have the following ranges:&lt;br /&gt;
&lt;br /&gt;
*spot.ms.1&lt;br /&gt;
&lt;br /&gt;
 min=24&lt;br /&gt;
 max=254&lt;br /&gt;
&lt;br /&gt;
*spot.ms.2&lt;br /&gt;
&lt;br /&gt;
 min=14&lt;br /&gt;
 max=254&lt;br /&gt;
*spot.ms.3&lt;br /&gt;
&lt;br /&gt;
 min=12&lt;br /&gt;
 max=254&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Nevertheless, as shown in the examples using MODIS surface reflectance products (read below) in which the range of the bands varies significantly, ''i.pca'''s results do not match the results of R's ''prcomp()'' function with the parameter ''center'' set to ''TRUE''. Instead, the results derived from ''i.pca'' are almost identical when the parameter ''center'' is set to ''FALSE''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following example performs PCA '''without data centering and scaling''' (options ''center=FALSE'' and ''scale=FALSE'').&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 prcomp(spot.ms.nonas, center=FALSE, scale=FALSE)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Standard deviations:&lt;br /&gt;
 [1] '''101.00927'''  15.79861   2.83775&lt;br /&gt;
 &lt;br /&gt;
 Rotation:&lt;br /&gt;
                  PC1        PC2        PC3&lt;br /&gt;
 spot.ms.1 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.5605487&amp;lt;/span&amp;gt; -0.3652694  0.7432116&lt;br /&gt;
 spot.ms.2 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.4726613&amp;lt;/span&amp;gt; -0.5958032 -0.6493149&lt;br /&gt;
 spot.ms.3 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.6799827&amp;lt;/span&amp;gt;  0.7152600 -0.1613280&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Comments]]&lt;br /&gt;
&lt;br /&gt;
+++&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following example performs PCA '''with data centering and scaling''' (options ''center=TRUE'' and ''scale=TRUE'')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 prcomp(spot.ms.nonas, center=TRUE, scale=TRUE)&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Standard deviations:&lt;br /&gt;
 [1] 1.6092826 0.6307795 0.1110256&lt;br /&gt;
 &lt;br /&gt;
 Rotation:&lt;br /&gt;
                  PC1        PC2         PC3&lt;br /&gt;
 spot.ms.1 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.6062688&amp;lt;/span&amp;gt;  0.3232856 -0.72658417&lt;br /&gt;
 spot.ms.2 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.5975823&amp;lt;/span&amp;gt;  0.4176378  0.68445170&lt;br /&gt;
 spot.ms.3 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.5247224&amp;lt;/span&amp;gt; -0.8491555  0.06001103&lt;br /&gt;
&lt;br /&gt;
= Examples using MODIS surface reflectance products =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Eigenvectors solution ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Based on the covariance matrix ===&lt;br /&gt;
&lt;br /&gt;
==== Using '''''m.eigensystem''''' ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command in one line&lt;br /&gt;
&lt;br /&gt;
 (echo 3; r.covar b02,b06,b07) | m.eigensystem&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E&amp;lt;/span&amp;gt; line is the eigen value. (Real part, imaginary part, percent importance)&lt;br /&gt;
* The &amp;lt;tt&amp;gt;V&amp;lt;/tt&amp;gt; lines are the eigen vectors associated with &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E&amp;lt;/span&amp;gt;.&lt;br /&gt;
* The &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N&amp;lt;/span&amp;gt; lines are the &amp;lt;tt&amp;gt;V&amp;lt;/tt&amp;gt; vectors normalized to have a magnitude of 1. '''These are the scaled eigen vectors that correspond to princomp()'s results presented in the following section.'''&lt;br /&gt;
* The &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W&amp;lt;/span&amp;gt; lines are the &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N&amp;lt;/span&amp;gt; vector multiplied by the square root of the magnitude of the eigen value (&amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E&amp;lt;/span&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
 r.covar: complete ...&lt;br /&gt;
 100%&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E    778244.0258462029          .0000000000    79.20&amp;lt;/span&amp;gt;&lt;br /&gt;
 V          .5006581842          .0000000000&lt;br /&gt;
 V          .8256483300          .0000000000&lt;br /&gt;
 V          .6155834548          .0000000000&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N          '''.4372107421'''          .0000000000&lt;br /&gt;
 N          '''.7210155161'''          .0000000000&lt;br /&gt;
 N          '''.5375717557'''          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W       385.6991853500          .0000000000&lt;br /&gt;
 W       636.0664787886          .0000000000&lt;br /&gt;
 W       474.2358050886          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E    192494.5769628266          .0000000000    19.59&amp;lt;/span&amp;gt;&lt;br /&gt;
 V         -.8689798010          .0000000000&lt;br /&gt;
 V          .0996340298          .0000000000&lt;br /&gt;
 V          .5731134848          .0000000000&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N         -.8309940700          .0000000000&lt;br /&gt;
 N          .0952787255          .0000000000&lt;br /&gt;
 N          .5480609638          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W      -364.5920328433          .0000000000&lt;br /&gt;
 W        41.8027823088          .0000000000&lt;br /&gt;
 W       240.4573848757          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E     11876.4548199713          .0000000000     1.21&amp;lt;/span&amp;gt;&lt;br /&gt;
 V          .2872248982          .0000000000&lt;br /&gt;
 V         -.5731591248          .0000000000&lt;br /&gt;
 V          .5351449518          .0000000000&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N          .3439413070          .0000000000&lt;br /&gt;
 N         -.6863370819          .0000000000&lt;br /&gt;
 N          .6408165005          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W        37.4824307850          .0000000000&lt;br /&gt;
 W       -74.7964308085          .0000000000&lt;br /&gt;
 W        69.8356366100          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In general, the solution to the eigen system results in complex&lt;br /&gt;
numbers (with both real and imaginary parts).  However, in the example&lt;br /&gt;
above, since the input matrix is symmetric (i.e., inverting the rows and columns&lt;br /&gt;
gives the same matrix) the eigen system has only real values (i.e., the&lt;br /&gt;
imaginary part is zero).&lt;br /&gt;
This fact makes it possible to use eigen vectors to perform principle component&lt;br /&gt;
transformation of data sets.  The covariance or correlation&lt;br /&gt;
matrix of any data set is symmetric&lt;br /&gt;
and thus has only real eigen values and vectors.&lt;br /&gt;
&lt;br /&gt;
'''Note''' The '''bold''' and &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;red&amp;lt;/span&amp;gt; colored eigen vectors of the first principal component, ease of the comparison with the results derived from R's ''princomp()'' function that follows.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Using the &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W&amp;lt;/span&amp;gt; vector, new maps can be created:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;B&amp;gt;r.mapcalc&amp;lt;/B&amp;gt; 'pc.1 =  &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;385.6992&amp;lt;/span&amp;gt;*map.1 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;+636.0665&amp;lt;/span&amp;gt;*map.2 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;+ 474.2358&amp;lt;/span&amp;gt;*map.3'&lt;br /&gt;
 &amp;lt;B&amp;gt;r.mapcalc&amp;lt;/B&amp;gt; 'pc.2 = &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;-364.5920&amp;lt;/span&amp;gt;*map.1 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;+ 41.8027&amp;lt;/span&amp;gt;*map.2 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;+ 240.4573&amp;lt;/span&amp;gt;*map.3'&lt;br /&gt;
 &amp;lt;B&amp;gt;r.mapcalc&amp;lt;/B&amp;gt; 'pc.3 =   &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;37.4824&amp;lt;/span&amp;gt;*map.1 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;- 74.7964&amp;lt;/span&amp;gt;*map.2 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;+  69.8356&amp;lt;/span&amp;gt;*map.3'&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Using R's '''''princomp()''''' function ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 princomp(modis)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Call:&lt;br /&gt;
 princomp(x = modis)&lt;br /&gt;
 Standard deviations:&lt;br /&gt;
   Comp.1   Comp.2   Comp.3&lt;br /&gt;
 857.5737 436.0922 108.5083&lt;br /&gt;
 3  variables and  350596 observations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Get loadings&lt;br /&gt;
&lt;br /&gt;
 (princomp(modis))$loadings&lt;br /&gt;
 Loadings:&lt;br /&gt;
     Comp.1 Comp.2 Comp.3&lt;br /&gt;
 b02 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.418'''&amp;lt;/span&amp;gt;  0.839  0.348&lt;br /&gt;
 b06 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.725'''&amp;lt;/span&amp;gt;        -0.684&lt;br /&gt;
 b07 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.547'''&amp;lt;/span&amp;gt; -0.539  0.641&lt;br /&gt;
&lt;br /&gt;
                Comp.1 Comp.2 Comp.3&lt;br /&gt;
 SS loadings     1.000  1.000  1.000&lt;br /&gt;
 Proportion Var  0.333  0.333  0.333&lt;br /&gt;
 Cumulative Var  0.333  0.667  1.000&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The '''bold''' and &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;red&amp;lt;/span&amp;gt; colored loadings, that is, the eigen vectors of the first principal component, ease of the comparison with the results derived from GRASS' ''m.eigensystem'' module above. Note the missing eigen value in row 2, column 2. For some reason R refused to yield it.&lt;br /&gt;
&lt;br /&gt;
=== Based on the correlation matrix ===&lt;br /&gt;
&lt;br /&gt;
==== Using '''''m.eigensystem'''''====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command in one line&lt;br /&gt;
&lt;br /&gt;
 (echo 3; r.covar -r MOD07_b02,MOD07_b06,MOD07_b07)|m.eigensystem&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 r.covar: complete ...&lt;br /&gt;
  100%&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E         2.2915877718          .0000000000    76.39&amp;lt;/span&amp;gt;&lt;br /&gt;
 V         -.5755655569          .0000000000&lt;br /&gt;
 V         -.7660355041          .0000000000&lt;br /&gt;
 V         -.6809380186          .0000000000&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N         -.4896413269          .0000000000&lt;br /&gt;
 N         -.6516766616          .0000000000&lt;br /&gt;
 N         -.5792830912          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W         -.7412186091          .0000000000&lt;br /&gt;
 W         -.9865075560          .0000000000&lt;br /&gt;
 W         -.8769182329          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E          .6740687010          .0000000000    22.47&amp;lt;/span&amp;gt;&lt;br /&gt;
 V          .8667178982          .0000000000&lt;br /&gt;
 V         -.1116525720          .0000000000&lt;br /&gt;
 V         -.6069908335          .0000000000&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N          '''.8145815825'''          .0000000000&lt;br /&gt;
 N         '''-.1049362531'''          .0000000000&lt;br /&gt;
 N         '''-.5704780699'''          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W          .6687852213          .0000000000&lt;br /&gt;
 W         -.0861544341          .0000000000&lt;br /&gt;
 W         -.4683721194          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E          .0343435272          .0000000000     1.14&amp;lt;/span&amp;gt;&lt;br /&gt;
 V          .2486404469          .0000000000&lt;br /&gt;
 V         -.6006166822          .0000000000&lt;br /&gt;
 V          .4655120098          .0000000000&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N          .3109794470          .0000000000&lt;br /&gt;
 N         -.7512029762          .0000000000&lt;br /&gt;
 N          .5822249325          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W          .0576307320          .0000000000&lt;br /&gt;
 W         -.1392129859          .0000000000&lt;br /&gt;
 W          .1078979635          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The '''bold''' and &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;red&amp;lt;/span&amp;gt; colored eigen vectors of the second principal component, ease of the comparison with the results derived from R's ''princomp()'' function that follows.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Using R's '''''princomp()''''' function ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 princomp(mod07, cor=TRUE)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Call:&lt;br /&gt;
 princomp(x = mod07, cor = TRUE)&lt;br /&gt;
&lt;br /&gt;
 Standard deviations:&lt;br /&gt;
    Comp.1    Comp.2    Comp.3&lt;br /&gt;
 1.5030740 0.8397807 0.1885121&lt;br /&gt;
 &lt;br /&gt;
  3  variables and  350596 observations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Get loadings&lt;br /&gt;
&lt;br /&gt;
 (princomp(mod07, cor=TRUE))$loadings&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Loadings:&lt;br /&gt;
                              Comp.1 Comp.2 Comp.3&lt;br /&gt;
 MOD2007_242_500_sur_refl_b02 -0.481  &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''0.820'''&amp;lt;/span&amp;gt;  0.310&lt;br /&gt;
 MOD2007_242_500_sur_refl_b06 -0.656 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.102'''&amp;lt;/span&amp;gt; -0.748&lt;br /&gt;
 MOD2007_242_500_sur_refl_b07 -0.582 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.563'''&amp;lt;/span&amp;gt;  0.587&lt;br /&gt;
 &lt;br /&gt;
                Comp.1 Comp.2 Comp.3&lt;br /&gt;
 SS loadings     1.000  1.000  1.000&lt;br /&gt;
 Proportion Var  0.333  0.333  0.333&lt;br /&gt;
 Cumulative Var  0.333  0.667  1.000&lt;br /&gt;
&lt;br /&gt;
The '''bold''' and &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;red&amp;lt;/span&amp;gt; colored loadings, that is, the eigen vectors of the second component, ease of the comparison with the results derived from GRASS' ''m.eigensystem'' module above.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Comments]]&lt;br /&gt;
'''Add comments here...'''&lt;br /&gt;
&lt;br /&gt;
== SVD solution ==&lt;br /&gt;
&lt;br /&gt;
==== Using ''i.pca'' ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 i.pca input=b2,b6,b7 output=pca.b267&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Eigen values, (vectors), and [percent importance]:&lt;br /&gt;
 PC1  '''6307563.04''' ( &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.64, -0.65, -0.42&amp;lt;/span&amp;gt; ) [ 98.71% ]&lt;br /&gt;
 PC2    78023.63 ( -0.71,  0.28,  0.64 ) [  1.22% ]&lt;br /&gt;
 PC3     4504.60 ( -0.30,  0.71, -0.64 ) [  0.07% ] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Using R's ''prcomp()'' function ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following example replicates ''i.pca'''s solution, that is, using the same data without data centering and/or scaling (options ''center=FALSE'' and ''scale=FALSE'').&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 prcomp(mod07, center=FALSE, scale=FALSE) &amp;lt;span style=&amp;quot;color:#006000&amp;quot;&amp;gt;&amp;lt;&amp;lt;== this corresponds to i.pca&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Standard deviations:&lt;br /&gt;
 [1] '''4288.3788'''  476.8904  114.3971&lt;br /&gt;
 Rotation:&lt;br /&gt;
                                    PC1        PC2        PC3&lt;br /&gt;
 MOD2007_242_500_sur_refl_b02 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.6353238&amp;lt;/span&amp;gt;  0.7124070 -0.2980602&lt;br /&gt;
 MOD2007_242_500_sur_refl_b06 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.6485551&amp;lt;/span&amp;gt; -0.2826985  0.7067234&lt;br /&gt;
 MOD2007_242_500_sur_refl_b07 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.4192135&amp;lt;/span&amp;gt; -0.6423066 -0.6416403&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Comments]]&lt;br /&gt;
&lt;br /&gt;
* The eigenvector matrices match although ''prcomp()'' reports loadings (=eigenvectors) column-wise and ''i.pca'' row-wise.&lt;br /&gt;
* The eigenvalues do '''not''' match. To exemplify, the standard deviation for PC1 reported by ''prcomp()'' is '''4288.3788''' and the variance reported by ''i.pca'' is 6307563.04 [ sqrt(6307563.04) = '''2511.486''' ]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''More examples to be added'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
Jon Shlens, &amp;quot;Tutorial on Principal Component Analysis, Dec 2005,&amp;quot; [http://www.snl.salk.edu/~shlens/pub/notes/pca.pdf] (accessed on March, 2009).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== e-mails in GRASS-user mailing list ==&lt;br /&gt;
&lt;br /&gt;
There are many posts concerning the functionality of ''i.pca''. Most of them are questioning the non-reporting of eigenvalues (an issue recently fixed).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Old posts'''&lt;br /&gt;
&lt;br /&gt;
[http://n2.nabble.com/i.pca-output-td1863271.html#a1863271]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Recent posts'''&lt;br /&gt;
&lt;br /&gt;
[http://n2.nabble.com/Testing-i.pca-~-prcomp()%2C-m.eigensystem-~-princomp()-td2413700.html#a2415727 Testing i.pca ~ prcomp(), m.eigensystem ~ princomp()]&lt;br /&gt;
&lt;br /&gt;
[http://n2.nabble.com/Calculating-eigen-values-and---variance-explained-after-PCA-analysis-td2383005.html#a2383165]&lt;br /&gt;
&lt;br /&gt;
[http://n2.nabble.com/Re%3A-Calculating-eigen-valuesand-varianceexplainedafter-PCA-analysis-td2413881.html#a2413881]&lt;br /&gt;
&lt;br /&gt;
[http://n2.nabble.com/Re%3A-Calculating-eigen-values-and--varianceexplainedafter-PCA-analysis-td2395558.html#a2409630]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''More sources to be added'''&lt;br /&gt;
&lt;br /&gt;
[[Category: Documentation]]&lt;/div&gt;</summary>
		<author><name>⚠️EdzerPebesma</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=Principal_Components_Analysis&amp;diff=8575</id>
		<title>Principal Components Analysis</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=Principal_Components_Analysis&amp;diff=8575"/>
		<updated>2009-03-31T14:21:04Z</updated>

		<summary type="html">&lt;p&gt;⚠️EdzerPebesma: /* Issues concerning R's princomp() function */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Under Construction'''&lt;br /&gt;
&lt;br /&gt;
This page is a short and practical introduction in Principal Component Analysis. It aims to highlight the importance of the values returned by PCA. In addition, it addresses numerical accuracy issues with respect to the default implementation of PCA in GRASS through the ''i.pca'' module.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Principal Component Analysis =&lt;br /&gt;
&lt;br /&gt;
Principal Component Analysis (PCA) is a dimensionality reduction technique used extensively in Remote Sensing studies (e.g. in change detection studies, image enhancement tasks and more). PCA is in fact a linear transformation applied on (usually) highly correlated multidimensional (e.g. multispectral) data. The input dimensions are transformed in a new coordinate system in which the produced dimensions (called principal components) contain, in decreasing order, the greatest variance related with unchanged landscape features.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PCA has two algebraic solutions:&lt;br /&gt;
&lt;br /&gt;
* '''Eigenvectors of Covariance''' (or Correlation)&lt;br /&gt;
* '''Singular Value Decomposition'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The '''SVD''' method is used for numerical accuracy [R Documentation]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
The basic steps of the transformation are:&lt;br /&gt;
&lt;br /&gt;
# '''organizing a dataset in a matrix'''&lt;br /&gt;
# '''data centering''' (that is: subtracting the dimensions means from themself so each of the dimensions in the dataset has zero mean)&lt;br /&gt;
# calculate&lt;br /&gt;
#* the '''covariance matrix''' ('''non-standardised PCA''') or&lt;br /&gt;
#* the '''correlation matrix''' ('''standardised PCA''', also known as scaling)&lt;br /&gt;
# calculate either&lt;br /&gt;
#* the '''eigenvectors''' and '''eigenvalues''' of the covariance (or the correlation) matrix or&lt;br /&gt;
#* the '''SVD''' of the data matrix&lt;br /&gt;
# '''sort variances in decreasing order''' (decreasing eigenvalues; this is default in eigenvalue analysis)&lt;br /&gt;
# '''project original dataset ''signals''''' (PC's or PC scores: eigenvector * input-data) to get&lt;br /&gt;
&lt;br /&gt;
== Solutions to PCA ==&lt;br /&gt;
&lt;br /&gt;
The '''Eigenvector''' solution to PCA involves:&lt;br /&gt;
&lt;br /&gt;
# calculation of&lt;br /&gt;
#* the covariance matrix of the given multidimensional dataset (non-standardised PCA) '''''or'''''&lt;br /&gt;
#* the correlation matrix of the given multidimensional dataset (standardised PCA)&lt;br /&gt;
# calculation of the eigenvalues and eigenvectors of the covariance (or correlation) matrix&lt;br /&gt;
# transformation of the input dataset using the eigenvalues as weighting coefficients&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
&lt;br /&gt;
'''eigenvalues''' represent either the variance of the original data contained in each principal component (in case they were computed from the covariance matrix), or the amount of correlation captured by the respective principle components (in case they were computed from the correlation matrix).&lt;br /&gt;
&lt;br /&gt;
'''eigenvectors''' act as weighting coefficients / represent the contribution of each original dimension the principal components / tell how the principle components relate to the the data variables (dimensions). Suppose an eigenvector is (0, 0, 1, 0), this indicates that the corresponding principle component is equal to dimension 3 and perpendicular to dimensions 1, 3 and 4. If it is (0.7, 0.7, 0, 0) the PC is equally determined by dimension 1 and 2 (it averages them), and not determined by dimensions 3 and 4. If it is (0.7, 0, -0.7, 0) it is the difference between dimension 1 and 3. Eigenvectors are normalized, meaning that the sum of its squared elements equals 1. &lt;br /&gt;
&lt;br /&gt;
'''loadings''' The individual numbers in an eigenvector are called loadings.&lt;br /&gt;
&lt;br /&gt;
'''scores''' When the original data are projected onto the eigenvectors, the resulting new variables are called the principle components; the new data values are called PC scores.&lt;br /&gt;
&lt;br /&gt;
== Performing PCA with GRASS ==&lt;br /&gt;
&lt;br /&gt;
* '''''m.eigensystem'''''&lt;br /&gt;
&lt;br /&gt;
The ''m.eigensystem'' module implements the eigenvector solution to PCA. The respective function in R is ''princomp()''. A comparison of their results confirms their almost identical performance. Specifically,&lt;br /&gt;
&lt;br /&gt;
# the standard deviations (sdev) reported by ''princomp()'' are (almost) identical with the variances (eigenvalues) reported by ''m.eigensystem''.&lt;br /&gt;
&lt;br /&gt;
# ''princomp()'' scales (also referred as normalization) the eigenvectors and so does ''m.eigensystem''. The scaled(=normalised) eigenvectors produced by m.eigensystem are marked with the capital letter N.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''''i.pca'''''&lt;br /&gt;
&lt;br /&gt;
The ''i.pca'' module performs PCA based on the SVD solution without data centering and/or scaling. A comparison of the results derived by ''i.pca'' and R's ''prcomp()'' function confirms this. Specifically, ''i.pca'' yields the same eigenvectors as R's ''prcomp()'' function does with the following options:&lt;br /&gt;
&lt;br /&gt;
 prcomp(x, center=FALSE, scale=FALSE)&lt;br /&gt;
&lt;br /&gt;
where x is a numeric or complex matrix (or data frame) which provides the data for the principal components analysis (R Documentation).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Issues concerning the ''i.pca'' module ==&lt;br /&gt;
&lt;br /&gt;
??? To add... ???&lt;br /&gt;
&lt;br /&gt;
== Issues concerning R's ''princomp()'' function ==&lt;br /&gt;
&lt;br /&gt;
If one computes principle components with R, the loadings are printed by default such that loadings close to 0 (between -.1 and .1, this can be controlled) are left out. This can be overriden (see the help page of function loadings). The reason for this is that for large loading tables, the real information is in loadings not close to 0; reading large loading tables is much easier when only important loadings are printed.&lt;br /&gt;
&lt;br /&gt;
= Examples using SPOT imagery =&lt;br /&gt;
Get the SPOT imagery from the Spearfish dataset: [http://grass.osgeo.org/sampledata/imagery60_grassdata.tar.gz SPOT images from the Spearfish dataset]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Eigenvectors solution ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Based on the covariance matrix ===&lt;br /&gt;
&lt;br /&gt;
==== Using '''''m.eigensystem''''' ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command in one line&lt;br /&gt;
&lt;br /&gt;
 (echo 3; r.covar spot.ms.1,spot.ms.2,spot.ms.3) | m.eigensystem&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
 r.covar: complete ...&lt;br /&gt;
  100%&lt;br /&gt;
 E      1159.7452017844          .0000000000    88.38&lt;br /&gt;
 V          .6910021591          .0000000000&lt;br /&gt;
 V          .7205280412          .0000000000&lt;br /&gt;
 V          .4805108400          .0000000000&lt;br /&gt;
 N          .6236808478          .0000000000&lt;br /&gt;
 N          .6503301526          .0000000000&lt;br /&gt;
 N          .4336967751          .0000000000&lt;br /&gt;
 W        21.2394712045          .0000000000&lt;br /&gt;
 W        22.1470141296          .0000000000&lt;br /&gt;
 W        14.7695575384          .0000000000&lt;br /&gt;
 E         5.9705414972          .0000000000      .45&lt;br /&gt;
 V          .7119385973          .0000000000&lt;br /&gt;
 V         -.6358200627          .0000000000&lt;br /&gt;
 V         -.0703936743          .0000000000&lt;br /&gt;
 N          .7438340890          .0000000000&lt;br /&gt;
 N         -.6643053754          .0000000000&lt;br /&gt;
 N         -.0735473745          .0000000000&lt;br /&gt;
 W         1.8175356507          .0000000000&lt;br /&gt;
 W        -1.6232096923          .0000000000&lt;br /&gt;
 W         -.1797107407          .0000000000&lt;br /&gt;
 E       146.5031967184          .0000000000    11.16&lt;br /&gt;
 V          .2265837636          .0000000000&lt;br /&gt;
 V          .3474697082          .0000000000&lt;br /&gt;
 V         -.8468727535          .0000000000&lt;br /&gt;
 N          .2402770238          .0000000000&lt;br /&gt;
 N          .3684685345          .0000000000&lt;br /&gt;
 N         -.8980522763          .0000000000&lt;br /&gt;
 W         2.9082771721          .0000000000&lt;br /&gt;
 W         4.4598880523          .0000000000&lt;br /&gt;
 W       -10.8698904856          .0000000000&lt;br /&gt;
&lt;br /&gt;
==== Using R's '''''princomp()''''' function ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Launch R from within GRASS&lt;br /&gt;
 R&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Load spgrass6() and projection information in R&lt;br /&gt;
 library(spgrass6)&lt;br /&gt;
 G &amp;lt;- gmeta6()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Read spot.ms bands&lt;br /&gt;
 spot.ms &amp;lt;- readRAST6(c('spot.ms.1', 'spot.ms.2', 'spot.ms.3'))&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Work around NA's&lt;br /&gt;
 spot.ms.nas &amp;lt;- which(is.na(spot.ms@data$spot.ms.1) &amp;amp; is.na(spot.ms@data$spot.ms.2) &amp;amp; is.na(spot.ms@data$spot.ms.3))&lt;br /&gt;
 spot.ms.values &amp;lt;- which(!is.na(spot.ms@data$spot.ms.1) &amp;amp; !is.na(spot.ms@data$spot.ms.2) &amp;amp; !is.na(spot.ms@data$spot.ms.3))&lt;br /&gt;
 spot.ms.nonas &amp;lt;- spot.ms.values@data[spot.ms.values, ]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 princomp(spot.ms.nonas)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Call:&lt;br /&gt;
 princomp(x = modis)&lt;br /&gt;
 Standard deviations:&lt;br /&gt;
   Comp.1   Comp.2   Comp.3&lt;br /&gt;
 34.055018 12.103846  2.443468&lt;br /&gt;
 &lt;br /&gt;
 3  variables and  1231860 observations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Get loadings&lt;br /&gt;
&lt;br /&gt;
 princomp(spot.ms.nonas)$loadings&lt;br /&gt;
 Loadings:&lt;br /&gt;
     Comp.1 Comp.2 Comp.3&lt;br /&gt;
 spot.ms.1 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.624'''&amp;lt;/span&amp;gt;  0.240  0.744&lt;br /&gt;
 spot.ms.2 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.650'''&amp;lt;/span&amp;gt; -0.368 -0.664&lt;br /&gt;
 spot.ms.3 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.434'''&amp;lt;/span&amp;gt;  0.898 &lt;br /&gt;
 &lt;br /&gt;
                Comp.1 Comp.2 Comp.3&lt;br /&gt;
 SS loadings     1.000  1.000  1.000&lt;br /&gt;
 Proportion Var  0.333  0.333  0.333&lt;br /&gt;
 Cumulative Var  0.333  0.667  1.000&lt;br /&gt;
&lt;br /&gt;
The '''bold''' and &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;red&amp;lt;/span&amp;gt; colored loadings, that is, the eigen vectors of the first principal component, ease of the comparison with the results derived from GRASS' ''m.eigensystem'' module above. Note the missing eigen value in row 3, column 3. For some reason R refused to yield it.&lt;br /&gt;
&lt;br /&gt;
=== Based on the correlation matrix ===&lt;br /&gt;
&lt;br /&gt;
==== Using '''''m.eigensystem'''''====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command in one line&lt;br /&gt;
&lt;br /&gt;
 (echo 3; r.covar -r spot.ms.1,spot.ms.2,spot.ms.3) | m.eigensystem&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 r.covar: complete ...&lt;br /&gt;
  100%&lt;br /&gt;
 E         2.5897901435          .0000000000    86.33&lt;br /&gt;
 V         -.7080795162          .0000000000&lt;br /&gt;
 V         -.6979341819          .0000000000&lt;br /&gt;
 V         -.6128387525          .0000000000&lt;br /&gt;
 N         -.6062688915          .0000000000&lt;br /&gt;
 N         -.5975822957          .0000000000&lt;br /&gt;
 N         -.5247222419          .0000000000&lt;br /&gt;
 W         -.9756579133          .0000000000&lt;br /&gt;
 W         -.9616787268          .0000000000&lt;br /&gt;
 W         -.8444263177          .0000000000&lt;br /&gt;
 E          .0123265666          .0000000000      .41&lt;br /&gt;
 V         -.6690685456          .0000000000&lt;br /&gt;
 V          .6302711261          .0000000000&lt;br /&gt;
 V          .0552608155          .0000000000&lt;br /&gt;
 N         -.7265842171          .0000000000&lt;br /&gt;
 N          .6844516242          .0000000000&lt;br /&gt;
 N          .0600112449          .0000000000&lt;br /&gt;
 W         -.0806690651          .0000000000&lt;br /&gt;
 W          .0759912909          .0000000000&lt;br /&gt;
 W          .0066627528          .0000000000&lt;br /&gt;
 E          .3978832898          .0000000000    13.26&lt;br /&gt;
 V          .3005969725          .0000000000&lt;br /&gt;
 V          .3883277727          .0000000000&lt;br /&gt;
 V         -.7895613377          .0000000000&lt;br /&gt;
 N          .3232853332          .0000000000&lt;br /&gt;
 N          .4176378502          .0000000000&lt;br /&gt;
 N         -.8491555920          .0000000000&lt;br /&gt;
 W          .2039218921          .0000000000&lt;br /&gt;
 W          .2634375639          .0000000000&lt;br /&gt;
 W         -.5356302845          .0000000000&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Using R's '''''princomp()''''' function ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Perform PCA&lt;br /&gt;
&lt;br /&gt;
 princomp(spot.ms.nonas, cor=TRUE)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Call:&lt;br /&gt;
 princomp(x = spot.ms.nonas, cor = TRUE)&lt;br /&gt;
 &lt;br /&gt;
 Standard deviations:&lt;br /&gt;
    Comp.1    Comp.2    Comp.3 &lt;br /&gt;
 1.6092826 0.6307795 0.1110256&lt;br /&gt;
 &lt;br /&gt;
 3  variables and  1231860 observations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Get loadings &lt;br /&gt;
&lt;br /&gt;
 princomp(spot.ms.nonas, cor=TRUE)$loadings&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Loadings:&lt;br /&gt;
           Comp.1 Comp.2 Comp.3&lt;br /&gt;
 spot.ms.1 -0.606 -0.323  0.727&lt;br /&gt;
 spot.ms.2 -0.598 -0.418 -0.684&lt;br /&gt;
 spot.ms.3 -0.525  0.849       &lt;br /&gt;
 &lt;br /&gt;
                Comp.1 Comp.2 Comp.3&lt;br /&gt;
 SS loadings     1.000  1.000  1.000&lt;br /&gt;
 Proportion Var  0.333  0.333  0.333&lt;br /&gt;
 Cumulative Var  0.333  0.667  1.000&lt;br /&gt;
&lt;br /&gt;
== SVD solution ==&lt;br /&gt;
&lt;br /&gt;
==== Using ''i.pca'' ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 i.pca input=spot.ms.1,spot.ms.2,spot.ms.3 out=pca.spot.ms rescale=0,0&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
  Eigen values, (vectors), and [percent importance]:&lt;br /&gt;
   PC1   '''1170.12''' (&amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.6251,-0.6536,-0.4268&amp;lt;/span&amp;gt;)[88.07%]&lt;br /&gt;
   PC2    152.49 ( 0.2328, 0.3658,-0.9011)[11.48%]&lt;br /&gt;
   PC3      6.01 ( 0.7450,-0.6626,-0.0765) [0.45%]&lt;br /&gt;
&lt;br /&gt;
==== Using R's ''prcomp()'' function ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following example replicates ''i.pca'''s solution using the same data '''with data centering and without scaling''' (options ''center=TRUE'' and ''scale=FALSE''). Note that these settings are the defaults.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 prcomp(spot.ms.nonas)&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Standard deviations:&lt;br /&gt;
 [1] 34.055032 12.103851  2.443469&lt;br /&gt;
 &lt;br /&gt;
 Rotation:&lt;br /&gt;
                  PC1        PC2         PC3&lt;br /&gt;
 spot.ms.1 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.6236808&amp;lt;/span&amp;gt;  0.2402770 -0.74383409&lt;br /&gt;
 spot.ms.2 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.6503302&amp;lt;/span&amp;gt;  0.3684685  0.66430538&lt;br /&gt;
 spot.ms.3 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.4336968&amp;lt;/span&amp;gt; -0.8980523  0.07354738&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Comments]]&lt;br /&gt;
&lt;br /&gt;
In this example ''i.pca'''s performance seems to be identical to R's ''prcomp()'' function which means that data centering is applied prior to the actual PCA.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The three SPOT bands used in this example have the following ranges:&lt;br /&gt;
&lt;br /&gt;
*spot.ms.1&lt;br /&gt;
&lt;br /&gt;
 min=24&lt;br /&gt;
 max=254&lt;br /&gt;
&lt;br /&gt;
*spot.ms.2&lt;br /&gt;
&lt;br /&gt;
 min=14&lt;br /&gt;
 max=254&lt;br /&gt;
*spot.ms.3&lt;br /&gt;
&lt;br /&gt;
 min=12&lt;br /&gt;
 max=254&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Nevertheless, as shown in the examples using MODIS surface reflectance products (read below) in which the range of the bands varies significantly, ''i.pca'''s results do not match the results of R's ''prcomp()'' function with the parameter ''center'' set to ''TRUE''. Instead, the results derived from ''i.pca'' are almost identical when the parameter ''center'' is set to ''FALSE''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following example performs PCA '''without data centering and scaling''' (options ''center=FALSE'' and ''scale=FALSE'').&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 prcomp(spot.ms.nonas, center=FALSE, scale=FALSE)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Standard deviations:&lt;br /&gt;
 [1] '''101.00927'''  15.79861   2.83775&lt;br /&gt;
 &lt;br /&gt;
 Rotation:&lt;br /&gt;
                  PC1        PC2        PC3&lt;br /&gt;
 spot.ms.1 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.5605487&amp;lt;/span&amp;gt; -0.3652694  0.7432116&lt;br /&gt;
 spot.ms.2 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.4726613&amp;lt;/span&amp;gt; -0.5958032 -0.6493149&lt;br /&gt;
 spot.ms.3 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.6799827&amp;lt;/span&amp;gt;  0.7152600 -0.1613280&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Comments]]&lt;br /&gt;
&lt;br /&gt;
+++&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following example performs PCA '''with data centering and scaling''' (options ''center=TRUE'' and ''scale=TRUE'')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 prcomp(spot.ms.nonas, center=TRUE, scale=TRUE)&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Standard deviations:&lt;br /&gt;
 [1] 1.6092826 0.6307795 0.1110256&lt;br /&gt;
 &lt;br /&gt;
 Rotation:&lt;br /&gt;
                  PC1        PC2         PC3&lt;br /&gt;
 spot.ms.1 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.6062688&amp;lt;/span&amp;gt;  0.3232856 -0.72658417&lt;br /&gt;
 spot.ms.2 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.5975823&amp;lt;/span&amp;gt;  0.4176378  0.68445170&lt;br /&gt;
 spot.ms.3 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.5247224&amp;lt;/span&amp;gt; -0.8491555  0.06001103&lt;br /&gt;
&lt;br /&gt;
= Examples using MODIS surface reflectance products =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Eigenvectors solution ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Based on the covariance matrix ===&lt;br /&gt;
&lt;br /&gt;
==== Using '''''m.eigensystem''''' ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command in one line&lt;br /&gt;
&lt;br /&gt;
 (echo 3; r.covar b02,b06,b07) | m.eigensystem&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E&amp;lt;/span&amp;gt; line is the eigen value. (Real part, imaginary part, percent importance)&lt;br /&gt;
* The &amp;lt;tt&amp;gt;V&amp;lt;/tt&amp;gt; lines are the eigen vectors associated with &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E&amp;lt;/span&amp;gt;.&lt;br /&gt;
* The &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N&amp;lt;/span&amp;gt; lines are the &amp;lt;tt&amp;gt;V&amp;lt;/tt&amp;gt; vectors normalized to have a magnitude of 1. '''These are the scaled eigen vectors that correspond to princomp()'s results presented in the following section.'''&lt;br /&gt;
* The &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W&amp;lt;/span&amp;gt; lines are the &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N&amp;lt;/span&amp;gt; vector multiplied by the square root of the magnitude of the eigen value (&amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E&amp;lt;/span&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
 r.covar: complete ...&lt;br /&gt;
 100%&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E    778244.0258462029          .0000000000    79.20&amp;lt;/span&amp;gt;&lt;br /&gt;
 V          .5006581842          .0000000000&lt;br /&gt;
 V          .8256483300          .0000000000&lt;br /&gt;
 V          .6155834548          .0000000000&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N          '''.4372107421'''          .0000000000&lt;br /&gt;
 N          '''.7210155161'''          .0000000000&lt;br /&gt;
 N          '''.5375717557'''          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W       385.6991853500          .0000000000&lt;br /&gt;
 W       636.0664787886          .0000000000&lt;br /&gt;
 W       474.2358050886          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E    192494.5769628266          .0000000000    19.59&amp;lt;/span&amp;gt;&lt;br /&gt;
 V         -.8689798010          .0000000000&lt;br /&gt;
 V          .0996340298          .0000000000&lt;br /&gt;
 V          .5731134848          .0000000000&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N         -.8309940700          .0000000000&lt;br /&gt;
 N          .0952787255          .0000000000&lt;br /&gt;
 N          .5480609638          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W      -364.5920328433          .0000000000&lt;br /&gt;
 W        41.8027823088          .0000000000&lt;br /&gt;
 W       240.4573848757          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E     11876.4548199713          .0000000000     1.21&amp;lt;/span&amp;gt;&lt;br /&gt;
 V          .2872248982          .0000000000&lt;br /&gt;
 V         -.5731591248          .0000000000&lt;br /&gt;
 V          .5351449518          .0000000000&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N          .3439413070          .0000000000&lt;br /&gt;
 N         -.6863370819          .0000000000&lt;br /&gt;
 N          .6408165005          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W        37.4824307850          .0000000000&lt;br /&gt;
 W       -74.7964308085          .0000000000&lt;br /&gt;
 W        69.8356366100          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In general, the solution to the eigen system results in complex&lt;br /&gt;
numbers (with both real and imaginary parts).  However, in the example&lt;br /&gt;
above, since the input matrix is symmetric (i.e., inverting the rows and columns&lt;br /&gt;
gives the same matrix) the eigen system has only real values (i.e., the&lt;br /&gt;
imaginary part is zero).&lt;br /&gt;
This fact makes it possible to use eigen vectors to perform principle component&lt;br /&gt;
transformation of data sets.  The covariance or correlation&lt;br /&gt;
matrix of any data set is symmetric&lt;br /&gt;
and thus has only real eigen values and vectors.&lt;br /&gt;
&lt;br /&gt;
'''Note''' The '''bold''' and &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;red&amp;lt;/span&amp;gt; colored eigen vectors of the first principal component, ease of the comparison with the results derived from R's ''princomp()'' function that follows.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Using the &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W&amp;lt;/span&amp;gt; vector, new maps can be created:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;B&amp;gt;r.mapcalc&amp;lt;/B&amp;gt; 'pc.1 =  &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;385.6992&amp;lt;/span&amp;gt;*map.1 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;+636.0665&amp;lt;/span&amp;gt;*map.2 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;+ 474.2358&amp;lt;/span&amp;gt;*map.3'&lt;br /&gt;
 &amp;lt;B&amp;gt;r.mapcalc&amp;lt;/B&amp;gt; 'pc.2 = &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;-364.5920&amp;lt;/span&amp;gt;*map.1 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;+ 41.8027&amp;lt;/span&amp;gt;*map.2 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;+ 240.4573&amp;lt;/span&amp;gt;*map.3'&lt;br /&gt;
 &amp;lt;B&amp;gt;r.mapcalc&amp;lt;/B&amp;gt; 'pc.3 =   &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;37.4824&amp;lt;/span&amp;gt;*map.1 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;- 74.7964&amp;lt;/span&amp;gt;*map.2 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;+  69.8356&amp;lt;/span&amp;gt;*map.3'&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Using R's '''''princomp()''''' function ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 princomp(modis)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Call:&lt;br /&gt;
 princomp(x = modis)&lt;br /&gt;
 Standard deviations:&lt;br /&gt;
   Comp.1   Comp.2   Comp.3&lt;br /&gt;
 857.5737 436.0922 108.5083&lt;br /&gt;
 3  variables and  350596 observations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Get loadings&lt;br /&gt;
&lt;br /&gt;
 (princomp(modis))$loadings&lt;br /&gt;
 Loadings:&lt;br /&gt;
     Comp.1 Comp.2 Comp.3&lt;br /&gt;
 b02 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.418'''&amp;lt;/span&amp;gt;  0.839  0.348&lt;br /&gt;
 b06 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.725'''&amp;lt;/span&amp;gt;        -0.684&lt;br /&gt;
 b07 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.547'''&amp;lt;/span&amp;gt; -0.539  0.641&lt;br /&gt;
&lt;br /&gt;
                Comp.1 Comp.2 Comp.3&lt;br /&gt;
 SS loadings     1.000  1.000  1.000&lt;br /&gt;
 Proportion Var  0.333  0.333  0.333&lt;br /&gt;
 Cumulative Var  0.333  0.667  1.000&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The '''bold''' and &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;red&amp;lt;/span&amp;gt; colored loadings, that is, the eigen vectors of the first principal component, ease of the comparison with the results derived from GRASS' ''m.eigensystem'' module above. Note the missing eigen value in row 2, column 2. For some reason R refused to yield it.&lt;br /&gt;
&lt;br /&gt;
=== Based on the correlation matrix ===&lt;br /&gt;
&lt;br /&gt;
==== Using '''''m.eigensystem'''''====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command in one line&lt;br /&gt;
&lt;br /&gt;
 (echo 3; r.covar -r MOD07_b02,MOD07_b06,MOD07_b07)|m.eigensystem&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 r.covar: complete ...&lt;br /&gt;
  100%&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E         2.2915877718          .0000000000    76.39&amp;lt;/span&amp;gt;&lt;br /&gt;
 V         -.5755655569          .0000000000&lt;br /&gt;
 V         -.7660355041          .0000000000&lt;br /&gt;
 V         -.6809380186          .0000000000&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N         -.4896413269          .0000000000&lt;br /&gt;
 N         -.6516766616          .0000000000&lt;br /&gt;
 N         -.5792830912          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W         -.7412186091          .0000000000&lt;br /&gt;
 W         -.9865075560          .0000000000&lt;br /&gt;
 W         -.8769182329          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E          .6740687010          .0000000000    22.47&amp;lt;/span&amp;gt;&lt;br /&gt;
 V          .8667178982          .0000000000&lt;br /&gt;
 V         -.1116525720          .0000000000&lt;br /&gt;
 V         -.6069908335          .0000000000&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N          '''.8145815825'''          .0000000000&lt;br /&gt;
 N         '''-.1049362531'''          .0000000000&lt;br /&gt;
 N         '''-.5704780699'''          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W          .6687852213          .0000000000&lt;br /&gt;
 W         -.0861544341          .0000000000&lt;br /&gt;
 W         -.4683721194          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E          .0343435272          .0000000000     1.14&amp;lt;/span&amp;gt;&lt;br /&gt;
 V          .2486404469          .0000000000&lt;br /&gt;
 V         -.6006166822          .0000000000&lt;br /&gt;
 V          .4655120098          .0000000000&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N          .3109794470          .0000000000&lt;br /&gt;
 N         -.7512029762          .0000000000&lt;br /&gt;
 N          .5822249325          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W          .0576307320          .0000000000&lt;br /&gt;
 W         -.1392129859          .0000000000&lt;br /&gt;
 W          .1078979635          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The '''bold''' and &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;red&amp;lt;/span&amp;gt; colored eigen vectors of the second principal component, ease of the comparison with the results derived from R's ''princomp()'' function that follows.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Using R's '''''princomp()''''' function ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 princomp(mod07, cor=TRUE)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Call:&lt;br /&gt;
 princomp(x = mod07, cor = TRUE)&lt;br /&gt;
&lt;br /&gt;
 Standard deviations:&lt;br /&gt;
    Comp.1    Comp.2    Comp.3&lt;br /&gt;
 1.5030740 0.8397807 0.1885121&lt;br /&gt;
 &lt;br /&gt;
  3  variables and  350596 observations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Get loadings&lt;br /&gt;
&lt;br /&gt;
 (princomp(mod07, cor=TRUE))$loadings&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Loadings:&lt;br /&gt;
                              Comp.1 Comp.2 Comp.3&lt;br /&gt;
 MOD2007_242_500_sur_refl_b02 -0.481  &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''0.820'''&amp;lt;/span&amp;gt;  0.310&lt;br /&gt;
 MOD2007_242_500_sur_refl_b06 -0.656 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.102'''&amp;lt;/span&amp;gt; -0.748&lt;br /&gt;
 MOD2007_242_500_sur_refl_b07 -0.582 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.563'''&amp;lt;/span&amp;gt;  0.587&lt;br /&gt;
 &lt;br /&gt;
                Comp.1 Comp.2 Comp.3&lt;br /&gt;
 SS loadings     1.000  1.000  1.000&lt;br /&gt;
 Proportion Var  0.333  0.333  0.333&lt;br /&gt;
 Cumulative Var  0.333  0.667  1.000&lt;br /&gt;
&lt;br /&gt;
The '''bold''' and &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;red&amp;lt;/span&amp;gt; colored loadings, that is, the eigen vectors of the second component, ease of the comparison with the results derived from GRASS' ''m.eigensystem'' module above.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Comments]]&lt;br /&gt;
'''Add comments here...'''&lt;br /&gt;
&lt;br /&gt;
== SVD solution ==&lt;br /&gt;
&lt;br /&gt;
==== Using ''i.pca'' ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 i.pca input=b2,b6,b7 output=pca.b267&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Eigen values, (vectors), and [percent importance]:&lt;br /&gt;
 PC1  '''6307563.04''' ( &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.64, -0.65, -0.42&amp;lt;/span&amp;gt; ) [ 98.71% ]&lt;br /&gt;
 PC2    78023.63 ( -0.71,  0.28,  0.64 ) [  1.22% ]&lt;br /&gt;
 PC3     4504.60 ( -0.30,  0.71, -0.64 ) [  0.07% ] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Using R's ''prcomp()'' function ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following example replicates ''i.pca'''s solution, that is, using the same data without data centering and/or scaling (options ''center=FALSE'' and ''scale=FALSE'').&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 prcomp(mod07, center=FALSE, scale=FALSE) &amp;lt;span style=&amp;quot;color:#006000&amp;quot;&amp;gt;&amp;lt;&amp;lt;== this corresponds to i.pca&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Standard deviations:&lt;br /&gt;
 [1] '''4288.3788'''  476.8904  114.3971&lt;br /&gt;
 Rotation:&lt;br /&gt;
                                    PC1        PC2        PC3&lt;br /&gt;
 MOD2007_242_500_sur_refl_b02 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.6353238&amp;lt;/span&amp;gt;  0.7124070 -0.2980602&lt;br /&gt;
 MOD2007_242_500_sur_refl_b06 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.6485551&amp;lt;/span&amp;gt; -0.2826985  0.7067234&lt;br /&gt;
 MOD2007_242_500_sur_refl_b07 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.4192135&amp;lt;/span&amp;gt; -0.6423066 -0.6416403&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Comments]]&lt;br /&gt;
&lt;br /&gt;
* The eigenvector matrices match although ''prcomp()'' reports loadings (=eigenvectors) column-wise and ''i.pca'' row-wise.&lt;br /&gt;
* The eigenvalues do '''not''' match. To exemplify, the standard deviation for PC1 reported by ''prcomp()'' is '''4288.3788''' and the variance reported by ''i.pca'' is 6307563.04 [ sqrt(6307563.04) = '''2511.486''' ]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''More examples to be added'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
Jon Shlens, &amp;quot;Tutorial on Principal Component Analysis, Dec 2005,&amp;quot; [http://www.snl.salk.edu/~shlens/pub/notes/pca.pdf] (accessed on March, 2009).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== e-mails in GRASS-user mailing list ==&lt;br /&gt;
&lt;br /&gt;
There are many posts concerning the functionality of ''i.pca''. Most of them are questioning the non-reporting of eigenvalues (an issue recently fixed).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Old posts'''&lt;br /&gt;
&lt;br /&gt;
[http://n2.nabble.com/i.pca-output-td1863271.html#a1863271]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Recent posts'''&lt;br /&gt;
&lt;br /&gt;
[http://n2.nabble.com/Testing-i.pca-~-prcomp()%2C-m.eigensystem-~-princomp()-td2413700.html#a2415727 Testing i.pca ~ prcomp(), m.eigensystem ~ princomp()]&lt;br /&gt;
&lt;br /&gt;
[http://n2.nabble.com/Calculating-eigen-values-and---variance-explained-after-PCA-analysis-td2383005.html#a2383165]&lt;br /&gt;
&lt;br /&gt;
[http://n2.nabble.com/Re%3A-Calculating-eigen-valuesand-varianceexplainedafter-PCA-analysis-td2413881.html#a2413881]&lt;br /&gt;
&lt;br /&gt;
[http://n2.nabble.com/Re%3A-Calculating-eigen-values-and--varianceexplainedafter-PCA-analysis-td2395558.html#a2409630]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''More sources to be added'''&lt;br /&gt;
&lt;br /&gt;
[[Category: Documentation]]&lt;/div&gt;</summary>
		<author><name>⚠️EdzerPebesma</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=Principal_Components_Analysis&amp;diff=8574</id>
		<title>Principal Components Analysis</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=Principal_Components_Analysis&amp;diff=8574"/>
		<updated>2009-03-31T14:15:03Z</updated>

		<summary type="html">&lt;p&gt;⚠️EdzerPebesma: /* Terminology */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Under Construction'''&lt;br /&gt;
&lt;br /&gt;
This page is a short and practical introduction in Principal Component Analysis. It aims to highlight the importance of the values returned by PCA. In addition, it addresses numerical accuracy issues with respect to the default implementation of PCA in GRASS through the ''i.pca'' module.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Principal Component Analysis =&lt;br /&gt;
&lt;br /&gt;
Principal Component Analysis (PCA) is a dimensionality reduction technique used extensively in Remote Sensing studies (e.g. in change detection studies, image enhancement tasks and more). PCA is in fact a linear transformation applied on (usually) highly correlated multidimensional (e.g. multispectral) data. The input dimensions are transformed in a new coordinate system in which the produced dimensions (called principal components) contain, in decreasing order, the greatest variance related with unchanged landscape features.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PCA has two algebraic solutions:&lt;br /&gt;
&lt;br /&gt;
* '''Eigenvectors of Covariance''' (or Correlation)&lt;br /&gt;
* '''Singular Value Decomposition'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The '''SVD''' method is used for numerical accuracy [R Documentation]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
The basic steps of the transformation are:&lt;br /&gt;
&lt;br /&gt;
# '''organizing a dataset in a matrix'''&lt;br /&gt;
# '''data centering''' (that is: subtracting the dimensions means from themself so each of the dimensions in the dataset has zero mean)&lt;br /&gt;
# calculate&lt;br /&gt;
#* the '''covariance matrix''' ('''non-standardised PCA''') or&lt;br /&gt;
#* the '''correlation matrix''' ('''standardised PCA''', also known as scaling)&lt;br /&gt;
# calculate either&lt;br /&gt;
#* the '''eigenvectors''' and '''eigenvalues''' of the covariance (or the correlation) matrix or&lt;br /&gt;
#* the '''SVD''' of the data matrix&lt;br /&gt;
# '''sort variances in decreasing order''' (decreasing eigenvalues; this is default in eigenvalue analysis)&lt;br /&gt;
# '''project original dataset ''signals''''' (PC's or PC scores: eigenvector * input-data) to get&lt;br /&gt;
&lt;br /&gt;
== Solutions to PCA ==&lt;br /&gt;
&lt;br /&gt;
The '''Eigenvector''' solution to PCA involves:&lt;br /&gt;
&lt;br /&gt;
# calculation of&lt;br /&gt;
#* the covariance matrix of the given multidimensional dataset (non-standardised PCA) '''''or'''''&lt;br /&gt;
#* the correlation matrix of the given multidimensional dataset (standardised PCA)&lt;br /&gt;
# calculation of the eigenvalues and eigenvectors of the covariance (or correlation) matrix&lt;br /&gt;
# transformation of the input dataset using the eigenvalues as weighting coefficients&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
&lt;br /&gt;
'''eigenvalues''' represent either the variance of the original data contained in each principal component (in case they were computed from the covariance matrix), or the amount of correlation captured by the respective principle components (in case they were computed from the correlation matrix).&lt;br /&gt;
&lt;br /&gt;
'''eigenvectors''' act as weighting coefficients / represent the contribution of each original dimension the principal components / tell how the principle components relate to the the data variables (dimensions). Suppose an eigenvector is (0, 0, 1, 0), this indicates that the corresponding principle component is equal to dimension 3 and perpendicular to dimensions 1, 3 and 4. If it is (0.7, 0.7, 0, 0) the PC is equally determined by dimension 1 and 2 (it averages them), and not determined by dimensions 3 and 4. If it is (0.7, 0, -0.7, 0) it is the difference between dimension 1 and 3. Eigenvectors are normalized, meaning that the sum of its squared elements equals 1. &lt;br /&gt;
&lt;br /&gt;
'''loadings''' The individual numbers in an eigenvector are called loadings.&lt;br /&gt;
&lt;br /&gt;
'''scores''' When the original data are projected onto the eigenvectors, the resulting new variables are called the principle components; the new data values are called PC scores.&lt;br /&gt;
&lt;br /&gt;
== Performing PCA with GRASS ==&lt;br /&gt;
&lt;br /&gt;
* '''''m.eigensystem'''''&lt;br /&gt;
&lt;br /&gt;
The ''m.eigensystem'' module implements the eigenvector solution to PCA. The respective function in R is ''princomp()''. A comparison of their results confirms their almost identical performance. Specifically,&lt;br /&gt;
&lt;br /&gt;
# the standard deviations (sdev) reported by ''princomp()'' are (almost) identical with the variances (eigenvalues) reported by ''m.eigensystem''.&lt;br /&gt;
&lt;br /&gt;
# ''princomp()'' scales (also referred as normalization) the eigenvectors and so does ''m.eigensystem''. The scaled(=normalised) eigenvectors produced by m.eigensystem are marked with the capital letter N.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''''i.pca'''''&lt;br /&gt;
&lt;br /&gt;
The ''i.pca'' module performs PCA based on the SVD solution without data centering and/or scaling. A comparison of the results derived by ''i.pca'' and R's ''prcomp()'' function confirms this. Specifically, ''i.pca'' yields the same eigenvectors as R's ''prcomp()'' function does with the following options:&lt;br /&gt;
&lt;br /&gt;
 prcomp(x, center=FALSE, scale=FALSE)&lt;br /&gt;
&lt;br /&gt;
where x is a numeric or complex matrix (or data frame) which provides the data for the principal components analysis (R Documentation).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Issues concerning the ''i.pca'' module ==&lt;br /&gt;
&lt;br /&gt;
??? To add... ???&lt;br /&gt;
&lt;br /&gt;
== Issues concerning R's ''princomp()'' function ==&lt;br /&gt;
&lt;br /&gt;
* For some reason one loading (=eigenvector) is missing from the output of the default application of princomp() on objects derived from GRASS as described above.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Examples using SPOT imagery =&lt;br /&gt;
Get the SPOT imagery from the Spearfish dataset: [http://grass.osgeo.org/sampledata/imagery60_grassdata.tar.gz SPOT images from the Spearfish dataset]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Eigenvectors solution ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Based on the covariance matrix ===&lt;br /&gt;
&lt;br /&gt;
==== Using '''''m.eigensystem''''' ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command in one line&lt;br /&gt;
&lt;br /&gt;
 (echo 3; r.covar spot.ms.1,spot.ms.2,spot.ms.3) | m.eigensystem&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
 r.covar: complete ...&lt;br /&gt;
  100%&lt;br /&gt;
 E      1159.7452017844          .0000000000    88.38&lt;br /&gt;
 V          .6910021591          .0000000000&lt;br /&gt;
 V          .7205280412          .0000000000&lt;br /&gt;
 V          .4805108400          .0000000000&lt;br /&gt;
 N          .6236808478          .0000000000&lt;br /&gt;
 N          .6503301526          .0000000000&lt;br /&gt;
 N          .4336967751          .0000000000&lt;br /&gt;
 W        21.2394712045          .0000000000&lt;br /&gt;
 W        22.1470141296          .0000000000&lt;br /&gt;
 W        14.7695575384          .0000000000&lt;br /&gt;
 E         5.9705414972          .0000000000      .45&lt;br /&gt;
 V          .7119385973          .0000000000&lt;br /&gt;
 V         -.6358200627          .0000000000&lt;br /&gt;
 V         -.0703936743          .0000000000&lt;br /&gt;
 N          .7438340890          .0000000000&lt;br /&gt;
 N         -.6643053754          .0000000000&lt;br /&gt;
 N         -.0735473745          .0000000000&lt;br /&gt;
 W         1.8175356507          .0000000000&lt;br /&gt;
 W        -1.6232096923          .0000000000&lt;br /&gt;
 W         -.1797107407          .0000000000&lt;br /&gt;
 E       146.5031967184          .0000000000    11.16&lt;br /&gt;
 V          .2265837636          .0000000000&lt;br /&gt;
 V          .3474697082          .0000000000&lt;br /&gt;
 V         -.8468727535          .0000000000&lt;br /&gt;
 N          .2402770238          .0000000000&lt;br /&gt;
 N          .3684685345          .0000000000&lt;br /&gt;
 N         -.8980522763          .0000000000&lt;br /&gt;
 W         2.9082771721          .0000000000&lt;br /&gt;
 W         4.4598880523          .0000000000&lt;br /&gt;
 W       -10.8698904856          .0000000000&lt;br /&gt;
&lt;br /&gt;
==== Using R's '''''princomp()''''' function ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Launch R from within GRASS&lt;br /&gt;
 R&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Load spgrass6() and projection information in R&lt;br /&gt;
 library(spgrass6)&lt;br /&gt;
 G &amp;lt;- gmeta6()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Read spot.ms bands&lt;br /&gt;
 spot.ms &amp;lt;- readRAST6(c('spot.ms.1', 'spot.ms.2', 'spot.ms.3'))&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Work around NA's&lt;br /&gt;
 spot.ms.nas &amp;lt;- which(is.na(spot.ms@data$spot.ms.1) &amp;amp; is.na(spot.ms@data$spot.ms.2) &amp;amp; is.na(spot.ms@data$spot.ms.3))&lt;br /&gt;
 spot.ms.values &amp;lt;- which(!is.na(spot.ms@data$spot.ms.1) &amp;amp; !is.na(spot.ms@data$spot.ms.2) &amp;amp; !is.na(spot.ms@data$spot.ms.3))&lt;br /&gt;
 spot.ms.nonas &amp;lt;- spot.ms.values@data[spot.ms.values, ]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 princomp(spot.ms.nonas)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Call:&lt;br /&gt;
 princomp(x = modis)&lt;br /&gt;
 Standard deviations:&lt;br /&gt;
   Comp.1   Comp.2   Comp.3&lt;br /&gt;
 34.055018 12.103846  2.443468&lt;br /&gt;
 &lt;br /&gt;
 3  variables and  1231860 observations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Get loadings&lt;br /&gt;
&lt;br /&gt;
 princomp(spot.ms.nonas)$loadings&lt;br /&gt;
 Loadings:&lt;br /&gt;
     Comp.1 Comp.2 Comp.3&lt;br /&gt;
 spot.ms.1 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.624'''&amp;lt;/span&amp;gt;  0.240  0.744&lt;br /&gt;
 spot.ms.2 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.650'''&amp;lt;/span&amp;gt; -0.368 -0.664&lt;br /&gt;
 spot.ms.3 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.434'''&amp;lt;/span&amp;gt;  0.898 &lt;br /&gt;
 &lt;br /&gt;
                Comp.1 Comp.2 Comp.3&lt;br /&gt;
 SS loadings     1.000  1.000  1.000&lt;br /&gt;
 Proportion Var  0.333  0.333  0.333&lt;br /&gt;
 Cumulative Var  0.333  0.667  1.000&lt;br /&gt;
&lt;br /&gt;
The '''bold''' and &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;red&amp;lt;/span&amp;gt; colored loadings, that is, the eigen vectors of the first principal component, ease of the comparison with the results derived from GRASS' ''m.eigensystem'' module above. Note the missing eigen value in row 3, column 3. For some reason R refused to yield it.&lt;br /&gt;
&lt;br /&gt;
=== Based on the correlation matrix ===&lt;br /&gt;
&lt;br /&gt;
==== Using '''''m.eigensystem'''''====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command in one line&lt;br /&gt;
&lt;br /&gt;
 (echo 3; r.covar -r spot.ms.1,spot.ms.2,spot.ms.3) | m.eigensystem&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 r.covar: complete ...&lt;br /&gt;
  100%&lt;br /&gt;
 E         2.5897901435          .0000000000    86.33&lt;br /&gt;
 V         -.7080795162          .0000000000&lt;br /&gt;
 V         -.6979341819          .0000000000&lt;br /&gt;
 V         -.6128387525          .0000000000&lt;br /&gt;
 N         -.6062688915          .0000000000&lt;br /&gt;
 N         -.5975822957          .0000000000&lt;br /&gt;
 N         -.5247222419          .0000000000&lt;br /&gt;
 W         -.9756579133          .0000000000&lt;br /&gt;
 W         -.9616787268          .0000000000&lt;br /&gt;
 W         -.8444263177          .0000000000&lt;br /&gt;
 E          .0123265666          .0000000000      .41&lt;br /&gt;
 V         -.6690685456          .0000000000&lt;br /&gt;
 V          .6302711261          .0000000000&lt;br /&gt;
 V          .0552608155          .0000000000&lt;br /&gt;
 N         -.7265842171          .0000000000&lt;br /&gt;
 N          .6844516242          .0000000000&lt;br /&gt;
 N          .0600112449          .0000000000&lt;br /&gt;
 W         -.0806690651          .0000000000&lt;br /&gt;
 W          .0759912909          .0000000000&lt;br /&gt;
 W          .0066627528          .0000000000&lt;br /&gt;
 E          .3978832898          .0000000000    13.26&lt;br /&gt;
 V          .3005969725          .0000000000&lt;br /&gt;
 V          .3883277727          .0000000000&lt;br /&gt;
 V         -.7895613377          .0000000000&lt;br /&gt;
 N          .3232853332          .0000000000&lt;br /&gt;
 N          .4176378502          .0000000000&lt;br /&gt;
 N         -.8491555920          .0000000000&lt;br /&gt;
 W          .2039218921          .0000000000&lt;br /&gt;
 W          .2634375639          .0000000000&lt;br /&gt;
 W         -.5356302845          .0000000000&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Using R's '''''princomp()''''' function ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Perform PCA&lt;br /&gt;
&lt;br /&gt;
 princomp(spot.ms.nonas, cor=TRUE)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Call:&lt;br /&gt;
 princomp(x = spot.ms.nonas, cor = TRUE)&lt;br /&gt;
 &lt;br /&gt;
 Standard deviations:&lt;br /&gt;
    Comp.1    Comp.2    Comp.3 &lt;br /&gt;
 1.6092826 0.6307795 0.1110256&lt;br /&gt;
 &lt;br /&gt;
 3  variables and  1231860 observations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Get loadings &lt;br /&gt;
&lt;br /&gt;
 princomp(spot.ms.nonas, cor=TRUE)$loadings&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Loadings:&lt;br /&gt;
           Comp.1 Comp.2 Comp.3&lt;br /&gt;
 spot.ms.1 -0.606 -0.323  0.727&lt;br /&gt;
 spot.ms.2 -0.598 -0.418 -0.684&lt;br /&gt;
 spot.ms.3 -0.525  0.849       &lt;br /&gt;
 &lt;br /&gt;
                Comp.1 Comp.2 Comp.3&lt;br /&gt;
 SS loadings     1.000  1.000  1.000&lt;br /&gt;
 Proportion Var  0.333  0.333  0.333&lt;br /&gt;
 Cumulative Var  0.333  0.667  1.000&lt;br /&gt;
&lt;br /&gt;
== SVD solution ==&lt;br /&gt;
&lt;br /&gt;
==== Using ''i.pca'' ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 i.pca input=spot.ms.1,spot.ms.2,spot.ms.3 out=pca.spot.ms rescale=0,0&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
  Eigen values, (vectors), and [percent importance]:&lt;br /&gt;
   PC1   '''1170.12''' (&amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.6251,-0.6536,-0.4268&amp;lt;/span&amp;gt;)[88.07%]&lt;br /&gt;
   PC2    152.49 ( 0.2328, 0.3658,-0.9011)[11.48%]&lt;br /&gt;
   PC3      6.01 ( 0.7450,-0.6626,-0.0765) [0.45%]&lt;br /&gt;
&lt;br /&gt;
==== Using R's ''prcomp()'' function ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following example replicates ''i.pca'''s solution using the same data '''with data centering and without scaling''' (options ''center=TRUE'' and ''scale=FALSE''). Note that these settings are the defaults.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 prcomp(spot.ms.nonas)&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Standard deviations:&lt;br /&gt;
 [1] 34.055032 12.103851  2.443469&lt;br /&gt;
 &lt;br /&gt;
 Rotation:&lt;br /&gt;
                  PC1        PC2         PC3&lt;br /&gt;
 spot.ms.1 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.6236808&amp;lt;/span&amp;gt;  0.2402770 -0.74383409&lt;br /&gt;
 spot.ms.2 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.6503302&amp;lt;/span&amp;gt;  0.3684685  0.66430538&lt;br /&gt;
 spot.ms.3 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.4336968&amp;lt;/span&amp;gt; -0.8980523  0.07354738&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Comments]]&lt;br /&gt;
&lt;br /&gt;
In this example ''i.pca'''s performance seems to be identical to R's ''prcomp()'' function which means that data centering is applied prior to the actual PCA.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The three SPOT bands used in this example have the following ranges:&lt;br /&gt;
&lt;br /&gt;
*spot.ms.1&lt;br /&gt;
&lt;br /&gt;
 min=24&lt;br /&gt;
 max=254&lt;br /&gt;
&lt;br /&gt;
*spot.ms.2&lt;br /&gt;
&lt;br /&gt;
 min=14&lt;br /&gt;
 max=254&lt;br /&gt;
*spot.ms.3&lt;br /&gt;
&lt;br /&gt;
 min=12&lt;br /&gt;
 max=254&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Nevertheless, as shown in the examples using MODIS surface reflectance products (read below) in which the range of the bands varies significantly, ''i.pca'''s results do not match the results of R's ''prcomp()'' function with the parameter ''center'' set to ''TRUE''. Instead, the results derived from ''i.pca'' are almost identical when the parameter ''center'' is set to ''FALSE''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following example performs PCA '''without data centering and scaling''' (options ''center=FALSE'' and ''scale=FALSE'').&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 prcomp(spot.ms.nonas, center=FALSE, scale=FALSE)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Standard deviations:&lt;br /&gt;
 [1] '''101.00927'''  15.79861   2.83775&lt;br /&gt;
 &lt;br /&gt;
 Rotation:&lt;br /&gt;
                  PC1        PC2        PC3&lt;br /&gt;
 spot.ms.1 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.5605487&amp;lt;/span&amp;gt; -0.3652694  0.7432116&lt;br /&gt;
 spot.ms.2 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.4726613&amp;lt;/span&amp;gt; -0.5958032 -0.6493149&lt;br /&gt;
 spot.ms.3 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.6799827&amp;lt;/span&amp;gt;  0.7152600 -0.1613280&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Comments]]&lt;br /&gt;
&lt;br /&gt;
+++&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following example performs PCA '''with data centering and scaling''' (options ''center=TRUE'' and ''scale=TRUE'')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 prcomp(spot.ms.nonas, center=TRUE, scale=TRUE)&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Standard deviations:&lt;br /&gt;
 [1] 1.6092826 0.6307795 0.1110256&lt;br /&gt;
 &lt;br /&gt;
 Rotation:&lt;br /&gt;
                  PC1        PC2         PC3&lt;br /&gt;
 spot.ms.1 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.6062688&amp;lt;/span&amp;gt;  0.3232856 -0.72658417&lt;br /&gt;
 spot.ms.2 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.5975823&amp;lt;/span&amp;gt;  0.4176378  0.68445170&lt;br /&gt;
 spot.ms.3 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.5247224&amp;lt;/span&amp;gt; -0.8491555  0.06001103&lt;br /&gt;
&lt;br /&gt;
= Examples using MODIS surface reflectance products =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Eigenvectors solution ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Based on the covariance matrix ===&lt;br /&gt;
&lt;br /&gt;
==== Using '''''m.eigensystem''''' ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command in one line&lt;br /&gt;
&lt;br /&gt;
 (echo 3; r.covar b02,b06,b07) | m.eigensystem&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E&amp;lt;/span&amp;gt; line is the eigen value. (Real part, imaginary part, percent importance)&lt;br /&gt;
* The &amp;lt;tt&amp;gt;V&amp;lt;/tt&amp;gt; lines are the eigen vectors associated with &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E&amp;lt;/span&amp;gt;.&lt;br /&gt;
* The &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N&amp;lt;/span&amp;gt; lines are the &amp;lt;tt&amp;gt;V&amp;lt;/tt&amp;gt; vectors normalized to have a magnitude of 1. '''These are the scaled eigen vectors that correspond to princomp()'s results presented in the following section.'''&lt;br /&gt;
* The &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W&amp;lt;/span&amp;gt; lines are the &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N&amp;lt;/span&amp;gt; vector multiplied by the square root of the magnitude of the eigen value (&amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E&amp;lt;/span&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
 r.covar: complete ...&lt;br /&gt;
 100%&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E    778244.0258462029          .0000000000    79.20&amp;lt;/span&amp;gt;&lt;br /&gt;
 V          .5006581842          .0000000000&lt;br /&gt;
 V          .8256483300          .0000000000&lt;br /&gt;
 V          .6155834548          .0000000000&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N          '''.4372107421'''          .0000000000&lt;br /&gt;
 N          '''.7210155161'''          .0000000000&lt;br /&gt;
 N          '''.5375717557'''          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W       385.6991853500          .0000000000&lt;br /&gt;
 W       636.0664787886          .0000000000&lt;br /&gt;
 W       474.2358050886          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E    192494.5769628266          .0000000000    19.59&amp;lt;/span&amp;gt;&lt;br /&gt;
 V         -.8689798010          .0000000000&lt;br /&gt;
 V          .0996340298          .0000000000&lt;br /&gt;
 V          .5731134848          .0000000000&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N         -.8309940700          .0000000000&lt;br /&gt;
 N          .0952787255          .0000000000&lt;br /&gt;
 N          .5480609638          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W      -364.5920328433          .0000000000&lt;br /&gt;
 W        41.8027823088          .0000000000&lt;br /&gt;
 W       240.4573848757          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E     11876.4548199713          .0000000000     1.21&amp;lt;/span&amp;gt;&lt;br /&gt;
 V          .2872248982          .0000000000&lt;br /&gt;
 V         -.5731591248          .0000000000&lt;br /&gt;
 V          .5351449518          .0000000000&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N          .3439413070          .0000000000&lt;br /&gt;
 N         -.6863370819          .0000000000&lt;br /&gt;
 N          .6408165005          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W        37.4824307850          .0000000000&lt;br /&gt;
 W       -74.7964308085          .0000000000&lt;br /&gt;
 W        69.8356366100          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In general, the solution to the eigen system results in complex&lt;br /&gt;
numbers (with both real and imaginary parts).  However, in the example&lt;br /&gt;
above, since the input matrix is symmetric (i.e., inverting the rows and columns&lt;br /&gt;
gives the same matrix) the eigen system has only real values (i.e., the&lt;br /&gt;
imaginary part is zero).&lt;br /&gt;
This fact makes it possible to use eigen vectors to perform principle component&lt;br /&gt;
transformation of data sets.  The covariance or correlation&lt;br /&gt;
matrix of any data set is symmetric&lt;br /&gt;
and thus has only real eigen values and vectors.&lt;br /&gt;
&lt;br /&gt;
'''Note''' The '''bold''' and &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;red&amp;lt;/span&amp;gt; colored eigen vectors of the first principal component, ease of the comparison with the results derived from R's ''princomp()'' function that follows.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Using the &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W&amp;lt;/span&amp;gt; vector, new maps can be created:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;B&amp;gt;r.mapcalc&amp;lt;/B&amp;gt; 'pc.1 =  &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;385.6992&amp;lt;/span&amp;gt;*map.1 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;+636.0665&amp;lt;/span&amp;gt;*map.2 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;+ 474.2358&amp;lt;/span&amp;gt;*map.3'&lt;br /&gt;
 &amp;lt;B&amp;gt;r.mapcalc&amp;lt;/B&amp;gt; 'pc.2 = &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;-364.5920&amp;lt;/span&amp;gt;*map.1 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;+ 41.8027&amp;lt;/span&amp;gt;*map.2 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;+ 240.4573&amp;lt;/span&amp;gt;*map.3'&lt;br /&gt;
 &amp;lt;B&amp;gt;r.mapcalc&amp;lt;/B&amp;gt; 'pc.3 =   &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;37.4824&amp;lt;/span&amp;gt;*map.1 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;- 74.7964&amp;lt;/span&amp;gt;*map.2 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;+  69.8356&amp;lt;/span&amp;gt;*map.3'&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Using R's '''''princomp()''''' function ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 princomp(modis)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Call:&lt;br /&gt;
 princomp(x = modis)&lt;br /&gt;
 Standard deviations:&lt;br /&gt;
   Comp.1   Comp.2   Comp.3&lt;br /&gt;
 857.5737 436.0922 108.5083&lt;br /&gt;
 3  variables and  350596 observations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Get loadings&lt;br /&gt;
&lt;br /&gt;
 (princomp(modis))$loadings&lt;br /&gt;
 Loadings:&lt;br /&gt;
     Comp.1 Comp.2 Comp.3&lt;br /&gt;
 b02 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.418'''&amp;lt;/span&amp;gt;  0.839  0.348&lt;br /&gt;
 b06 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.725'''&amp;lt;/span&amp;gt;        -0.684&lt;br /&gt;
 b07 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.547'''&amp;lt;/span&amp;gt; -0.539  0.641&lt;br /&gt;
&lt;br /&gt;
                Comp.1 Comp.2 Comp.3&lt;br /&gt;
 SS loadings     1.000  1.000  1.000&lt;br /&gt;
 Proportion Var  0.333  0.333  0.333&lt;br /&gt;
 Cumulative Var  0.333  0.667  1.000&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The '''bold''' and &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;red&amp;lt;/span&amp;gt; colored loadings, that is, the eigen vectors of the first principal component, ease of the comparison with the results derived from GRASS' ''m.eigensystem'' module above. Note the missing eigen value in row 2, column 2. For some reason R refused to yield it.&lt;br /&gt;
&lt;br /&gt;
=== Based on the correlation matrix ===&lt;br /&gt;
&lt;br /&gt;
==== Using '''''m.eigensystem'''''====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command in one line&lt;br /&gt;
&lt;br /&gt;
 (echo 3; r.covar -r MOD07_b02,MOD07_b06,MOD07_b07)|m.eigensystem&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 r.covar: complete ...&lt;br /&gt;
  100%&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E         2.2915877718          .0000000000    76.39&amp;lt;/span&amp;gt;&lt;br /&gt;
 V         -.5755655569          .0000000000&lt;br /&gt;
 V         -.7660355041          .0000000000&lt;br /&gt;
 V         -.6809380186          .0000000000&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N         -.4896413269          .0000000000&lt;br /&gt;
 N         -.6516766616          .0000000000&lt;br /&gt;
 N         -.5792830912          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W         -.7412186091          .0000000000&lt;br /&gt;
 W         -.9865075560          .0000000000&lt;br /&gt;
 W         -.8769182329          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E          .6740687010          .0000000000    22.47&amp;lt;/span&amp;gt;&lt;br /&gt;
 V          .8667178982          .0000000000&lt;br /&gt;
 V         -.1116525720          .0000000000&lt;br /&gt;
 V         -.6069908335          .0000000000&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N          '''.8145815825'''          .0000000000&lt;br /&gt;
 N         '''-.1049362531'''          .0000000000&lt;br /&gt;
 N         '''-.5704780699'''          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W          .6687852213          .0000000000&lt;br /&gt;
 W         -.0861544341          .0000000000&lt;br /&gt;
 W         -.4683721194          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E          .0343435272          .0000000000     1.14&amp;lt;/span&amp;gt;&lt;br /&gt;
 V          .2486404469          .0000000000&lt;br /&gt;
 V         -.6006166822          .0000000000&lt;br /&gt;
 V          .4655120098          .0000000000&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N          .3109794470          .0000000000&lt;br /&gt;
 N         -.7512029762          .0000000000&lt;br /&gt;
 N          .5822249325          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W          .0576307320          .0000000000&lt;br /&gt;
 W         -.1392129859          .0000000000&lt;br /&gt;
 W          .1078979635          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The '''bold''' and &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;red&amp;lt;/span&amp;gt; colored eigen vectors of the second principal component, ease of the comparison with the results derived from R's ''princomp()'' function that follows.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Using R's '''''princomp()''''' function ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 princomp(mod07, cor=TRUE)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Call:&lt;br /&gt;
 princomp(x = mod07, cor = TRUE)&lt;br /&gt;
&lt;br /&gt;
 Standard deviations:&lt;br /&gt;
    Comp.1    Comp.2    Comp.3&lt;br /&gt;
 1.5030740 0.8397807 0.1885121&lt;br /&gt;
 &lt;br /&gt;
  3  variables and  350596 observations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Get loadings&lt;br /&gt;
&lt;br /&gt;
 (princomp(mod07, cor=TRUE))$loadings&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Loadings:&lt;br /&gt;
                              Comp.1 Comp.2 Comp.3&lt;br /&gt;
 MOD2007_242_500_sur_refl_b02 -0.481  &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''0.820'''&amp;lt;/span&amp;gt;  0.310&lt;br /&gt;
 MOD2007_242_500_sur_refl_b06 -0.656 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.102'''&amp;lt;/span&amp;gt; -0.748&lt;br /&gt;
 MOD2007_242_500_sur_refl_b07 -0.582 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.563'''&amp;lt;/span&amp;gt;  0.587&lt;br /&gt;
 &lt;br /&gt;
                Comp.1 Comp.2 Comp.3&lt;br /&gt;
 SS loadings     1.000  1.000  1.000&lt;br /&gt;
 Proportion Var  0.333  0.333  0.333&lt;br /&gt;
 Cumulative Var  0.333  0.667  1.000&lt;br /&gt;
&lt;br /&gt;
The '''bold''' and &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;red&amp;lt;/span&amp;gt; colored loadings, that is, the eigen vectors of the second component, ease of the comparison with the results derived from GRASS' ''m.eigensystem'' module above.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Comments]]&lt;br /&gt;
'''Add comments here...'''&lt;br /&gt;
&lt;br /&gt;
== SVD solution ==&lt;br /&gt;
&lt;br /&gt;
==== Using ''i.pca'' ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 i.pca input=b2,b6,b7 output=pca.b267&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Eigen values, (vectors), and [percent importance]:&lt;br /&gt;
 PC1  '''6307563.04''' ( &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.64, -0.65, -0.42&amp;lt;/span&amp;gt; ) [ 98.71% ]&lt;br /&gt;
 PC2    78023.63 ( -0.71,  0.28,  0.64 ) [  1.22% ]&lt;br /&gt;
 PC3     4504.60 ( -0.30,  0.71, -0.64 ) [  0.07% ] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Using R's ''prcomp()'' function ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following example replicates ''i.pca'''s solution, that is, using the same data without data centering and/or scaling (options ''center=FALSE'' and ''scale=FALSE'').&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 prcomp(mod07, center=FALSE, scale=FALSE) &amp;lt;span style=&amp;quot;color:#006000&amp;quot;&amp;gt;&amp;lt;&amp;lt;== this corresponds to i.pca&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Standard deviations:&lt;br /&gt;
 [1] '''4288.3788'''  476.8904  114.3971&lt;br /&gt;
 Rotation:&lt;br /&gt;
                                    PC1        PC2        PC3&lt;br /&gt;
 MOD2007_242_500_sur_refl_b02 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.6353238&amp;lt;/span&amp;gt;  0.7124070 -0.2980602&lt;br /&gt;
 MOD2007_242_500_sur_refl_b06 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.6485551&amp;lt;/span&amp;gt; -0.2826985  0.7067234&lt;br /&gt;
 MOD2007_242_500_sur_refl_b07 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.4192135&amp;lt;/span&amp;gt; -0.6423066 -0.6416403&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Comments]]&lt;br /&gt;
&lt;br /&gt;
* The eigenvector matrices match although ''prcomp()'' reports loadings (=eigenvectors) column-wise and ''i.pca'' row-wise.&lt;br /&gt;
* The eigenvalues do '''not''' match. To exemplify, the standard deviation for PC1 reported by ''prcomp()'' is '''4288.3788''' and the variance reported by ''i.pca'' is 6307563.04 [ sqrt(6307563.04) = '''2511.486''' ]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''More examples to be added'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
Jon Shlens, &amp;quot;Tutorial on Principal Component Analysis, Dec 2005,&amp;quot; [http://www.snl.salk.edu/~shlens/pub/notes/pca.pdf] (accessed on March, 2009).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== e-mails in GRASS-user mailing list ==&lt;br /&gt;
&lt;br /&gt;
There are many posts concerning the functionality of ''i.pca''. Most of them are questioning the non-reporting of eigenvalues (an issue recently fixed).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Old posts'''&lt;br /&gt;
&lt;br /&gt;
[http://n2.nabble.com/i.pca-output-td1863271.html#a1863271]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Recent posts'''&lt;br /&gt;
&lt;br /&gt;
[http://n2.nabble.com/Testing-i.pca-~-prcomp()%2C-m.eigensystem-~-princomp()-td2413700.html#a2415727 Testing i.pca ~ prcomp(), m.eigensystem ~ princomp()]&lt;br /&gt;
&lt;br /&gt;
[http://n2.nabble.com/Calculating-eigen-values-and---variance-explained-after-PCA-analysis-td2383005.html#a2383165]&lt;br /&gt;
&lt;br /&gt;
[http://n2.nabble.com/Re%3A-Calculating-eigen-valuesand-varianceexplainedafter-PCA-analysis-td2413881.html#a2413881]&lt;br /&gt;
&lt;br /&gt;
[http://n2.nabble.com/Re%3A-Calculating-eigen-values-and--varianceexplainedafter-PCA-analysis-td2395558.html#a2409630]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''More sources to be added'''&lt;br /&gt;
&lt;br /&gt;
[[Category: Documentation]]&lt;/div&gt;</summary>
		<author><name>⚠️EdzerPebesma</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=Principal_Components_Analysis&amp;diff=8573</id>
		<title>Principal Components Analysis</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=Principal_Components_Analysis&amp;diff=8573"/>
		<updated>2009-03-31T14:11:54Z</updated>

		<summary type="html">&lt;p&gt;⚠️EdzerPebesma: /* Terminology */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Under Construction'''&lt;br /&gt;
&lt;br /&gt;
This page is a short and practical introduction in Principal Component Analysis. It aims to highlight the importance of the values returned by PCA. In addition, it addresses numerical accuracy issues with respect to the default implementation of PCA in GRASS through the ''i.pca'' module.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Principal Component Analysis =&lt;br /&gt;
&lt;br /&gt;
Principal Component Analysis (PCA) is a dimensionality reduction technique used extensively in Remote Sensing studies (e.g. in change detection studies, image enhancement tasks and more). PCA is in fact a linear transformation applied on (usually) highly correlated multidimensional (e.g. multispectral) data. The input dimensions are transformed in a new coordinate system in which the produced dimensions (called principal components) contain, in decreasing order, the greatest variance related with unchanged landscape features.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PCA has two algebraic solutions:&lt;br /&gt;
&lt;br /&gt;
* '''Eigenvectors of Covariance''' (or Correlation)&lt;br /&gt;
* '''Singular Value Decomposition'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The '''SVD''' method is used for numerical accuracy [R Documentation]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
The basic steps of the transformation are:&lt;br /&gt;
&lt;br /&gt;
# '''organizing a dataset in a matrix'''&lt;br /&gt;
# '''data centering''' (that is: subtracting the dimensions means from themself so each of the dimensions in the dataset has zero mean)&lt;br /&gt;
# calculate&lt;br /&gt;
#* the '''covariance matrix''' ('''non-standardised PCA''') or&lt;br /&gt;
#* the '''correlation matrix''' ('''standardised PCA''', also known as scaling)&lt;br /&gt;
# calculate either&lt;br /&gt;
#* the '''eigenvectors''' and '''eigenvalues''' of the covariance (or the correlation) matrix or&lt;br /&gt;
#* the '''SVD''' of the data matrix&lt;br /&gt;
# '''sort variances in decreasing order''' (decreasing eigenvalues; this is default in eigenvalue analysis)&lt;br /&gt;
# '''project original dataset ''signals''''' (PC's or PC scores: eigenvector * input-data) to get&lt;br /&gt;
&lt;br /&gt;
== Solutions to PCA ==&lt;br /&gt;
&lt;br /&gt;
The '''Eigenvector''' solution to PCA involves:&lt;br /&gt;
&lt;br /&gt;
# calculation of&lt;br /&gt;
#* the covariance matrix of the given multidimensional dataset (non-standardised PCA) '''''or'''''&lt;br /&gt;
#* the correlation matrix of the given multidimensional dataset (standardised PCA)&lt;br /&gt;
# calculation of the eigenvalues and eigenvectors of the covariance (or correlation) matrix&lt;br /&gt;
# transformation of the input dataset using the eigenvalues as weighting coefficients&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
&lt;br /&gt;
'''eigenvalues''' represent either the variance of the original data contained in each principal component (in case they were computed from the covariance matrix), or the amount of correlation captured by the respective principle components (in case they were computed from the correlation matrix).&lt;br /&gt;
&lt;br /&gt;
'''eigenvectors''' act as weighting coefficients / represent the contribution of each original dimension the principal components / tell how the principle components relate to the the data variables (dimensions). Suppose an eigenvector is (0, 0, 1, 0), this indicates that the corresponding principle component is equal to dimension 3 and perpendicular to dimensions 1, 3 and 4. If it is (0.7, 0.7, 0, 0) the PC is equally determined by dimension 1 and 2 (it averages them), and not determined by dimensions 3 and 4. If it is (0.7, 0, -0.7, 0) it is the difference between dimension 1 and 3. Eigenvectors are normalized, meaning that the sum of its squared elements equals 1. The individual numbers in an eigenvector are called loadings.&lt;br /&gt;
&lt;br /&gt;
== Performing PCA with GRASS ==&lt;br /&gt;
&lt;br /&gt;
* '''''m.eigensystem'''''&lt;br /&gt;
&lt;br /&gt;
The ''m.eigensystem'' module implements the eigenvector solution to PCA. The respective function in R is ''princomp()''. A comparison of their results confirms their almost identical performance. Specifically,&lt;br /&gt;
&lt;br /&gt;
# the standard deviations (sdev) reported by ''princomp()'' are (almost) identical with the variances (eigenvalues) reported by ''m.eigensystem''.&lt;br /&gt;
&lt;br /&gt;
# ''princomp()'' scales (also referred as normalization) the eigenvectors and so does ''m.eigensystem''. The scaled(=normalised) eigenvectors produced by m.eigensystem are marked with the capital letter N.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''''i.pca'''''&lt;br /&gt;
&lt;br /&gt;
The ''i.pca'' module performs PCA based on the SVD solution without data centering and/or scaling. A comparison of the results derived by ''i.pca'' and R's ''prcomp()'' function confirms this. Specifically, ''i.pca'' yields the same eigenvectors as R's ''prcomp()'' function does with the following options:&lt;br /&gt;
&lt;br /&gt;
 prcomp(x, center=FALSE, scale=FALSE)&lt;br /&gt;
&lt;br /&gt;
where x is a numeric or complex matrix (or data frame) which provides the data for the principal components analysis (R Documentation).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Issues concerning the ''i.pca'' module ==&lt;br /&gt;
&lt;br /&gt;
??? To add... ???&lt;br /&gt;
&lt;br /&gt;
== Issues concerning R's ''princomp()'' function ==&lt;br /&gt;
&lt;br /&gt;
* For some reason one loading (=eigenvector) is missing from the output of the default application of princomp() on objects derived from GRASS as described above.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Examples using SPOT imagery =&lt;br /&gt;
Get the SPOT imagery from the Spearfish dataset: [http://grass.osgeo.org/sampledata/imagery60_grassdata.tar.gz SPOT images from the Spearfish dataset]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Eigenvectors solution ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Based on the covariance matrix ===&lt;br /&gt;
&lt;br /&gt;
==== Using '''''m.eigensystem''''' ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command in one line&lt;br /&gt;
&lt;br /&gt;
 (echo 3; r.covar spot.ms.1,spot.ms.2,spot.ms.3) | m.eigensystem&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
 r.covar: complete ...&lt;br /&gt;
  100%&lt;br /&gt;
 E      1159.7452017844          .0000000000    88.38&lt;br /&gt;
 V          .6910021591          .0000000000&lt;br /&gt;
 V          .7205280412          .0000000000&lt;br /&gt;
 V          .4805108400          .0000000000&lt;br /&gt;
 N          .6236808478          .0000000000&lt;br /&gt;
 N          .6503301526          .0000000000&lt;br /&gt;
 N          .4336967751          .0000000000&lt;br /&gt;
 W        21.2394712045          .0000000000&lt;br /&gt;
 W        22.1470141296          .0000000000&lt;br /&gt;
 W        14.7695575384          .0000000000&lt;br /&gt;
 E         5.9705414972          .0000000000      .45&lt;br /&gt;
 V          .7119385973          .0000000000&lt;br /&gt;
 V         -.6358200627          .0000000000&lt;br /&gt;
 V         -.0703936743          .0000000000&lt;br /&gt;
 N          .7438340890          .0000000000&lt;br /&gt;
 N         -.6643053754          .0000000000&lt;br /&gt;
 N         -.0735473745          .0000000000&lt;br /&gt;
 W         1.8175356507          .0000000000&lt;br /&gt;
 W        -1.6232096923          .0000000000&lt;br /&gt;
 W         -.1797107407          .0000000000&lt;br /&gt;
 E       146.5031967184          .0000000000    11.16&lt;br /&gt;
 V          .2265837636          .0000000000&lt;br /&gt;
 V          .3474697082          .0000000000&lt;br /&gt;
 V         -.8468727535          .0000000000&lt;br /&gt;
 N          .2402770238          .0000000000&lt;br /&gt;
 N          .3684685345          .0000000000&lt;br /&gt;
 N         -.8980522763          .0000000000&lt;br /&gt;
 W         2.9082771721          .0000000000&lt;br /&gt;
 W         4.4598880523          .0000000000&lt;br /&gt;
 W       -10.8698904856          .0000000000&lt;br /&gt;
&lt;br /&gt;
==== Using R's '''''princomp()''''' function ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Launch R from within GRASS&lt;br /&gt;
 R&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Load spgrass6() and projection information in R&lt;br /&gt;
 library(spgrass6)&lt;br /&gt;
 G &amp;lt;- gmeta6()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Read spot.ms bands&lt;br /&gt;
 spot.ms &amp;lt;- readRAST6(c('spot.ms.1', 'spot.ms.2', 'spot.ms.3'))&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Work around NA's&lt;br /&gt;
 spot.ms.nas &amp;lt;- which(is.na(spot.ms@data$spot.ms.1) &amp;amp; is.na(spot.ms@data$spot.ms.2) &amp;amp; is.na(spot.ms@data$spot.ms.3))&lt;br /&gt;
 spot.ms.values &amp;lt;- which(!is.na(spot.ms@data$spot.ms.1) &amp;amp; !is.na(spot.ms@data$spot.ms.2) &amp;amp; !is.na(spot.ms@data$spot.ms.3))&lt;br /&gt;
 spot.ms.nonas &amp;lt;- spot.ms.values@data[spot.ms.values, ]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 princomp(spot.ms.nonas)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Call:&lt;br /&gt;
 princomp(x = modis)&lt;br /&gt;
 Standard deviations:&lt;br /&gt;
   Comp.1   Comp.2   Comp.3&lt;br /&gt;
 34.055018 12.103846  2.443468&lt;br /&gt;
 &lt;br /&gt;
 3  variables and  1231860 observations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Get loadings&lt;br /&gt;
&lt;br /&gt;
 princomp(spot.ms.nonas)$loadings&lt;br /&gt;
 Loadings:&lt;br /&gt;
     Comp.1 Comp.2 Comp.3&lt;br /&gt;
 spot.ms.1 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.624'''&amp;lt;/span&amp;gt;  0.240  0.744&lt;br /&gt;
 spot.ms.2 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.650'''&amp;lt;/span&amp;gt; -0.368 -0.664&lt;br /&gt;
 spot.ms.3 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.434'''&amp;lt;/span&amp;gt;  0.898 &lt;br /&gt;
 &lt;br /&gt;
                Comp.1 Comp.2 Comp.3&lt;br /&gt;
 SS loadings     1.000  1.000  1.000&lt;br /&gt;
 Proportion Var  0.333  0.333  0.333&lt;br /&gt;
 Cumulative Var  0.333  0.667  1.000&lt;br /&gt;
&lt;br /&gt;
The '''bold''' and &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;red&amp;lt;/span&amp;gt; colored loadings, that is, the eigen vectors of the first principal component, ease of the comparison with the results derived from GRASS' ''m.eigensystem'' module above. Note the missing eigen value in row 3, column 3. For some reason R refused to yield it.&lt;br /&gt;
&lt;br /&gt;
=== Based on the correlation matrix ===&lt;br /&gt;
&lt;br /&gt;
==== Using '''''m.eigensystem'''''====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command in one line&lt;br /&gt;
&lt;br /&gt;
 (echo 3; r.covar -r spot.ms.1,spot.ms.2,spot.ms.3) | m.eigensystem&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 r.covar: complete ...&lt;br /&gt;
  100%&lt;br /&gt;
 E         2.5897901435          .0000000000    86.33&lt;br /&gt;
 V         -.7080795162          .0000000000&lt;br /&gt;
 V         -.6979341819          .0000000000&lt;br /&gt;
 V         -.6128387525          .0000000000&lt;br /&gt;
 N         -.6062688915          .0000000000&lt;br /&gt;
 N         -.5975822957          .0000000000&lt;br /&gt;
 N         -.5247222419          .0000000000&lt;br /&gt;
 W         -.9756579133          .0000000000&lt;br /&gt;
 W         -.9616787268          .0000000000&lt;br /&gt;
 W         -.8444263177          .0000000000&lt;br /&gt;
 E          .0123265666          .0000000000      .41&lt;br /&gt;
 V         -.6690685456          .0000000000&lt;br /&gt;
 V          .6302711261          .0000000000&lt;br /&gt;
 V          .0552608155          .0000000000&lt;br /&gt;
 N         -.7265842171          .0000000000&lt;br /&gt;
 N          .6844516242          .0000000000&lt;br /&gt;
 N          .0600112449          .0000000000&lt;br /&gt;
 W         -.0806690651          .0000000000&lt;br /&gt;
 W          .0759912909          .0000000000&lt;br /&gt;
 W          .0066627528          .0000000000&lt;br /&gt;
 E          .3978832898          .0000000000    13.26&lt;br /&gt;
 V          .3005969725          .0000000000&lt;br /&gt;
 V          .3883277727          .0000000000&lt;br /&gt;
 V         -.7895613377          .0000000000&lt;br /&gt;
 N          .3232853332          .0000000000&lt;br /&gt;
 N          .4176378502          .0000000000&lt;br /&gt;
 N         -.8491555920          .0000000000&lt;br /&gt;
 W          .2039218921          .0000000000&lt;br /&gt;
 W          .2634375639          .0000000000&lt;br /&gt;
 W         -.5356302845          .0000000000&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Using R's '''''princomp()''''' function ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Perform PCA&lt;br /&gt;
&lt;br /&gt;
 princomp(spot.ms.nonas, cor=TRUE)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Call:&lt;br /&gt;
 princomp(x = spot.ms.nonas, cor = TRUE)&lt;br /&gt;
 &lt;br /&gt;
 Standard deviations:&lt;br /&gt;
    Comp.1    Comp.2    Comp.3 &lt;br /&gt;
 1.6092826 0.6307795 0.1110256&lt;br /&gt;
 &lt;br /&gt;
 3  variables and  1231860 observations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Get loadings &lt;br /&gt;
&lt;br /&gt;
 princomp(spot.ms.nonas, cor=TRUE)$loadings&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Loadings:&lt;br /&gt;
           Comp.1 Comp.2 Comp.3&lt;br /&gt;
 spot.ms.1 -0.606 -0.323  0.727&lt;br /&gt;
 spot.ms.2 -0.598 -0.418 -0.684&lt;br /&gt;
 spot.ms.3 -0.525  0.849       &lt;br /&gt;
 &lt;br /&gt;
                Comp.1 Comp.2 Comp.3&lt;br /&gt;
 SS loadings     1.000  1.000  1.000&lt;br /&gt;
 Proportion Var  0.333  0.333  0.333&lt;br /&gt;
 Cumulative Var  0.333  0.667  1.000&lt;br /&gt;
&lt;br /&gt;
== SVD solution ==&lt;br /&gt;
&lt;br /&gt;
==== Using ''i.pca'' ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 i.pca input=spot.ms.1,spot.ms.2,spot.ms.3 out=pca.spot.ms rescale=0,0&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
  Eigen values, (vectors), and [percent importance]:&lt;br /&gt;
   PC1   '''1170.12''' (&amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.6251,-0.6536,-0.4268&amp;lt;/span&amp;gt;)[88.07%]&lt;br /&gt;
   PC2    152.49 ( 0.2328, 0.3658,-0.9011)[11.48%]&lt;br /&gt;
   PC3      6.01 ( 0.7450,-0.6626,-0.0765) [0.45%]&lt;br /&gt;
&lt;br /&gt;
==== Using R's ''prcomp()'' function ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following example replicates ''i.pca'''s solution using the same data '''with data centering and without scaling''' (options ''center=TRUE'' and ''scale=FALSE''). Note that these settings are the defaults.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 prcomp(spot.ms.nonas)&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Standard deviations:&lt;br /&gt;
 [1] 34.055032 12.103851  2.443469&lt;br /&gt;
 &lt;br /&gt;
 Rotation:&lt;br /&gt;
                  PC1        PC2         PC3&lt;br /&gt;
 spot.ms.1 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.6236808&amp;lt;/span&amp;gt;  0.2402770 -0.74383409&lt;br /&gt;
 spot.ms.2 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.6503302&amp;lt;/span&amp;gt;  0.3684685  0.66430538&lt;br /&gt;
 spot.ms.3 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.4336968&amp;lt;/span&amp;gt; -0.8980523  0.07354738&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Comments]]&lt;br /&gt;
&lt;br /&gt;
In this example ''i.pca'''s performance seems to be identical to R's ''prcomp()'' function which means that data centering is applied prior to the actual PCA.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The three SPOT bands used in this example have the following ranges:&lt;br /&gt;
&lt;br /&gt;
*spot.ms.1&lt;br /&gt;
&lt;br /&gt;
 min=24&lt;br /&gt;
 max=254&lt;br /&gt;
&lt;br /&gt;
*spot.ms.2&lt;br /&gt;
&lt;br /&gt;
 min=14&lt;br /&gt;
 max=254&lt;br /&gt;
*spot.ms.3&lt;br /&gt;
&lt;br /&gt;
 min=12&lt;br /&gt;
 max=254&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Nevertheless, as shown in the examples using MODIS surface reflectance products (read below) in which the range of the bands varies significantly, ''i.pca'''s results do not match the results of R's ''prcomp()'' function with the parameter ''center'' set to ''TRUE''. Instead, the results derived from ''i.pca'' are almost identical when the parameter ''center'' is set to ''FALSE''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following example performs PCA '''without data centering and scaling''' (options ''center=FALSE'' and ''scale=FALSE'').&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 prcomp(spot.ms.nonas, center=FALSE, scale=FALSE)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Standard deviations:&lt;br /&gt;
 [1] '''101.00927'''  15.79861   2.83775&lt;br /&gt;
 &lt;br /&gt;
 Rotation:&lt;br /&gt;
                  PC1        PC2        PC3&lt;br /&gt;
 spot.ms.1 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.5605487&amp;lt;/span&amp;gt; -0.3652694  0.7432116&lt;br /&gt;
 spot.ms.2 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.4726613&amp;lt;/span&amp;gt; -0.5958032 -0.6493149&lt;br /&gt;
 spot.ms.3 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.6799827&amp;lt;/span&amp;gt;  0.7152600 -0.1613280&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Comments]]&lt;br /&gt;
&lt;br /&gt;
+++&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following example performs PCA '''with data centering and scaling''' (options ''center=TRUE'' and ''scale=TRUE'')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 prcomp(spot.ms.nonas, center=TRUE, scale=TRUE)&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Standard deviations:&lt;br /&gt;
 [1] 1.6092826 0.6307795 0.1110256&lt;br /&gt;
 &lt;br /&gt;
 Rotation:&lt;br /&gt;
                  PC1        PC2         PC3&lt;br /&gt;
 spot.ms.1 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.6062688&amp;lt;/span&amp;gt;  0.3232856 -0.72658417&lt;br /&gt;
 spot.ms.2 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.5975823&amp;lt;/span&amp;gt;  0.4176378  0.68445170&lt;br /&gt;
 spot.ms.3 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.5247224&amp;lt;/span&amp;gt; -0.8491555  0.06001103&lt;br /&gt;
&lt;br /&gt;
= Examples using MODIS surface reflectance products =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Eigenvectors solution ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Based on the covariance matrix ===&lt;br /&gt;
&lt;br /&gt;
==== Using '''''m.eigensystem''''' ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command in one line&lt;br /&gt;
&lt;br /&gt;
 (echo 3; r.covar b02,b06,b07) | m.eigensystem&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E&amp;lt;/span&amp;gt; line is the eigen value. (Real part, imaginary part, percent importance)&lt;br /&gt;
* The &amp;lt;tt&amp;gt;V&amp;lt;/tt&amp;gt; lines are the eigen vectors associated with &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E&amp;lt;/span&amp;gt;.&lt;br /&gt;
* The &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N&amp;lt;/span&amp;gt; lines are the &amp;lt;tt&amp;gt;V&amp;lt;/tt&amp;gt; vectors normalized to have a magnitude of 1. '''These are the scaled eigen vectors that correspond to princomp()'s results presented in the following section.'''&lt;br /&gt;
* The &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W&amp;lt;/span&amp;gt; lines are the &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N&amp;lt;/span&amp;gt; vector multiplied by the square root of the magnitude of the eigen value (&amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E&amp;lt;/span&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
 r.covar: complete ...&lt;br /&gt;
 100%&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E    778244.0258462029          .0000000000    79.20&amp;lt;/span&amp;gt;&lt;br /&gt;
 V          .5006581842          .0000000000&lt;br /&gt;
 V          .8256483300          .0000000000&lt;br /&gt;
 V          .6155834548          .0000000000&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N          '''.4372107421'''          .0000000000&lt;br /&gt;
 N          '''.7210155161'''          .0000000000&lt;br /&gt;
 N          '''.5375717557'''          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W       385.6991853500          .0000000000&lt;br /&gt;
 W       636.0664787886          .0000000000&lt;br /&gt;
 W       474.2358050886          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E    192494.5769628266          .0000000000    19.59&amp;lt;/span&amp;gt;&lt;br /&gt;
 V         -.8689798010          .0000000000&lt;br /&gt;
 V          .0996340298          .0000000000&lt;br /&gt;
 V          .5731134848          .0000000000&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N         -.8309940700          .0000000000&lt;br /&gt;
 N          .0952787255          .0000000000&lt;br /&gt;
 N          .5480609638          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W      -364.5920328433          .0000000000&lt;br /&gt;
 W        41.8027823088          .0000000000&lt;br /&gt;
 W       240.4573848757          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E     11876.4548199713          .0000000000     1.21&amp;lt;/span&amp;gt;&lt;br /&gt;
 V          .2872248982          .0000000000&lt;br /&gt;
 V         -.5731591248          .0000000000&lt;br /&gt;
 V          .5351449518          .0000000000&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N          .3439413070          .0000000000&lt;br /&gt;
 N         -.6863370819          .0000000000&lt;br /&gt;
 N          .6408165005          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W        37.4824307850          .0000000000&lt;br /&gt;
 W       -74.7964308085          .0000000000&lt;br /&gt;
 W        69.8356366100          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In general, the solution to the eigen system results in complex&lt;br /&gt;
numbers (with both real and imaginary parts).  However, in the example&lt;br /&gt;
above, since the input matrix is symmetric (i.e., inverting the rows and columns&lt;br /&gt;
gives the same matrix) the eigen system has only real values (i.e., the&lt;br /&gt;
imaginary part is zero).&lt;br /&gt;
This fact makes it possible to use eigen vectors to perform principle component&lt;br /&gt;
transformation of data sets.  The covariance or correlation&lt;br /&gt;
matrix of any data set is symmetric&lt;br /&gt;
and thus has only real eigen values and vectors.&lt;br /&gt;
&lt;br /&gt;
'''Note''' The '''bold''' and &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;red&amp;lt;/span&amp;gt; colored eigen vectors of the first principal component, ease of the comparison with the results derived from R's ''princomp()'' function that follows.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Using the &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W&amp;lt;/span&amp;gt; vector, new maps can be created:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;B&amp;gt;r.mapcalc&amp;lt;/B&amp;gt; 'pc.1 =  &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;385.6992&amp;lt;/span&amp;gt;*map.1 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;+636.0665&amp;lt;/span&amp;gt;*map.2 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;+ 474.2358&amp;lt;/span&amp;gt;*map.3'&lt;br /&gt;
 &amp;lt;B&amp;gt;r.mapcalc&amp;lt;/B&amp;gt; 'pc.2 = &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;-364.5920&amp;lt;/span&amp;gt;*map.1 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;+ 41.8027&amp;lt;/span&amp;gt;*map.2 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;+ 240.4573&amp;lt;/span&amp;gt;*map.3'&lt;br /&gt;
 &amp;lt;B&amp;gt;r.mapcalc&amp;lt;/B&amp;gt; 'pc.3 =   &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;37.4824&amp;lt;/span&amp;gt;*map.1 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;- 74.7964&amp;lt;/span&amp;gt;*map.2 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;+  69.8356&amp;lt;/span&amp;gt;*map.3'&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Using R's '''''princomp()''''' function ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 princomp(modis)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Call:&lt;br /&gt;
 princomp(x = modis)&lt;br /&gt;
 Standard deviations:&lt;br /&gt;
   Comp.1   Comp.2   Comp.3&lt;br /&gt;
 857.5737 436.0922 108.5083&lt;br /&gt;
 3  variables and  350596 observations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Get loadings&lt;br /&gt;
&lt;br /&gt;
 (princomp(modis))$loadings&lt;br /&gt;
 Loadings:&lt;br /&gt;
     Comp.1 Comp.2 Comp.3&lt;br /&gt;
 b02 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.418'''&amp;lt;/span&amp;gt;  0.839  0.348&lt;br /&gt;
 b06 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.725'''&amp;lt;/span&amp;gt;        -0.684&lt;br /&gt;
 b07 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.547'''&amp;lt;/span&amp;gt; -0.539  0.641&lt;br /&gt;
&lt;br /&gt;
                Comp.1 Comp.2 Comp.3&lt;br /&gt;
 SS loadings     1.000  1.000  1.000&lt;br /&gt;
 Proportion Var  0.333  0.333  0.333&lt;br /&gt;
 Cumulative Var  0.333  0.667  1.000&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The '''bold''' and &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;red&amp;lt;/span&amp;gt; colored loadings, that is, the eigen vectors of the first principal component, ease of the comparison with the results derived from GRASS' ''m.eigensystem'' module above. Note the missing eigen value in row 2, column 2. For some reason R refused to yield it.&lt;br /&gt;
&lt;br /&gt;
=== Based on the correlation matrix ===&lt;br /&gt;
&lt;br /&gt;
==== Using '''''m.eigensystem'''''====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command in one line&lt;br /&gt;
&lt;br /&gt;
 (echo 3; r.covar -r MOD07_b02,MOD07_b06,MOD07_b07)|m.eigensystem&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 r.covar: complete ...&lt;br /&gt;
  100%&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E         2.2915877718          .0000000000    76.39&amp;lt;/span&amp;gt;&lt;br /&gt;
 V         -.5755655569          .0000000000&lt;br /&gt;
 V         -.7660355041          .0000000000&lt;br /&gt;
 V         -.6809380186          .0000000000&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N         -.4896413269          .0000000000&lt;br /&gt;
 N         -.6516766616          .0000000000&lt;br /&gt;
 N         -.5792830912          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W         -.7412186091          .0000000000&lt;br /&gt;
 W         -.9865075560          .0000000000&lt;br /&gt;
 W         -.8769182329          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E          .6740687010          .0000000000    22.47&amp;lt;/span&amp;gt;&lt;br /&gt;
 V          .8667178982          .0000000000&lt;br /&gt;
 V         -.1116525720          .0000000000&lt;br /&gt;
 V         -.6069908335          .0000000000&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N          '''.8145815825'''          .0000000000&lt;br /&gt;
 N         '''-.1049362531'''          .0000000000&lt;br /&gt;
 N         '''-.5704780699'''          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W          .6687852213          .0000000000&lt;br /&gt;
 W         -.0861544341          .0000000000&lt;br /&gt;
 W         -.4683721194          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E          .0343435272          .0000000000     1.14&amp;lt;/span&amp;gt;&lt;br /&gt;
 V          .2486404469          .0000000000&lt;br /&gt;
 V         -.6006166822          .0000000000&lt;br /&gt;
 V          .4655120098          .0000000000&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N          .3109794470          .0000000000&lt;br /&gt;
 N         -.7512029762          .0000000000&lt;br /&gt;
 N          .5822249325          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W          .0576307320          .0000000000&lt;br /&gt;
 W         -.1392129859          .0000000000&lt;br /&gt;
 W          .1078979635          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The '''bold''' and &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;red&amp;lt;/span&amp;gt; colored eigen vectors of the second principal component, ease of the comparison with the results derived from R's ''princomp()'' function that follows.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Using R's '''''princomp()''''' function ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 princomp(mod07, cor=TRUE)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Call:&lt;br /&gt;
 princomp(x = mod07, cor = TRUE)&lt;br /&gt;
&lt;br /&gt;
 Standard deviations:&lt;br /&gt;
    Comp.1    Comp.2    Comp.3&lt;br /&gt;
 1.5030740 0.8397807 0.1885121&lt;br /&gt;
 &lt;br /&gt;
  3  variables and  350596 observations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Get loadings&lt;br /&gt;
&lt;br /&gt;
 (princomp(mod07, cor=TRUE))$loadings&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Loadings:&lt;br /&gt;
                              Comp.1 Comp.2 Comp.3&lt;br /&gt;
 MOD2007_242_500_sur_refl_b02 -0.481  &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''0.820'''&amp;lt;/span&amp;gt;  0.310&lt;br /&gt;
 MOD2007_242_500_sur_refl_b06 -0.656 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.102'''&amp;lt;/span&amp;gt; -0.748&lt;br /&gt;
 MOD2007_242_500_sur_refl_b07 -0.582 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.563'''&amp;lt;/span&amp;gt;  0.587&lt;br /&gt;
 &lt;br /&gt;
                Comp.1 Comp.2 Comp.3&lt;br /&gt;
 SS loadings     1.000  1.000  1.000&lt;br /&gt;
 Proportion Var  0.333  0.333  0.333&lt;br /&gt;
 Cumulative Var  0.333  0.667  1.000&lt;br /&gt;
&lt;br /&gt;
The '''bold''' and &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;red&amp;lt;/span&amp;gt; colored loadings, that is, the eigen vectors of the second component, ease of the comparison with the results derived from GRASS' ''m.eigensystem'' module above.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Comments]]&lt;br /&gt;
'''Add comments here...'''&lt;br /&gt;
&lt;br /&gt;
== SVD solution ==&lt;br /&gt;
&lt;br /&gt;
==== Using ''i.pca'' ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 i.pca input=b2,b6,b7 output=pca.b267&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Eigen values, (vectors), and [percent importance]:&lt;br /&gt;
 PC1  '''6307563.04''' ( &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.64, -0.65, -0.42&amp;lt;/span&amp;gt; ) [ 98.71% ]&lt;br /&gt;
 PC2    78023.63 ( -0.71,  0.28,  0.64 ) [  1.22% ]&lt;br /&gt;
 PC3     4504.60 ( -0.30,  0.71, -0.64 ) [  0.07% ] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Using R's ''prcomp()'' function ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following example replicates ''i.pca'''s solution, that is, using the same data without data centering and/or scaling (options ''center=FALSE'' and ''scale=FALSE'').&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 prcomp(mod07, center=FALSE, scale=FALSE) &amp;lt;span style=&amp;quot;color:#006000&amp;quot;&amp;gt;&amp;lt;&amp;lt;== this corresponds to i.pca&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Standard deviations:&lt;br /&gt;
 [1] '''4288.3788'''  476.8904  114.3971&lt;br /&gt;
 Rotation:&lt;br /&gt;
                                    PC1        PC2        PC3&lt;br /&gt;
 MOD2007_242_500_sur_refl_b02 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.6353238&amp;lt;/span&amp;gt;  0.7124070 -0.2980602&lt;br /&gt;
 MOD2007_242_500_sur_refl_b06 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.6485551&amp;lt;/span&amp;gt; -0.2826985  0.7067234&lt;br /&gt;
 MOD2007_242_500_sur_refl_b07 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.4192135&amp;lt;/span&amp;gt; -0.6423066 -0.6416403&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Comments]]&lt;br /&gt;
&lt;br /&gt;
* The eigenvector matrices match although ''prcomp()'' reports loadings (=eigenvectors) column-wise and ''i.pca'' row-wise.&lt;br /&gt;
* The eigenvalues do '''not''' match. To exemplify, the standard deviation for PC1 reported by ''prcomp()'' is '''4288.3788''' and the variance reported by ''i.pca'' is 6307563.04 [ sqrt(6307563.04) = '''2511.486''' ]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''More examples to be added'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
Jon Shlens, &amp;quot;Tutorial on Principal Component Analysis, Dec 2005,&amp;quot; [http://www.snl.salk.edu/~shlens/pub/notes/pca.pdf] (accessed on March, 2009).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== e-mails in GRASS-user mailing list ==&lt;br /&gt;
&lt;br /&gt;
There are many posts concerning the functionality of ''i.pca''. Most of them are questioning the non-reporting of eigenvalues (an issue recently fixed).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Old posts'''&lt;br /&gt;
&lt;br /&gt;
[http://n2.nabble.com/i.pca-output-td1863271.html#a1863271]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Recent posts'''&lt;br /&gt;
&lt;br /&gt;
[http://n2.nabble.com/Testing-i.pca-~-prcomp()%2C-m.eigensystem-~-princomp()-td2413700.html#a2415727 Testing i.pca ~ prcomp(), m.eigensystem ~ princomp()]&lt;br /&gt;
&lt;br /&gt;
[http://n2.nabble.com/Calculating-eigen-values-and---variance-explained-after-PCA-analysis-td2383005.html#a2383165]&lt;br /&gt;
&lt;br /&gt;
[http://n2.nabble.com/Re%3A-Calculating-eigen-valuesand-varianceexplainedafter-PCA-analysis-td2413881.html#a2413881]&lt;br /&gt;
&lt;br /&gt;
[http://n2.nabble.com/Re%3A-Calculating-eigen-values-and--varianceexplainedafter-PCA-analysis-td2395558.html#a2409630]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''More sources to be added'''&lt;br /&gt;
&lt;br /&gt;
[[Category: Documentation]]&lt;/div&gt;</summary>
		<author><name>⚠️EdzerPebesma</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=Principal_Components_Analysis&amp;diff=8572</id>
		<title>Principal Components Analysis</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=Principal_Components_Analysis&amp;diff=8572"/>
		<updated>2009-03-31T14:10:57Z</updated>

		<summary type="html">&lt;p&gt;⚠️EdzerPebesma: /* Terminology */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Under Construction'''&lt;br /&gt;
&lt;br /&gt;
This page is a short and practical introduction in Principal Component Analysis. It aims to highlight the importance of the values returned by PCA. In addition, it addresses numerical accuracy issues with respect to the default implementation of PCA in GRASS through the ''i.pca'' module.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Principal Component Analysis =&lt;br /&gt;
&lt;br /&gt;
Principal Component Analysis (PCA) is a dimensionality reduction technique used extensively in Remote Sensing studies (e.g. in change detection studies, image enhancement tasks and more). PCA is in fact a linear transformation applied on (usually) highly correlated multidimensional (e.g. multispectral) data. The input dimensions are transformed in a new coordinate system in which the produced dimensions (called principal components) contain, in decreasing order, the greatest variance related with unchanged landscape features.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PCA has two algebraic solutions:&lt;br /&gt;
&lt;br /&gt;
* '''Eigenvectors of Covariance''' (or Correlation)&lt;br /&gt;
* '''Singular Value Decomposition'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The '''SVD''' method is used for numerical accuracy [R Documentation]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
The basic steps of the transformation are:&lt;br /&gt;
&lt;br /&gt;
# '''organizing a dataset in a matrix'''&lt;br /&gt;
# '''data centering''' (that is: subtracting the dimensions means from themself so each of the dimensions in the dataset has zero mean)&lt;br /&gt;
# calculate&lt;br /&gt;
#* the '''covariance matrix''' ('''non-standardised PCA''') or&lt;br /&gt;
#* the '''correlation matrix''' ('''standardised PCA''', also known as scaling)&lt;br /&gt;
# calculate either&lt;br /&gt;
#* the '''eigenvectors''' and '''eigenvalues''' of the covariance (or the correlation) matrix or&lt;br /&gt;
#* the '''SVD''' of the data matrix&lt;br /&gt;
# '''sort variances in decreasing order''' (decreasing eigenvalues; this is default in eigenvalue analysis)&lt;br /&gt;
# '''project original dataset ''signals''''' (PC's or PC scores: eigenvector * input-data) to get&lt;br /&gt;
&lt;br /&gt;
== Solutions to PCA ==&lt;br /&gt;
&lt;br /&gt;
The '''Eigenvector''' solution to PCA involves:&lt;br /&gt;
&lt;br /&gt;
# calculation of&lt;br /&gt;
#* the covariance matrix of the given multidimensional dataset (non-standardised PCA) '''''or'''''&lt;br /&gt;
#* the correlation matrix of the given multidimensional dataset (standardised PCA)&lt;br /&gt;
# calculation of the eigenvalues and eigenvectors of the covariance (or correlation) matrix&lt;br /&gt;
# transformation of the input dataset using the eigenvalues as weighting coefficients&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
&lt;br /&gt;
'''eigenvalues''' represent either the variance of the original data contained in each principal component (in case they were computed from the covariance matrix), or the amount of correlation captured by the respective principle components (in case they were computed from the correlation matrix).&lt;br /&gt;
&lt;br /&gt;
'''eigenvectors''' act as weighting coefficients / represent the contribution of each original dimension the principal components / tell how the principle components relate to the the data variables (dimensions). Suppose an eigenvector is (0 0 1 0), this indicates that the corresponding principle component is equal to dimension 3 and perpendicular to dimensions 1, 3 and 4. If it is (0.7, 0.7, 0, 0) the PC is equally determined by dimension 1 and 2 (it averages them), and not determined by dimensions 3 and 4. If it is (0.7, 0, -0.7, 0) it is the difference between dimension 1 and 3. Eigenvectors are normalized, meaning that the sum of its squared elements equals 1. The individual numbers in an eigenvector are called loadings.&lt;br /&gt;
&lt;br /&gt;
== Performing PCA with GRASS ==&lt;br /&gt;
&lt;br /&gt;
* '''''m.eigensystem'''''&lt;br /&gt;
&lt;br /&gt;
The ''m.eigensystem'' module implements the eigenvector solution to PCA. The respective function in R is ''princomp()''. A comparison of their results confirms their almost identical performance. Specifically,&lt;br /&gt;
&lt;br /&gt;
# the standard deviations (sdev) reported by ''princomp()'' are (almost) identical with the variances (eigenvalues) reported by ''m.eigensystem''.&lt;br /&gt;
&lt;br /&gt;
# ''princomp()'' scales (also referred as normalization) the eigenvectors and so does ''m.eigensystem''. The scaled(=normalised) eigenvectors produced by m.eigensystem are marked with the capital letter N.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''''i.pca'''''&lt;br /&gt;
&lt;br /&gt;
The ''i.pca'' module performs PCA based on the SVD solution without data centering and/or scaling. A comparison of the results derived by ''i.pca'' and R's ''prcomp()'' function confirms this. Specifically, ''i.pca'' yields the same eigenvectors as R's ''prcomp()'' function does with the following options:&lt;br /&gt;
&lt;br /&gt;
 prcomp(x, center=FALSE, scale=FALSE)&lt;br /&gt;
&lt;br /&gt;
where x is a numeric or complex matrix (or data frame) which provides the data for the principal components analysis (R Documentation).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Issues concerning the ''i.pca'' module ==&lt;br /&gt;
&lt;br /&gt;
??? To add... ???&lt;br /&gt;
&lt;br /&gt;
== Issues concerning R's ''princomp()'' function ==&lt;br /&gt;
&lt;br /&gt;
* For some reason one loading (=eigenvector) is missing from the output of the default application of princomp() on objects derived from GRASS as described above.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Examples using SPOT imagery =&lt;br /&gt;
Get the SPOT imagery from the Spearfish dataset: [http://grass.osgeo.org/sampledata/imagery60_grassdata.tar.gz SPOT images from the Spearfish dataset]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Eigenvectors solution ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Based on the covariance matrix ===&lt;br /&gt;
&lt;br /&gt;
==== Using '''''m.eigensystem''''' ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command in one line&lt;br /&gt;
&lt;br /&gt;
 (echo 3; r.covar spot.ms.1,spot.ms.2,spot.ms.3) | m.eigensystem&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
 r.covar: complete ...&lt;br /&gt;
  100%&lt;br /&gt;
 E      1159.7452017844          .0000000000    88.38&lt;br /&gt;
 V          .6910021591          .0000000000&lt;br /&gt;
 V          .7205280412          .0000000000&lt;br /&gt;
 V          .4805108400          .0000000000&lt;br /&gt;
 N          .6236808478          .0000000000&lt;br /&gt;
 N          .6503301526          .0000000000&lt;br /&gt;
 N          .4336967751          .0000000000&lt;br /&gt;
 W        21.2394712045          .0000000000&lt;br /&gt;
 W        22.1470141296          .0000000000&lt;br /&gt;
 W        14.7695575384          .0000000000&lt;br /&gt;
 E         5.9705414972          .0000000000      .45&lt;br /&gt;
 V          .7119385973          .0000000000&lt;br /&gt;
 V         -.6358200627          .0000000000&lt;br /&gt;
 V         -.0703936743          .0000000000&lt;br /&gt;
 N          .7438340890          .0000000000&lt;br /&gt;
 N         -.6643053754          .0000000000&lt;br /&gt;
 N         -.0735473745          .0000000000&lt;br /&gt;
 W         1.8175356507          .0000000000&lt;br /&gt;
 W        -1.6232096923          .0000000000&lt;br /&gt;
 W         -.1797107407          .0000000000&lt;br /&gt;
 E       146.5031967184          .0000000000    11.16&lt;br /&gt;
 V          .2265837636          .0000000000&lt;br /&gt;
 V          .3474697082          .0000000000&lt;br /&gt;
 V         -.8468727535          .0000000000&lt;br /&gt;
 N          .2402770238          .0000000000&lt;br /&gt;
 N          .3684685345          .0000000000&lt;br /&gt;
 N         -.8980522763          .0000000000&lt;br /&gt;
 W         2.9082771721          .0000000000&lt;br /&gt;
 W         4.4598880523          .0000000000&lt;br /&gt;
 W       -10.8698904856          .0000000000&lt;br /&gt;
&lt;br /&gt;
==== Using R's '''''princomp()''''' function ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Launch R from within GRASS&lt;br /&gt;
 R&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Load spgrass6() and projection information in R&lt;br /&gt;
 library(spgrass6)&lt;br /&gt;
 G &amp;lt;- gmeta6()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Read spot.ms bands&lt;br /&gt;
 spot.ms &amp;lt;- readRAST6(c('spot.ms.1', 'spot.ms.2', 'spot.ms.3'))&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Work around NA's&lt;br /&gt;
 spot.ms.nas &amp;lt;- which(is.na(spot.ms@data$spot.ms.1) &amp;amp; is.na(spot.ms@data$spot.ms.2) &amp;amp; is.na(spot.ms@data$spot.ms.3))&lt;br /&gt;
 spot.ms.values &amp;lt;- which(!is.na(spot.ms@data$spot.ms.1) &amp;amp; !is.na(spot.ms@data$spot.ms.2) &amp;amp; !is.na(spot.ms@data$spot.ms.3))&lt;br /&gt;
 spot.ms.nonas &amp;lt;- spot.ms.values@data[spot.ms.values, ]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 princomp(spot.ms.nonas)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Call:&lt;br /&gt;
 princomp(x = modis)&lt;br /&gt;
 Standard deviations:&lt;br /&gt;
   Comp.1   Comp.2   Comp.3&lt;br /&gt;
 34.055018 12.103846  2.443468&lt;br /&gt;
 &lt;br /&gt;
 3  variables and  1231860 observations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Get loadings&lt;br /&gt;
&lt;br /&gt;
 princomp(spot.ms.nonas)$loadings&lt;br /&gt;
 Loadings:&lt;br /&gt;
     Comp.1 Comp.2 Comp.3&lt;br /&gt;
 spot.ms.1 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.624'''&amp;lt;/span&amp;gt;  0.240  0.744&lt;br /&gt;
 spot.ms.2 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.650'''&amp;lt;/span&amp;gt; -0.368 -0.664&lt;br /&gt;
 spot.ms.3 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.434'''&amp;lt;/span&amp;gt;  0.898 &lt;br /&gt;
 &lt;br /&gt;
                Comp.1 Comp.2 Comp.3&lt;br /&gt;
 SS loadings     1.000  1.000  1.000&lt;br /&gt;
 Proportion Var  0.333  0.333  0.333&lt;br /&gt;
 Cumulative Var  0.333  0.667  1.000&lt;br /&gt;
&lt;br /&gt;
The '''bold''' and &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;red&amp;lt;/span&amp;gt; colored loadings, that is, the eigen vectors of the first principal component, ease of the comparison with the results derived from GRASS' ''m.eigensystem'' module above. Note the missing eigen value in row 3, column 3. For some reason R refused to yield it.&lt;br /&gt;
&lt;br /&gt;
=== Based on the correlation matrix ===&lt;br /&gt;
&lt;br /&gt;
==== Using '''''m.eigensystem'''''====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command in one line&lt;br /&gt;
&lt;br /&gt;
 (echo 3; r.covar -r spot.ms.1,spot.ms.2,spot.ms.3) | m.eigensystem&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 r.covar: complete ...&lt;br /&gt;
  100%&lt;br /&gt;
 E         2.5897901435          .0000000000    86.33&lt;br /&gt;
 V         -.7080795162          .0000000000&lt;br /&gt;
 V         -.6979341819          .0000000000&lt;br /&gt;
 V         -.6128387525          .0000000000&lt;br /&gt;
 N         -.6062688915          .0000000000&lt;br /&gt;
 N         -.5975822957          .0000000000&lt;br /&gt;
 N         -.5247222419          .0000000000&lt;br /&gt;
 W         -.9756579133          .0000000000&lt;br /&gt;
 W         -.9616787268          .0000000000&lt;br /&gt;
 W         -.8444263177          .0000000000&lt;br /&gt;
 E          .0123265666          .0000000000      .41&lt;br /&gt;
 V         -.6690685456          .0000000000&lt;br /&gt;
 V          .6302711261          .0000000000&lt;br /&gt;
 V          .0552608155          .0000000000&lt;br /&gt;
 N         -.7265842171          .0000000000&lt;br /&gt;
 N          .6844516242          .0000000000&lt;br /&gt;
 N          .0600112449          .0000000000&lt;br /&gt;
 W         -.0806690651          .0000000000&lt;br /&gt;
 W          .0759912909          .0000000000&lt;br /&gt;
 W          .0066627528          .0000000000&lt;br /&gt;
 E          .3978832898          .0000000000    13.26&lt;br /&gt;
 V          .3005969725          .0000000000&lt;br /&gt;
 V          .3883277727          .0000000000&lt;br /&gt;
 V         -.7895613377          .0000000000&lt;br /&gt;
 N          .3232853332          .0000000000&lt;br /&gt;
 N          .4176378502          .0000000000&lt;br /&gt;
 N         -.8491555920          .0000000000&lt;br /&gt;
 W          .2039218921          .0000000000&lt;br /&gt;
 W          .2634375639          .0000000000&lt;br /&gt;
 W         -.5356302845          .0000000000&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Using R's '''''princomp()''''' function ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Perform PCA&lt;br /&gt;
&lt;br /&gt;
 princomp(spot.ms.nonas, cor=TRUE)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Call:&lt;br /&gt;
 princomp(x = spot.ms.nonas, cor = TRUE)&lt;br /&gt;
 &lt;br /&gt;
 Standard deviations:&lt;br /&gt;
    Comp.1    Comp.2    Comp.3 &lt;br /&gt;
 1.6092826 0.6307795 0.1110256&lt;br /&gt;
 &lt;br /&gt;
 3  variables and  1231860 observations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Get loadings &lt;br /&gt;
&lt;br /&gt;
 princomp(spot.ms.nonas, cor=TRUE)$loadings&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Loadings:&lt;br /&gt;
           Comp.1 Comp.2 Comp.3&lt;br /&gt;
 spot.ms.1 -0.606 -0.323  0.727&lt;br /&gt;
 spot.ms.2 -0.598 -0.418 -0.684&lt;br /&gt;
 spot.ms.3 -0.525  0.849       &lt;br /&gt;
 &lt;br /&gt;
                Comp.1 Comp.2 Comp.3&lt;br /&gt;
 SS loadings     1.000  1.000  1.000&lt;br /&gt;
 Proportion Var  0.333  0.333  0.333&lt;br /&gt;
 Cumulative Var  0.333  0.667  1.000&lt;br /&gt;
&lt;br /&gt;
== SVD solution ==&lt;br /&gt;
&lt;br /&gt;
==== Using ''i.pca'' ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 i.pca input=spot.ms.1,spot.ms.2,spot.ms.3 out=pca.spot.ms rescale=0,0&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
  Eigen values, (vectors), and [percent importance]:&lt;br /&gt;
   PC1   '''1170.12''' (&amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.6251,-0.6536,-0.4268&amp;lt;/span&amp;gt;)[88.07%]&lt;br /&gt;
   PC2    152.49 ( 0.2328, 0.3658,-0.9011)[11.48%]&lt;br /&gt;
   PC3      6.01 ( 0.7450,-0.6626,-0.0765) [0.45%]&lt;br /&gt;
&lt;br /&gt;
==== Using R's ''prcomp()'' function ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following example replicates ''i.pca'''s solution using the same data '''with data centering and without scaling''' (options ''center=TRUE'' and ''scale=FALSE''). Note that these settings are the defaults.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 prcomp(spot.ms.nonas)&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Standard deviations:&lt;br /&gt;
 [1] 34.055032 12.103851  2.443469&lt;br /&gt;
 &lt;br /&gt;
 Rotation:&lt;br /&gt;
                  PC1        PC2         PC3&lt;br /&gt;
 spot.ms.1 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.6236808&amp;lt;/span&amp;gt;  0.2402770 -0.74383409&lt;br /&gt;
 spot.ms.2 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.6503302&amp;lt;/span&amp;gt;  0.3684685  0.66430538&lt;br /&gt;
 spot.ms.3 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.4336968&amp;lt;/span&amp;gt; -0.8980523  0.07354738&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Comments]]&lt;br /&gt;
&lt;br /&gt;
In this example ''i.pca'''s performance seems to be identical to R's ''prcomp()'' function which means that data centering is applied prior to the actual PCA.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The three SPOT bands used in this example have the following ranges:&lt;br /&gt;
&lt;br /&gt;
*spot.ms.1&lt;br /&gt;
&lt;br /&gt;
 min=24&lt;br /&gt;
 max=254&lt;br /&gt;
&lt;br /&gt;
*spot.ms.2&lt;br /&gt;
&lt;br /&gt;
 min=14&lt;br /&gt;
 max=254&lt;br /&gt;
*spot.ms.3&lt;br /&gt;
&lt;br /&gt;
 min=12&lt;br /&gt;
 max=254&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Nevertheless, as shown in the examples using MODIS surface reflectance products (read below) in which the range of the bands varies significantly, ''i.pca'''s results do not match the results of R's ''prcomp()'' function with the parameter ''center'' set to ''TRUE''. Instead, the results derived from ''i.pca'' are almost identical when the parameter ''center'' is set to ''FALSE''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following example performs PCA '''without data centering and scaling''' (options ''center=FALSE'' and ''scale=FALSE'').&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 prcomp(spot.ms.nonas, center=FALSE, scale=FALSE)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Standard deviations:&lt;br /&gt;
 [1] '''101.00927'''  15.79861   2.83775&lt;br /&gt;
 &lt;br /&gt;
 Rotation:&lt;br /&gt;
                  PC1        PC2        PC3&lt;br /&gt;
 spot.ms.1 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.5605487&amp;lt;/span&amp;gt; -0.3652694  0.7432116&lt;br /&gt;
 spot.ms.2 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.4726613&amp;lt;/span&amp;gt; -0.5958032 -0.6493149&lt;br /&gt;
 spot.ms.3 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.6799827&amp;lt;/span&amp;gt;  0.7152600 -0.1613280&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Comments]]&lt;br /&gt;
&lt;br /&gt;
+++&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following example performs PCA '''with data centering and scaling''' (options ''center=TRUE'' and ''scale=TRUE'')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 prcomp(spot.ms.nonas, center=TRUE, scale=TRUE)&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Standard deviations:&lt;br /&gt;
 [1] 1.6092826 0.6307795 0.1110256&lt;br /&gt;
 &lt;br /&gt;
 Rotation:&lt;br /&gt;
                  PC1        PC2         PC3&lt;br /&gt;
 spot.ms.1 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.6062688&amp;lt;/span&amp;gt;  0.3232856 -0.72658417&lt;br /&gt;
 spot.ms.2 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.5975823&amp;lt;/span&amp;gt;  0.4176378  0.68445170&lt;br /&gt;
 spot.ms.3 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.5247224&amp;lt;/span&amp;gt; -0.8491555  0.06001103&lt;br /&gt;
&lt;br /&gt;
= Examples using MODIS surface reflectance products =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Eigenvectors solution ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Based on the covariance matrix ===&lt;br /&gt;
&lt;br /&gt;
==== Using '''''m.eigensystem''''' ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command in one line&lt;br /&gt;
&lt;br /&gt;
 (echo 3; r.covar b02,b06,b07) | m.eigensystem&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E&amp;lt;/span&amp;gt; line is the eigen value. (Real part, imaginary part, percent importance)&lt;br /&gt;
* The &amp;lt;tt&amp;gt;V&amp;lt;/tt&amp;gt; lines are the eigen vectors associated with &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E&amp;lt;/span&amp;gt;.&lt;br /&gt;
* The &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N&amp;lt;/span&amp;gt; lines are the &amp;lt;tt&amp;gt;V&amp;lt;/tt&amp;gt; vectors normalized to have a magnitude of 1. '''These are the scaled eigen vectors that correspond to princomp()'s results presented in the following section.'''&lt;br /&gt;
* The &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W&amp;lt;/span&amp;gt; lines are the &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N&amp;lt;/span&amp;gt; vector multiplied by the square root of the magnitude of the eigen value (&amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E&amp;lt;/span&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
 r.covar: complete ...&lt;br /&gt;
 100%&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E    778244.0258462029          .0000000000    79.20&amp;lt;/span&amp;gt;&lt;br /&gt;
 V          .5006581842          .0000000000&lt;br /&gt;
 V          .8256483300          .0000000000&lt;br /&gt;
 V          .6155834548          .0000000000&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N          '''.4372107421'''          .0000000000&lt;br /&gt;
 N          '''.7210155161'''          .0000000000&lt;br /&gt;
 N          '''.5375717557'''          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W       385.6991853500          .0000000000&lt;br /&gt;
 W       636.0664787886          .0000000000&lt;br /&gt;
 W       474.2358050886          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E    192494.5769628266          .0000000000    19.59&amp;lt;/span&amp;gt;&lt;br /&gt;
 V         -.8689798010          .0000000000&lt;br /&gt;
 V          .0996340298          .0000000000&lt;br /&gt;
 V          .5731134848          .0000000000&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N         -.8309940700          .0000000000&lt;br /&gt;
 N          .0952787255          .0000000000&lt;br /&gt;
 N          .5480609638          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W      -364.5920328433          .0000000000&lt;br /&gt;
 W        41.8027823088          .0000000000&lt;br /&gt;
 W       240.4573848757          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E     11876.4548199713          .0000000000     1.21&amp;lt;/span&amp;gt;&lt;br /&gt;
 V          .2872248982          .0000000000&lt;br /&gt;
 V         -.5731591248          .0000000000&lt;br /&gt;
 V          .5351449518          .0000000000&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N          .3439413070          .0000000000&lt;br /&gt;
 N         -.6863370819          .0000000000&lt;br /&gt;
 N          .6408165005          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W        37.4824307850          .0000000000&lt;br /&gt;
 W       -74.7964308085          .0000000000&lt;br /&gt;
 W        69.8356366100          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In general, the solution to the eigen system results in complex&lt;br /&gt;
numbers (with both real and imaginary parts).  However, in the example&lt;br /&gt;
above, since the input matrix is symmetric (i.e., inverting the rows and columns&lt;br /&gt;
gives the same matrix) the eigen system has only real values (i.e., the&lt;br /&gt;
imaginary part is zero).&lt;br /&gt;
This fact makes it possible to use eigen vectors to perform principle component&lt;br /&gt;
transformation of data sets.  The covariance or correlation&lt;br /&gt;
matrix of any data set is symmetric&lt;br /&gt;
and thus has only real eigen values and vectors.&lt;br /&gt;
&lt;br /&gt;
'''Note''' The '''bold''' and &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;red&amp;lt;/span&amp;gt; colored eigen vectors of the first principal component, ease of the comparison with the results derived from R's ''princomp()'' function that follows.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Using the &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W&amp;lt;/span&amp;gt; vector, new maps can be created:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;B&amp;gt;r.mapcalc&amp;lt;/B&amp;gt; 'pc.1 =  &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;385.6992&amp;lt;/span&amp;gt;*map.1 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;+636.0665&amp;lt;/span&amp;gt;*map.2 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;+ 474.2358&amp;lt;/span&amp;gt;*map.3'&lt;br /&gt;
 &amp;lt;B&amp;gt;r.mapcalc&amp;lt;/B&amp;gt; 'pc.2 = &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;-364.5920&amp;lt;/span&amp;gt;*map.1 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;+ 41.8027&amp;lt;/span&amp;gt;*map.2 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;+ 240.4573&amp;lt;/span&amp;gt;*map.3'&lt;br /&gt;
 &amp;lt;B&amp;gt;r.mapcalc&amp;lt;/B&amp;gt; 'pc.3 =   &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;37.4824&amp;lt;/span&amp;gt;*map.1 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;- 74.7964&amp;lt;/span&amp;gt;*map.2 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;+  69.8356&amp;lt;/span&amp;gt;*map.3'&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Using R's '''''princomp()''''' function ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 princomp(modis)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Call:&lt;br /&gt;
 princomp(x = modis)&lt;br /&gt;
 Standard deviations:&lt;br /&gt;
   Comp.1   Comp.2   Comp.3&lt;br /&gt;
 857.5737 436.0922 108.5083&lt;br /&gt;
 3  variables and  350596 observations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Get loadings&lt;br /&gt;
&lt;br /&gt;
 (princomp(modis))$loadings&lt;br /&gt;
 Loadings:&lt;br /&gt;
     Comp.1 Comp.2 Comp.3&lt;br /&gt;
 b02 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.418'''&amp;lt;/span&amp;gt;  0.839  0.348&lt;br /&gt;
 b06 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.725'''&amp;lt;/span&amp;gt;        -0.684&lt;br /&gt;
 b07 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.547'''&amp;lt;/span&amp;gt; -0.539  0.641&lt;br /&gt;
&lt;br /&gt;
                Comp.1 Comp.2 Comp.3&lt;br /&gt;
 SS loadings     1.000  1.000  1.000&lt;br /&gt;
 Proportion Var  0.333  0.333  0.333&lt;br /&gt;
 Cumulative Var  0.333  0.667  1.000&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The '''bold''' and &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;red&amp;lt;/span&amp;gt; colored loadings, that is, the eigen vectors of the first principal component, ease of the comparison with the results derived from GRASS' ''m.eigensystem'' module above. Note the missing eigen value in row 2, column 2. For some reason R refused to yield it.&lt;br /&gt;
&lt;br /&gt;
=== Based on the correlation matrix ===&lt;br /&gt;
&lt;br /&gt;
==== Using '''''m.eigensystem'''''====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command in one line&lt;br /&gt;
&lt;br /&gt;
 (echo 3; r.covar -r MOD07_b02,MOD07_b06,MOD07_b07)|m.eigensystem&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 r.covar: complete ...&lt;br /&gt;
  100%&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E         2.2915877718          .0000000000    76.39&amp;lt;/span&amp;gt;&lt;br /&gt;
 V         -.5755655569          .0000000000&lt;br /&gt;
 V         -.7660355041          .0000000000&lt;br /&gt;
 V         -.6809380186          .0000000000&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N         -.4896413269          .0000000000&lt;br /&gt;
 N         -.6516766616          .0000000000&lt;br /&gt;
 N         -.5792830912          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W         -.7412186091          .0000000000&lt;br /&gt;
 W         -.9865075560          .0000000000&lt;br /&gt;
 W         -.8769182329          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E          .6740687010          .0000000000    22.47&amp;lt;/span&amp;gt;&lt;br /&gt;
 V          .8667178982          .0000000000&lt;br /&gt;
 V         -.1116525720          .0000000000&lt;br /&gt;
 V         -.6069908335          .0000000000&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N          '''.8145815825'''          .0000000000&lt;br /&gt;
 N         '''-.1049362531'''          .0000000000&lt;br /&gt;
 N         '''-.5704780699'''          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W          .6687852213          .0000000000&lt;br /&gt;
 W         -.0861544341          .0000000000&lt;br /&gt;
 W         -.4683721194          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E          .0343435272          .0000000000     1.14&amp;lt;/span&amp;gt;&lt;br /&gt;
 V          .2486404469          .0000000000&lt;br /&gt;
 V         -.6006166822          .0000000000&lt;br /&gt;
 V          .4655120098          .0000000000&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N          .3109794470          .0000000000&lt;br /&gt;
 N         -.7512029762          .0000000000&lt;br /&gt;
 N          .5822249325          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W          .0576307320          .0000000000&lt;br /&gt;
 W         -.1392129859          .0000000000&lt;br /&gt;
 W          .1078979635          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The '''bold''' and &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;red&amp;lt;/span&amp;gt; colored eigen vectors of the second principal component, ease of the comparison with the results derived from R's ''princomp()'' function that follows.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Using R's '''''princomp()''''' function ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 princomp(mod07, cor=TRUE)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Call:&lt;br /&gt;
 princomp(x = mod07, cor = TRUE)&lt;br /&gt;
&lt;br /&gt;
 Standard deviations:&lt;br /&gt;
    Comp.1    Comp.2    Comp.3&lt;br /&gt;
 1.5030740 0.8397807 0.1885121&lt;br /&gt;
 &lt;br /&gt;
  3  variables and  350596 observations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Get loadings&lt;br /&gt;
&lt;br /&gt;
 (princomp(mod07, cor=TRUE))$loadings&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Loadings:&lt;br /&gt;
                              Comp.1 Comp.2 Comp.3&lt;br /&gt;
 MOD2007_242_500_sur_refl_b02 -0.481  &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''0.820'''&amp;lt;/span&amp;gt;  0.310&lt;br /&gt;
 MOD2007_242_500_sur_refl_b06 -0.656 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.102'''&amp;lt;/span&amp;gt; -0.748&lt;br /&gt;
 MOD2007_242_500_sur_refl_b07 -0.582 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.563'''&amp;lt;/span&amp;gt;  0.587&lt;br /&gt;
 &lt;br /&gt;
                Comp.1 Comp.2 Comp.3&lt;br /&gt;
 SS loadings     1.000  1.000  1.000&lt;br /&gt;
 Proportion Var  0.333  0.333  0.333&lt;br /&gt;
 Cumulative Var  0.333  0.667  1.000&lt;br /&gt;
&lt;br /&gt;
The '''bold''' and &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;red&amp;lt;/span&amp;gt; colored loadings, that is, the eigen vectors of the second component, ease of the comparison with the results derived from GRASS' ''m.eigensystem'' module above.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Comments]]&lt;br /&gt;
'''Add comments here...'''&lt;br /&gt;
&lt;br /&gt;
== SVD solution ==&lt;br /&gt;
&lt;br /&gt;
==== Using ''i.pca'' ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 i.pca input=b2,b6,b7 output=pca.b267&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Eigen values, (vectors), and [percent importance]:&lt;br /&gt;
 PC1  '''6307563.04''' ( &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.64, -0.65, -0.42&amp;lt;/span&amp;gt; ) [ 98.71% ]&lt;br /&gt;
 PC2    78023.63 ( -0.71,  0.28,  0.64 ) [  1.22% ]&lt;br /&gt;
 PC3     4504.60 ( -0.30,  0.71, -0.64 ) [  0.07% ] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Using R's ''prcomp()'' function ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following example replicates ''i.pca'''s solution, that is, using the same data without data centering and/or scaling (options ''center=FALSE'' and ''scale=FALSE'').&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 prcomp(mod07, center=FALSE, scale=FALSE) &amp;lt;span style=&amp;quot;color:#006000&amp;quot;&amp;gt;&amp;lt;&amp;lt;== this corresponds to i.pca&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Standard deviations:&lt;br /&gt;
 [1] '''4288.3788'''  476.8904  114.3971&lt;br /&gt;
 Rotation:&lt;br /&gt;
                                    PC1        PC2        PC3&lt;br /&gt;
 MOD2007_242_500_sur_refl_b02 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.6353238&amp;lt;/span&amp;gt;  0.7124070 -0.2980602&lt;br /&gt;
 MOD2007_242_500_sur_refl_b06 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.6485551&amp;lt;/span&amp;gt; -0.2826985  0.7067234&lt;br /&gt;
 MOD2007_242_500_sur_refl_b07 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.4192135&amp;lt;/span&amp;gt; -0.6423066 -0.6416403&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Comments]]&lt;br /&gt;
&lt;br /&gt;
* The eigenvector matrices match although ''prcomp()'' reports loadings (=eigenvectors) column-wise and ''i.pca'' row-wise.&lt;br /&gt;
* The eigenvalues do '''not''' match. To exemplify, the standard deviation for PC1 reported by ''prcomp()'' is '''4288.3788''' and the variance reported by ''i.pca'' is 6307563.04 [ sqrt(6307563.04) = '''2511.486''' ]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''More examples to be added'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
Jon Shlens, &amp;quot;Tutorial on Principal Component Analysis, Dec 2005,&amp;quot; [http://www.snl.salk.edu/~shlens/pub/notes/pca.pdf] (accessed on March, 2009).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== e-mails in GRASS-user mailing list ==&lt;br /&gt;
&lt;br /&gt;
There are many posts concerning the functionality of ''i.pca''. Most of them are questioning the non-reporting of eigenvalues (an issue recently fixed).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Old posts'''&lt;br /&gt;
&lt;br /&gt;
[http://n2.nabble.com/i.pca-output-td1863271.html#a1863271]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Recent posts'''&lt;br /&gt;
&lt;br /&gt;
[http://n2.nabble.com/Testing-i.pca-~-prcomp()%2C-m.eigensystem-~-princomp()-td2413700.html#a2415727 Testing i.pca ~ prcomp(), m.eigensystem ~ princomp()]&lt;br /&gt;
&lt;br /&gt;
[http://n2.nabble.com/Calculating-eigen-values-and---variance-explained-after-PCA-analysis-td2383005.html#a2383165]&lt;br /&gt;
&lt;br /&gt;
[http://n2.nabble.com/Re%3A-Calculating-eigen-valuesand-varianceexplainedafter-PCA-analysis-td2413881.html#a2413881]&lt;br /&gt;
&lt;br /&gt;
[http://n2.nabble.com/Re%3A-Calculating-eigen-values-and--varianceexplainedafter-PCA-analysis-td2395558.html#a2409630]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''More sources to be added'''&lt;br /&gt;
&lt;br /&gt;
[[Category: Documentation]]&lt;/div&gt;</summary>
		<author><name>⚠️EdzerPebesma</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=Principal_Components_Analysis&amp;diff=8571</id>
		<title>Principal Components Analysis</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=Principal_Components_Analysis&amp;diff=8571"/>
		<updated>2009-03-31T13:35:48Z</updated>

		<summary type="html">&lt;p&gt;⚠️EdzerPebesma: /* Background */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Under Construction'''&lt;br /&gt;
&lt;br /&gt;
This page is a short and practical introduction in Principal Component Analysis. It aims to highlight the importance of the values returned by PCA. In addition, it addresses numerical accuracy issues with respect to the default implementation of PCA in GRASS through the ''i.pca'' module.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Principal Component Analysis =&lt;br /&gt;
&lt;br /&gt;
Principal Component Analysis (PCA) is a dimensionality reduction technique used extensively in Remote Sensing studies (e.g. in change detection studies, image enhancement tasks and more). PCA is in fact a linear transformation applied on (usually) highly correlated multidimensional (e.g. multispectral) data. The input dimensions are transformed in a new coordinate system in which the produced dimensions (called principal components) contain, in decreasing order, the greatest variance related with unchanged landscape features.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PCA has two algebraic solutions:&lt;br /&gt;
&lt;br /&gt;
* '''Eigenvectors of Covariance''' (or Correlation)&lt;br /&gt;
* '''Singular Value Decomposition'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The '''SVD''' method is used for numerical accuracy [R Documentation]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
The basic steps of the transformation are:&lt;br /&gt;
&lt;br /&gt;
# '''organizing a dataset in a matrix'''&lt;br /&gt;
# '''data centering''' (that is: subtracting the dimensions means from themself so each of the dimensions in the dataset has zero mean)&lt;br /&gt;
# calculate&lt;br /&gt;
#* the '''covariance matrix''' ('''non-standardised PCA''') or&lt;br /&gt;
#* the '''correlation matrix''' ('''standardised PCA''', also known as scaling)&lt;br /&gt;
# calculate either&lt;br /&gt;
#* the '''eigenvectors''' and '''eigenvalues''' of the covariance (or the correlation) matrix or&lt;br /&gt;
#* the '''SVD''' of the data matrix&lt;br /&gt;
# '''sort variances in decreasing order''' (decreasing eigenvalues; this is default in eigenvalue analysis)&lt;br /&gt;
# '''project original dataset ''signals''''' (PC's or PC scores: eigenvector * input-data) to get&lt;br /&gt;
&lt;br /&gt;
== Solutions to PCA ==&lt;br /&gt;
&lt;br /&gt;
The '''Eigenvector''' solution to PCA involves:&lt;br /&gt;
&lt;br /&gt;
# calculation of&lt;br /&gt;
#* the covariance matrix of the given multidimensional dataset (non-standardised PCA) '''''or'''''&lt;br /&gt;
#* the correlation matrix of the given multidimensional dataset (standardised PCA)&lt;br /&gt;
# calculation of the eigenvalues and eigenvectors of the covariance (or correlation) matrix&lt;br /&gt;
# transformation of the input dataset using the eigenvalues as weighting coefficients&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
&lt;br /&gt;
'''eigenvalues''' represent the variance of the original data contained in each principal component.&lt;br /&gt;
&lt;br /&gt;
'''eigenvectors''' act as weighting coefficients / represent the contribution of each original dimension the principal components.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Performing PCA with GRASS ==&lt;br /&gt;
&lt;br /&gt;
* '''''m.eigensystem'''''&lt;br /&gt;
&lt;br /&gt;
The ''m.eigensystem'' module implements the eigenvector solution to PCA. The respective function in R is ''princomp()''. A comparison of their results confirms their almost identical performance. Specifically,&lt;br /&gt;
&lt;br /&gt;
# the standard deviations (sdev) reported by ''princomp()'' are (almost) identical with the variances (eigenvalues) reported by ''m.eigensystem''.&lt;br /&gt;
&lt;br /&gt;
# ''princomp()'' scales (also referred as normalization) the eigenvectors and so does ''m.eigensystem''. The scaled(=normalised) eigenvectors produced by m.eigensystem are marked with the capital letter N.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''''i.pca'''''&lt;br /&gt;
&lt;br /&gt;
The ''i.pca'' module performs PCA based on the SVD solution without data centering and/or scaling. A comparison of the results derived by ''i.pca'' and R's ''prcomp()'' function confirms this. Specifically, ''i.pca'' yields the same eigenvectors as R's ''prcomp()'' function does with the following options:&lt;br /&gt;
&lt;br /&gt;
 prcomp(x, center=FALSE, scale=FALSE)&lt;br /&gt;
&lt;br /&gt;
where x is a numeric or complex matrix (or data frame) which provides the data for the principal components analysis (R Documentation).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Issues concerning the ''i.pca'' module ==&lt;br /&gt;
&lt;br /&gt;
??? To add... ???&lt;br /&gt;
&lt;br /&gt;
== Issues concerning R's ''princomp()'' function ==&lt;br /&gt;
&lt;br /&gt;
* For some reason one loading (=eigenvector) is missing from the output of the default application of princomp() on objects derived from GRASS as described above.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Examples using SPOT imagery =&lt;br /&gt;
Get the SPOT imagery from the Spearfish dataset: [http://grass.osgeo.org/sampledata/imagery60_grassdata.tar.gz SPOT images from the Spearfish dataset]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Eigenvectors solution ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Based on the covariance matrix ===&lt;br /&gt;
&lt;br /&gt;
==== Using '''''m.eigensystem''''' ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command in one line&lt;br /&gt;
&lt;br /&gt;
 (echo 3; r.covar spot.ms.1,spot.ms.2,spot.ms.3) | m.eigensystem&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
 r.covar: complete ...&lt;br /&gt;
  100%&lt;br /&gt;
 E      1159.7452017844          .0000000000    88.38&lt;br /&gt;
 V          .6910021591          .0000000000&lt;br /&gt;
 V          .7205280412          .0000000000&lt;br /&gt;
 V          .4805108400          .0000000000&lt;br /&gt;
 N          .6236808478          .0000000000&lt;br /&gt;
 N          .6503301526          .0000000000&lt;br /&gt;
 N          .4336967751          .0000000000&lt;br /&gt;
 W        21.2394712045          .0000000000&lt;br /&gt;
 W        22.1470141296          .0000000000&lt;br /&gt;
 W        14.7695575384          .0000000000&lt;br /&gt;
 E         5.9705414972          .0000000000      .45&lt;br /&gt;
 V          .7119385973          .0000000000&lt;br /&gt;
 V         -.6358200627          .0000000000&lt;br /&gt;
 V         -.0703936743          .0000000000&lt;br /&gt;
 N          .7438340890          .0000000000&lt;br /&gt;
 N         -.6643053754          .0000000000&lt;br /&gt;
 N         -.0735473745          .0000000000&lt;br /&gt;
 W         1.8175356507          .0000000000&lt;br /&gt;
 W        -1.6232096923          .0000000000&lt;br /&gt;
 W         -.1797107407          .0000000000&lt;br /&gt;
 E       146.5031967184          .0000000000    11.16&lt;br /&gt;
 V          .2265837636          .0000000000&lt;br /&gt;
 V          .3474697082          .0000000000&lt;br /&gt;
 V         -.8468727535          .0000000000&lt;br /&gt;
 N          .2402770238          .0000000000&lt;br /&gt;
 N          .3684685345          .0000000000&lt;br /&gt;
 N         -.8980522763          .0000000000&lt;br /&gt;
 W         2.9082771721          .0000000000&lt;br /&gt;
 W         4.4598880523          .0000000000&lt;br /&gt;
 W       -10.8698904856          .0000000000&lt;br /&gt;
&lt;br /&gt;
==== Using R's '''''princomp()''''' function ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Launch R from within GRASS&lt;br /&gt;
 R&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Load spgrass6() and projection information in R&lt;br /&gt;
 library(spgrass6)&lt;br /&gt;
 G &amp;lt;- gmeta6()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Read spot.ms bands&lt;br /&gt;
 spot.ms &amp;lt;- readRAST6(c('spot.ms.1', 'spot.ms.2', 'spot.ms.3'))&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Work around NA's&lt;br /&gt;
 spot.ms.nas &amp;lt;- which(is.na(spot.ms@data$spot.ms.1) &amp;amp; is.na(spot.ms@data$spot.ms.2) &amp;amp; is.na(spot.ms@data$spot.ms.3))&lt;br /&gt;
 spot.ms.values &amp;lt;- which(!is.na(spot.ms@data$spot.ms.1) &amp;amp; !is.na(spot.ms@data$spot.ms.2) &amp;amp; !is.na(spot.ms@data$spot.ms.3))&lt;br /&gt;
 spot.ms.nonas &amp;lt;- spot.ms.values@data[spot.ms.values, ]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 princomp(spot.ms.nonas)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Call:&lt;br /&gt;
 princomp(x = modis)&lt;br /&gt;
 Standard deviations:&lt;br /&gt;
   Comp.1   Comp.2   Comp.3&lt;br /&gt;
 34.055018 12.103846  2.443468&lt;br /&gt;
 &lt;br /&gt;
 3  variables and  1231860 observations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Get loadings&lt;br /&gt;
&lt;br /&gt;
 princomp(spot.ms.nonas)$loadings&lt;br /&gt;
 Loadings:&lt;br /&gt;
     Comp.1 Comp.2 Comp.3&lt;br /&gt;
 spot.ms.1 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.624'''&amp;lt;/span&amp;gt;  0.240  0.744&lt;br /&gt;
 spot.ms.2 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.650'''&amp;lt;/span&amp;gt; -0.368 -0.664&lt;br /&gt;
 spot.ms.3 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.434'''&amp;lt;/span&amp;gt;  0.898 &lt;br /&gt;
 &lt;br /&gt;
                Comp.1 Comp.2 Comp.3&lt;br /&gt;
 SS loadings     1.000  1.000  1.000&lt;br /&gt;
 Proportion Var  0.333  0.333  0.333&lt;br /&gt;
 Cumulative Var  0.333  0.667  1.000&lt;br /&gt;
&lt;br /&gt;
The '''bold''' and &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;red&amp;lt;/span&amp;gt; colored loadings, that is, the eigen vectors of the first principal component, ease of the comparison with the results derived from GRASS' ''m.eigensystem'' module above. Note the missing eigen value in row 3, column 3. For some reason R refused to yield it.&lt;br /&gt;
&lt;br /&gt;
=== Based on the correlation matrix ===&lt;br /&gt;
&lt;br /&gt;
==== Using '''''m.eigensystem'''''====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command in one line&lt;br /&gt;
&lt;br /&gt;
 (echo 3; r.covar -r spot.ms.1,spot.ms.2,spot.ms.3) | m.eigensystem&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 r.covar: complete ...&lt;br /&gt;
  100%&lt;br /&gt;
 E         2.5897901435          .0000000000    86.33&lt;br /&gt;
 V         -.7080795162          .0000000000&lt;br /&gt;
 V         -.6979341819          .0000000000&lt;br /&gt;
 V         -.6128387525          .0000000000&lt;br /&gt;
 N         -.6062688915          .0000000000&lt;br /&gt;
 N         -.5975822957          .0000000000&lt;br /&gt;
 N         -.5247222419          .0000000000&lt;br /&gt;
 W         -.9756579133          .0000000000&lt;br /&gt;
 W         -.9616787268          .0000000000&lt;br /&gt;
 W         -.8444263177          .0000000000&lt;br /&gt;
 E          .0123265666          .0000000000      .41&lt;br /&gt;
 V         -.6690685456          .0000000000&lt;br /&gt;
 V          .6302711261          .0000000000&lt;br /&gt;
 V          .0552608155          .0000000000&lt;br /&gt;
 N         -.7265842171          .0000000000&lt;br /&gt;
 N          .6844516242          .0000000000&lt;br /&gt;
 N          .0600112449          .0000000000&lt;br /&gt;
 W         -.0806690651          .0000000000&lt;br /&gt;
 W          .0759912909          .0000000000&lt;br /&gt;
 W          .0066627528          .0000000000&lt;br /&gt;
 E          .3978832898          .0000000000    13.26&lt;br /&gt;
 V          .3005969725          .0000000000&lt;br /&gt;
 V          .3883277727          .0000000000&lt;br /&gt;
 V         -.7895613377          .0000000000&lt;br /&gt;
 N          .3232853332          .0000000000&lt;br /&gt;
 N          .4176378502          .0000000000&lt;br /&gt;
 N         -.8491555920          .0000000000&lt;br /&gt;
 W          .2039218921          .0000000000&lt;br /&gt;
 W          .2634375639          .0000000000&lt;br /&gt;
 W         -.5356302845          .0000000000&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Using R's '''''princomp()''''' function ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Perform PCA&lt;br /&gt;
&lt;br /&gt;
 princomp(spot.ms.nonas, cor=TRUE)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Call:&lt;br /&gt;
 princomp(x = spot.ms.nonas, cor = TRUE)&lt;br /&gt;
 &lt;br /&gt;
 Standard deviations:&lt;br /&gt;
    Comp.1    Comp.2    Comp.3 &lt;br /&gt;
 1.6092826 0.6307795 0.1110256&lt;br /&gt;
 &lt;br /&gt;
 3  variables and  1231860 observations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Get loadings &lt;br /&gt;
&lt;br /&gt;
 princomp(spot.ms.nonas, cor=TRUE)$loadings&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Loadings:&lt;br /&gt;
           Comp.1 Comp.2 Comp.3&lt;br /&gt;
 spot.ms.1 -0.606 -0.323  0.727&lt;br /&gt;
 spot.ms.2 -0.598 -0.418 -0.684&lt;br /&gt;
 spot.ms.3 -0.525  0.849       &lt;br /&gt;
 &lt;br /&gt;
                Comp.1 Comp.2 Comp.3&lt;br /&gt;
 SS loadings     1.000  1.000  1.000&lt;br /&gt;
 Proportion Var  0.333  0.333  0.333&lt;br /&gt;
 Cumulative Var  0.333  0.667  1.000&lt;br /&gt;
&lt;br /&gt;
== SVD solution ==&lt;br /&gt;
&lt;br /&gt;
==== Using ''i.pca'' ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 i.pca input=spot.ms.1,spot.ms.2,spot.ms.3 out=pca.spot.ms rescale=0,0&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
  Eigen values, (vectors), and [percent importance]:&lt;br /&gt;
   PC1   '''1170.12''' (&amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.6251,-0.6536,-0.4268&amp;lt;/span&amp;gt;)[88.07%]&lt;br /&gt;
   PC2    152.49 ( 0.2328, 0.3658,-0.9011)[11.48%]&lt;br /&gt;
   PC3      6.01 ( 0.7450,-0.6626,-0.0765) [0.45%]&lt;br /&gt;
&lt;br /&gt;
==== Using R's ''prcomp()'' function ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following example replicates ''i.pca'''s solution using the same data '''with data centering and without scaling''' (options ''center=TRUE'' and ''scale=FALSE''). Note that these settings are the defaults.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 prcomp(spot.ms.nonas)&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Standard deviations:&lt;br /&gt;
 [1] 34.055032 12.103851  2.443469&lt;br /&gt;
 &lt;br /&gt;
 Rotation:&lt;br /&gt;
                  PC1        PC2         PC3&lt;br /&gt;
 spot.ms.1 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.6236808&amp;lt;/span&amp;gt;  0.2402770 -0.74383409&lt;br /&gt;
 spot.ms.2 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.6503302&amp;lt;/span&amp;gt;  0.3684685  0.66430538&lt;br /&gt;
 spot.ms.3 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.4336968&amp;lt;/span&amp;gt; -0.8980523  0.07354738&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Comments]]&lt;br /&gt;
&lt;br /&gt;
In this example ''i.pca'''s performance seems to be identical to R's ''prcomp()'' function which means that data centering is applied prior to the actual PCA.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The three SPOT bands used in this example have the following ranges:&lt;br /&gt;
&lt;br /&gt;
*spot.ms.1&lt;br /&gt;
&lt;br /&gt;
 min=24&lt;br /&gt;
 max=254&lt;br /&gt;
&lt;br /&gt;
*spot.ms.2&lt;br /&gt;
&lt;br /&gt;
 min=14&lt;br /&gt;
 max=254&lt;br /&gt;
*spot.ms.3&lt;br /&gt;
&lt;br /&gt;
 min=12&lt;br /&gt;
 max=254&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Nevertheless, as shown in the examples using MODIS surface reflectance products (read below) in which the range of the bands varies significantly, ''i.pca'''s results do not match the results of R's ''prcomp()'' function with the parameter ''center'' set to ''TRUE''. Instead, the results derived from ''i.pca'' are almost identical when the parameter ''center'' is set to ''FALSE''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following example performs PCA '''without data centering and scaling''' (options ''center=FALSE'' and ''scale=FALSE'').&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 prcomp(spot.ms.nonas, center=FALSE, scale=FALSE)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Standard deviations:&lt;br /&gt;
 [1] '''101.00927'''  15.79861   2.83775&lt;br /&gt;
 &lt;br /&gt;
 Rotation:&lt;br /&gt;
                  PC1        PC2        PC3&lt;br /&gt;
 spot.ms.1 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.5605487&amp;lt;/span&amp;gt; -0.3652694  0.7432116&lt;br /&gt;
 spot.ms.2 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.4726613&amp;lt;/span&amp;gt; -0.5958032 -0.6493149&lt;br /&gt;
 spot.ms.3 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.6799827&amp;lt;/span&amp;gt;  0.7152600 -0.1613280&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Comments]]&lt;br /&gt;
&lt;br /&gt;
+++&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following example performs PCA '''with data centering and scaling''' (options ''center=TRUE'' and ''scale=TRUE'')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 prcomp(spot.ms.nonas, center=TRUE, scale=TRUE)&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Standard deviations:&lt;br /&gt;
 [1] 1.6092826 0.6307795 0.1110256&lt;br /&gt;
 &lt;br /&gt;
 Rotation:&lt;br /&gt;
                  PC1        PC2         PC3&lt;br /&gt;
 spot.ms.1 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.6062688&amp;lt;/span&amp;gt;  0.3232856 -0.72658417&lt;br /&gt;
 spot.ms.2 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.5975823&amp;lt;/span&amp;gt;  0.4176378  0.68445170&lt;br /&gt;
 spot.ms.3 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.5247224&amp;lt;/span&amp;gt; -0.8491555  0.06001103&lt;br /&gt;
&lt;br /&gt;
= Examples using MODIS surface reflectance products =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Eigenvectors solution ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Based on the covariance matrix ===&lt;br /&gt;
&lt;br /&gt;
==== Using '''''m.eigensystem''''' ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command in one line&lt;br /&gt;
&lt;br /&gt;
 (echo 3; r.covar b02,b06,b07) | m.eigensystem&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E&amp;lt;/span&amp;gt; line is the eigen value. (Real part, imaginary part, percent importance)&lt;br /&gt;
* The &amp;lt;tt&amp;gt;V&amp;lt;/tt&amp;gt; lines are the eigen vectors associated with &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E&amp;lt;/span&amp;gt;.&lt;br /&gt;
* The &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N&amp;lt;/span&amp;gt; lines are the &amp;lt;tt&amp;gt;V&amp;lt;/tt&amp;gt; vectors normalized to have a magnitude of 1. '''These are the scaled eigen vectors that correspond to princomp()'s results presented in the following section.'''&lt;br /&gt;
* The &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W&amp;lt;/span&amp;gt; lines are the &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N&amp;lt;/span&amp;gt; vector multiplied by the square root of the magnitude of the eigen value (&amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E&amp;lt;/span&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
 r.covar: complete ...&lt;br /&gt;
 100%&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E    778244.0258462029          .0000000000    79.20&amp;lt;/span&amp;gt;&lt;br /&gt;
 V          .5006581842          .0000000000&lt;br /&gt;
 V          .8256483300          .0000000000&lt;br /&gt;
 V          .6155834548          .0000000000&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N          '''.4372107421'''          .0000000000&lt;br /&gt;
 N          '''.7210155161'''          .0000000000&lt;br /&gt;
 N          '''.5375717557'''          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W       385.6991853500          .0000000000&lt;br /&gt;
 W       636.0664787886          .0000000000&lt;br /&gt;
 W       474.2358050886          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E    192494.5769628266          .0000000000    19.59&amp;lt;/span&amp;gt;&lt;br /&gt;
 V         -.8689798010          .0000000000&lt;br /&gt;
 V          .0996340298          .0000000000&lt;br /&gt;
 V          .5731134848          .0000000000&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N         -.8309940700          .0000000000&lt;br /&gt;
 N          .0952787255          .0000000000&lt;br /&gt;
 N          .5480609638          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W      -364.5920328433          .0000000000&lt;br /&gt;
 W        41.8027823088          .0000000000&lt;br /&gt;
 W       240.4573848757          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E     11876.4548199713          .0000000000     1.21&amp;lt;/span&amp;gt;&lt;br /&gt;
 V          .2872248982          .0000000000&lt;br /&gt;
 V         -.5731591248          .0000000000&lt;br /&gt;
 V          .5351449518          .0000000000&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N          .3439413070          .0000000000&lt;br /&gt;
 N         -.6863370819          .0000000000&lt;br /&gt;
 N          .6408165005          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W        37.4824307850          .0000000000&lt;br /&gt;
 W       -74.7964308085          .0000000000&lt;br /&gt;
 W        69.8356366100          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In general, the solution to the eigen system results in complex&lt;br /&gt;
numbers (with both real and imaginary parts).  However, in the example&lt;br /&gt;
above, since the input matrix is symmetric (i.e., inverting the rows and columns&lt;br /&gt;
gives the same matrix) the eigen system has only real values (i.e., the&lt;br /&gt;
imaginary part is zero).&lt;br /&gt;
This fact makes it possible to use eigen vectors to perform principle component&lt;br /&gt;
transformation of data sets.  The covariance or correlation&lt;br /&gt;
matrix of any data set is symmetric&lt;br /&gt;
and thus has only real eigen values and vectors.&lt;br /&gt;
&lt;br /&gt;
'''Note''' The '''bold''' and &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;red&amp;lt;/span&amp;gt; colored eigen vectors of the first principal component, ease of the comparison with the results derived from R's ''princomp()'' function that follows.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Using the &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W&amp;lt;/span&amp;gt; vector, new maps can be created:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;B&amp;gt;r.mapcalc&amp;lt;/B&amp;gt; 'pc.1 =  &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;385.6992&amp;lt;/span&amp;gt;*map.1 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;+636.0665&amp;lt;/span&amp;gt;*map.2 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;+ 474.2358&amp;lt;/span&amp;gt;*map.3'&lt;br /&gt;
 &amp;lt;B&amp;gt;r.mapcalc&amp;lt;/B&amp;gt; 'pc.2 = &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;-364.5920&amp;lt;/span&amp;gt;*map.1 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;+ 41.8027&amp;lt;/span&amp;gt;*map.2 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;+ 240.4573&amp;lt;/span&amp;gt;*map.3'&lt;br /&gt;
 &amp;lt;B&amp;gt;r.mapcalc&amp;lt;/B&amp;gt; 'pc.3 =   &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;37.4824&amp;lt;/span&amp;gt;*map.1 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;- 74.7964&amp;lt;/span&amp;gt;*map.2 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;+  69.8356&amp;lt;/span&amp;gt;*map.3'&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Using R's '''''princomp()''''' function ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 princomp(modis)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Call:&lt;br /&gt;
 princomp(x = modis)&lt;br /&gt;
 Standard deviations:&lt;br /&gt;
   Comp.1   Comp.2   Comp.3&lt;br /&gt;
 857.5737 436.0922 108.5083&lt;br /&gt;
 3  variables and  350596 observations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Get loadings&lt;br /&gt;
&lt;br /&gt;
 (princomp(modis))$loadings&lt;br /&gt;
 Loadings:&lt;br /&gt;
     Comp.1 Comp.2 Comp.3&lt;br /&gt;
 b02 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.418'''&amp;lt;/span&amp;gt;  0.839  0.348&lt;br /&gt;
 b06 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.725'''&amp;lt;/span&amp;gt;        -0.684&lt;br /&gt;
 b07 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.547'''&amp;lt;/span&amp;gt; -0.539  0.641&lt;br /&gt;
&lt;br /&gt;
                Comp.1 Comp.2 Comp.3&lt;br /&gt;
 SS loadings     1.000  1.000  1.000&lt;br /&gt;
 Proportion Var  0.333  0.333  0.333&lt;br /&gt;
 Cumulative Var  0.333  0.667  1.000&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The '''bold''' and &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;red&amp;lt;/span&amp;gt; colored loadings, that is, the eigen vectors of the first principal component, ease of the comparison with the results derived from GRASS' ''m.eigensystem'' module above. Note the missing eigen value in row 2, column 2. For some reason R refused to yield it.&lt;br /&gt;
&lt;br /&gt;
=== Based on the correlation matrix ===&lt;br /&gt;
&lt;br /&gt;
==== Using '''''m.eigensystem'''''====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command in one line&lt;br /&gt;
&lt;br /&gt;
 (echo 3; r.covar -r MOD07_b02,MOD07_b06,MOD07_b07)|m.eigensystem&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 r.covar: complete ...&lt;br /&gt;
  100%&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E         2.2915877718          .0000000000    76.39&amp;lt;/span&amp;gt;&lt;br /&gt;
 V         -.5755655569          .0000000000&lt;br /&gt;
 V         -.7660355041          .0000000000&lt;br /&gt;
 V         -.6809380186          .0000000000&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N         -.4896413269          .0000000000&lt;br /&gt;
 N         -.6516766616          .0000000000&lt;br /&gt;
 N         -.5792830912          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W         -.7412186091          .0000000000&lt;br /&gt;
 W         -.9865075560          .0000000000&lt;br /&gt;
 W         -.8769182329          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E          .6740687010          .0000000000    22.47&amp;lt;/span&amp;gt;&lt;br /&gt;
 V          .8667178982          .0000000000&lt;br /&gt;
 V         -.1116525720          .0000000000&lt;br /&gt;
 V         -.6069908335          .0000000000&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N          '''.8145815825'''          .0000000000&lt;br /&gt;
 N         '''-.1049362531'''          .0000000000&lt;br /&gt;
 N         '''-.5704780699'''          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W          .6687852213          .0000000000&lt;br /&gt;
 W         -.0861544341          .0000000000&lt;br /&gt;
 W         -.4683721194          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E          .0343435272          .0000000000     1.14&amp;lt;/span&amp;gt;&lt;br /&gt;
 V          .2486404469          .0000000000&lt;br /&gt;
 V         -.6006166822          .0000000000&lt;br /&gt;
 V          .4655120098          .0000000000&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N          .3109794470          .0000000000&lt;br /&gt;
 N         -.7512029762          .0000000000&lt;br /&gt;
 N          .5822249325          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W          .0576307320          .0000000000&lt;br /&gt;
 W         -.1392129859          .0000000000&lt;br /&gt;
 W          .1078979635          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The '''bold''' and &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;red&amp;lt;/span&amp;gt; colored eigen vectors of the second principal component, ease of the comparison with the results derived from R's ''princomp()'' function that follows.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Using R's '''''princomp()''''' function ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 princomp(mod07, cor=TRUE)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Call:&lt;br /&gt;
 princomp(x = mod07, cor = TRUE)&lt;br /&gt;
&lt;br /&gt;
 Standard deviations:&lt;br /&gt;
    Comp.1    Comp.2    Comp.3&lt;br /&gt;
 1.5030740 0.8397807 0.1885121&lt;br /&gt;
 &lt;br /&gt;
  3  variables and  350596 observations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Get loadings&lt;br /&gt;
&lt;br /&gt;
 (princomp(mod07, cor=TRUE))$loadings&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Loadings:&lt;br /&gt;
                              Comp.1 Comp.2 Comp.3&lt;br /&gt;
 MOD2007_242_500_sur_refl_b02 -0.481  &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''0.820'''&amp;lt;/span&amp;gt;  0.310&lt;br /&gt;
 MOD2007_242_500_sur_refl_b06 -0.656 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.102'''&amp;lt;/span&amp;gt; -0.748&lt;br /&gt;
 MOD2007_242_500_sur_refl_b07 -0.582 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.563'''&amp;lt;/span&amp;gt;  0.587&lt;br /&gt;
 &lt;br /&gt;
                Comp.1 Comp.2 Comp.3&lt;br /&gt;
 SS loadings     1.000  1.000  1.000&lt;br /&gt;
 Proportion Var  0.333  0.333  0.333&lt;br /&gt;
 Cumulative Var  0.333  0.667  1.000&lt;br /&gt;
&lt;br /&gt;
The '''bold''' and &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;red&amp;lt;/span&amp;gt; colored loadings, that is, the eigen vectors of the second component, ease of the comparison with the results derived from GRASS' ''m.eigensystem'' module above.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Comments]]&lt;br /&gt;
'''Add comments here...'''&lt;br /&gt;
&lt;br /&gt;
== SVD solution ==&lt;br /&gt;
&lt;br /&gt;
==== Using ''i.pca'' ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 i.pca input=b2,b6,b7 output=pca.b267&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Eigen values, (vectors), and [percent importance]:&lt;br /&gt;
 PC1  '''6307563.04''' ( &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.64, -0.65, -0.42&amp;lt;/span&amp;gt; ) [ 98.71% ]&lt;br /&gt;
 PC2    78023.63 ( -0.71,  0.28,  0.64 ) [  1.22% ]&lt;br /&gt;
 PC3     4504.60 ( -0.30,  0.71, -0.64 ) [  0.07% ] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Using R's ''prcomp()'' function ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following example replicates ''i.pca'''s solution, that is, using the same data without data centering and/or scaling (options ''center=FALSE'' and ''scale=FALSE'').&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 prcomp(mod07, center=FALSE, scale=FALSE) &amp;lt;span style=&amp;quot;color:#006000&amp;quot;&amp;gt;&amp;lt;&amp;lt;== this corresponds to i.pca&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Standard deviations:&lt;br /&gt;
 [1] '''4288.3788'''  476.8904  114.3971&lt;br /&gt;
 Rotation:&lt;br /&gt;
                                    PC1        PC2        PC3&lt;br /&gt;
 MOD2007_242_500_sur_refl_b02 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.6353238&amp;lt;/span&amp;gt;  0.7124070 -0.2980602&lt;br /&gt;
 MOD2007_242_500_sur_refl_b06 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.6485551&amp;lt;/span&amp;gt; -0.2826985  0.7067234&lt;br /&gt;
 MOD2007_242_500_sur_refl_b07 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.4192135&amp;lt;/span&amp;gt; -0.6423066 -0.6416403&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Comments]]&lt;br /&gt;
&lt;br /&gt;
* The eigenvector matrices match although ''prcomp()'' reports loadings (=eigenvectors) column-wise and ''i.pca'' row-wise.&lt;br /&gt;
* The eigenvalues do '''not''' match. To exemplify, the standard deviation for PC1 reported by ''prcomp()'' is '''4288.3788''' and the variance reported by ''i.pca'' is 6307563.04 [ sqrt(6307563.04) = '''2511.486''' ]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''More examples to be added'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
Jon Shlens, &amp;quot;Tutorial on Principal Component Analysis, Dec 2005,&amp;quot; [http://www.snl.salk.edu/~shlens/pub/notes/pca.pdf] (accessed on March, 2009).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== e-mails in GRASS-user mailing list ==&lt;br /&gt;
&lt;br /&gt;
There are many posts concerning the functionality of ''i.pca''. Most of them are questioning the non-reporting of eigenvalues (an issue recently fixed).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Old posts'''&lt;br /&gt;
&lt;br /&gt;
[http://n2.nabble.com/i.pca-output-td1863271.html#a1863271]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Recent posts'''&lt;br /&gt;
&lt;br /&gt;
[http://n2.nabble.com/Testing-i.pca-~-prcomp()%2C-m.eigensystem-~-princomp()-td2413700.html#a2415727 Testing i.pca ~ prcomp(), m.eigensystem ~ princomp()]&lt;br /&gt;
&lt;br /&gt;
[http://n2.nabble.com/Calculating-eigen-values-and---variance-explained-after-PCA-analysis-td2383005.html#a2383165]&lt;br /&gt;
&lt;br /&gt;
[http://n2.nabble.com/Re%3A-Calculating-eigen-valuesand-varianceexplainedafter-PCA-analysis-td2413881.html#a2413881]&lt;br /&gt;
&lt;br /&gt;
[http://n2.nabble.com/Re%3A-Calculating-eigen-values-and--varianceexplainedafter-PCA-analysis-td2395558.html#a2409630]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''More sources to be added'''&lt;br /&gt;
&lt;br /&gt;
[[Category: Documentation]]&lt;/div&gt;</summary>
		<author><name>⚠️EdzerPebesma</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=Principal_Components_Analysis&amp;diff=8570</id>
		<title>Principal Components Analysis</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=Principal_Components_Analysis&amp;diff=8570"/>
		<updated>2009-03-31T13:28:34Z</updated>

		<summary type="html">&lt;p&gt;⚠️EdzerPebesma: /* Background */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Under Construction'''&lt;br /&gt;
&lt;br /&gt;
This page is a short and practical introduction in Principal Component Analysis. It aims to highlight the importance of the values returned by PCA. In addition, it addresses numerical accuracy issues with respect to the default implementation of PCA in GRASS through the ''i.pca'' module.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Principal Component Analysis =&lt;br /&gt;
&lt;br /&gt;
Principal Component Analysis (PCA) is a dimensionality reduction technique used extensively in Remote Sensing studies (e.g. in change detection studies, image enhancement tasks and more). PCA is in fact a linear transformation applied on (usually) highly correlated multidimensional (e.g. multispectral) data. The input dimensions are transformed in a new coordinate system in which the produced dimensions (called principal components) contain, in decreasing order, the greatest variance related with unchanged landscape features.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PCA has two algebraic solutions:&lt;br /&gt;
&lt;br /&gt;
* '''Eigenvectors of Covariance''' (or Correlation)&lt;br /&gt;
* '''Singular Value Decomposition'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The '''SVD''' method is used for numerical accuracy [R Documentation]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
The basic steps of the transformation are:&lt;br /&gt;
&lt;br /&gt;
# '''organizing a dataset in a matrix'''&lt;br /&gt;
# '''data centering''' (that is: subtracting the dimensions means from themself so each of the dimensions in the dataset has zero mean)&lt;br /&gt;
# calculate&lt;br /&gt;
#* the '''covariance matrix''' ('''non-standardised PCA''') or&lt;br /&gt;
#* the '''correlation matrix''' ('''standardised PCA''', also known as scaling)&lt;br /&gt;
# calculate&lt;br /&gt;
#* the '''eigenvectors''' and '''eigenvalues''' of the covariance (or the correlation) matrix or&lt;br /&gt;
#* the '''SVD''' of the data matrix&lt;br /&gt;
# '''sort variances in decreasing order''' (decreasing eigenvalues)&lt;br /&gt;
# '''project original dataset ''signals''''' (PC's = eigenvector * input-data)&lt;br /&gt;
&lt;br /&gt;
== Solutions to PCA ==&lt;br /&gt;
&lt;br /&gt;
The '''Eigenvector''' solution to PCA involves:&lt;br /&gt;
&lt;br /&gt;
# calculation of&lt;br /&gt;
#* the covariance matrix of the given multidimensional dataset (non-standardised PCA) '''''or'''''&lt;br /&gt;
#* the correlation matrix of the given multidimensional dataset (standardised PCA)&lt;br /&gt;
# calculation of the eigenvalues and eigenvectors of the covariance (or correlation) matrix&lt;br /&gt;
# transformation of the input dataset using the eigenvalues as weighting coefficients&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
&lt;br /&gt;
'''eigenvalues''' represent the variance of the original data contained in each principal component.&lt;br /&gt;
&lt;br /&gt;
'''eigenvectors''' act as weighting coefficients / represent the contribution of each original dimension the principal components.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Performing PCA with GRASS ==&lt;br /&gt;
&lt;br /&gt;
* '''''m.eigensystem'''''&lt;br /&gt;
&lt;br /&gt;
The ''m.eigensystem'' module implements the eigenvector solution to PCA. The respective function in R is ''princomp()''. A comparison of their results confirms their almost identical performance. Specifically,&lt;br /&gt;
&lt;br /&gt;
# the standard deviations (sdev) reported by ''princomp()'' are (almost) identical with the variances (eigenvalues) reported by ''m.eigensystem''.&lt;br /&gt;
&lt;br /&gt;
# ''princomp()'' scales (also referred as normalization) the eigenvectors and so does ''m.eigensystem''. The scaled(=normalised) eigenvectors produced by m.eigensystem are marked with the capital letter N.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''''i.pca'''''&lt;br /&gt;
&lt;br /&gt;
The ''i.pca'' module performs PCA based on the SVD solution without data centering and/or scaling. A comparison of the results derived by ''i.pca'' and R's ''prcomp()'' function confirms this. Specifically, ''i.pca'' yields the same eigenvectors as R's ''prcomp()'' function does with the following options:&lt;br /&gt;
&lt;br /&gt;
 prcomp(x, center=FALSE, scale=FALSE)&lt;br /&gt;
&lt;br /&gt;
where x is a numeric or complex matrix (or data frame) which provides the data for the principal components analysis (R Documentation).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Issues concerning the ''i.pca'' module ==&lt;br /&gt;
&lt;br /&gt;
??? To add... ???&lt;br /&gt;
&lt;br /&gt;
== Issues concerning R's ''princomp()'' function ==&lt;br /&gt;
&lt;br /&gt;
* For some reason one loading (=eigenvector) is missing from the output of the default application of princomp() on objects derived from GRASS as described above.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Examples using SPOT imagery =&lt;br /&gt;
Get the SPOT imagery from the Spearfish dataset: [http://grass.osgeo.org/sampledata/imagery60_grassdata.tar.gz SPOT images from the Spearfish dataset]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Eigenvectors solution ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Based on the covariance matrix ===&lt;br /&gt;
&lt;br /&gt;
==== Using '''''m.eigensystem''''' ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command in one line&lt;br /&gt;
&lt;br /&gt;
 (echo 3; r.covar spot.ms.1,spot.ms.2,spot.ms.3) | m.eigensystem&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
 r.covar: complete ...&lt;br /&gt;
  100%&lt;br /&gt;
 E      1159.7452017844          .0000000000    88.38&lt;br /&gt;
 V          .6910021591          .0000000000&lt;br /&gt;
 V          .7205280412          .0000000000&lt;br /&gt;
 V          .4805108400          .0000000000&lt;br /&gt;
 N          .6236808478          .0000000000&lt;br /&gt;
 N          .6503301526          .0000000000&lt;br /&gt;
 N          .4336967751          .0000000000&lt;br /&gt;
 W        21.2394712045          .0000000000&lt;br /&gt;
 W        22.1470141296          .0000000000&lt;br /&gt;
 W        14.7695575384          .0000000000&lt;br /&gt;
 E         5.9705414972          .0000000000      .45&lt;br /&gt;
 V          .7119385973          .0000000000&lt;br /&gt;
 V         -.6358200627          .0000000000&lt;br /&gt;
 V         -.0703936743          .0000000000&lt;br /&gt;
 N          .7438340890          .0000000000&lt;br /&gt;
 N         -.6643053754          .0000000000&lt;br /&gt;
 N         -.0735473745          .0000000000&lt;br /&gt;
 W         1.8175356507          .0000000000&lt;br /&gt;
 W        -1.6232096923          .0000000000&lt;br /&gt;
 W         -.1797107407          .0000000000&lt;br /&gt;
 E       146.5031967184          .0000000000    11.16&lt;br /&gt;
 V          .2265837636          .0000000000&lt;br /&gt;
 V          .3474697082          .0000000000&lt;br /&gt;
 V         -.8468727535          .0000000000&lt;br /&gt;
 N          .2402770238          .0000000000&lt;br /&gt;
 N          .3684685345          .0000000000&lt;br /&gt;
 N         -.8980522763          .0000000000&lt;br /&gt;
 W         2.9082771721          .0000000000&lt;br /&gt;
 W         4.4598880523          .0000000000&lt;br /&gt;
 W       -10.8698904856          .0000000000&lt;br /&gt;
&lt;br /&gt;
==== Using R's '''''princomp()''''' function ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Launch R from within GRASS&lt;br /&gt;
 R&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Load spgrass6() and projection information in R&lt;br /&gt;
 library(spgrass6)&lt;br /&gt;
 G &amp;lt;- gmeta6()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Read spot.ms bands&lt;br /&gt;
 spot.ms &amp;lt;- readRAST6(c('spot.ms.1', 'spot.ms.2', 'spot.ms.3'))&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Work around NA's&lt;br /&gt;
 spot.ms.nas &amp;lt;- which(is.na(spot.ms@data$spot.ms.1) &amp;amp; is.na(spot.ms@data$spot.ms.2) &amp;amp; is.na(spot.ms@data$spot.ms.3))&lt;br /&gt;
 spot.ms.values &amp;lt;- which(!is.na(spot.ms@data$spot.ms.1) &amp;amp; !is.na(spot.ms@data$spot.ms.2) &amp;amp; !is.na(spot.ms@data$spot.ms.3))&lt;br /&gt;
 spot.ms.nonas &amp;lt;- spot.ms.values@data[spot.ms.values, ]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 princomp(spot.ms.nonas)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Call:&lt;br /&gt;
 princomp(x = modis)&lt;br /&gt;
 Standard deviations:&lt;br /&gt;
   Comp.1   Comp.2   Comp.3&lt;br /&gt;
 34.055018 12.103846  2.443468&lt;br /&gt;
 &lt;br /&gt;
 3  variables and  1231860 observations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Get loadings&lt;br /&gt;
&lt;br /&gt;
 princomp(spot.ms.nonas)$loadings&lt;br /&gt;
 Loadings:&lt;br /&gt;
     Comp.1 Comp.2 Comp.3&lt;br /&gt;
 spot.ms.1 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.624'''&amp;lt;/span&amp;gt;  0.240  0.744&lt;br /&gt;
 spot.ms.2 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.650'''&amp;lt;/span&amp;gt; -0.368 -0.664&lt;br /&gt;
 spot.ms.3 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.434'''&amp;lt;/span&amp;gt;  0.898 &lt;br /&gt;
 &lt;br /&gt;
                Comp.1 Comp.2 Comp.3&lt;br /&gt;
 SS loadings     1.000  1.000  1.000&lt;br /&gt;
 Proportion Var  0.333  0.333  0.333&lt;br /&gt;
 Cumulative Var  0.333  0.667  1.000&lt;br /&gt;
&lt;br /&gt;
The '''bold''' and &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;red&amp;lt;/span&amp;gt; colored loadings, that is, the eigen vectors of the first principal component, ease of the comparison with the results derived from GRASS' ''m.eigensystem'' module above. Note the missing eigen value in row 3, column 3. For some reason R refused to yield it.&lt;br /&gt;
&lt;br /&gt;
=== Based on the correlation matrix ===&lt;br /&gt;
&lt;br /&gt;
==== Using '''''m.eigensystem'''''====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command in one line&lt;br /&gt;
&lt;br /&gt;
 (echo 3; r.covar -r spot.ms.1,spot.ms.2,spot.ms.3) | m.eigensystem&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 r.covar: complete ...&lt;br /&gt;
  100%&lt;br /&gt;
 E         2.5897901435          .0000000000    86.33&lt;br /&gt;
 V         -.7080795162          .0000000000&lt;br /&gt;
 V         -.6979341819          .0000000000&lt;br /&gt;
 V         -.6128387525          .0000000000&lt;br /&gt;
 N         -.6062688915          .0000000000&lt;br /&gt;
 N         -.5975822957          .0000000000&lt;br /&gt;
 N         -.5247222419          .0000000000&lt;br /&gt;
 W         -.9756579133          .0000000000&lt;br /&gt;
 W         -.9616787268          .0000000000&lt;br /&gt;
 W         -.8444263177          .0000000000&lt;br /&gt;
 E          .0123265666          .0000000000      .41&lt;br /&gt;
 V         -.6690685456          .0000000000&lt;br /&gt;
 V          .6302711261          .0000000000&lt;br /&gt;
 V          .0552608155          .0000000000&lt;br /&gt;
 N         -.7265842171          .0000000000&lt;br /&gt;
 N          .6844516242          .0000000000&lt;br /&gt;
 N          .0600112449          .0000000000&lt;br /&gt;
 W         -.0806690651          .0000000000&lt;br /&gt;
 W          .0759912909          .0000000000&lt;br /&gt;
 W          .0066627528          .0000000000&lt;br /&gt;
 E          .3978832898          .0000000000    13.26&lt;br /&gt;
 V          .3005969725          .0000000000&lt;br /&gt;
 V          .3883277727          .0000000000&lt;br /&gt;
 V         -.7895613377          .0000000000&lt;br /&gt;
 N          .3232853332          .0000000000&lt;br /&gt;
 N          .4176378502          .0000000000&lt;br /&gt;
 N         -.8491555920          .0000000000&lt;br /&gt;
 W          .2039218921          .0000000000&lt;br /&gt;
 W          .2634375639          .0000000000&lt;br /&gt;
 W         -.5356302845          .0000000000&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Using R's '''''princomp()''''' function ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Perform PCA&lt;br /&gt;
&lt;br /&gt;
 princomp(spot.ms.nonas, cor=TRUE)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Call:&lt;br /&gt;
 princomp(x = spot.ms.nonas, cor = TRUE)&lt;br /&gt;
 &lt;br /&gt;
 Standard deviations:&lt;br /&gt;
    Comp.1    Comp.2    Comp.3 &lt;br /&gt;
 1.6092826 0.6307795 0.1110256&lt;br /&gt;
 &lt;br /&gt;
 3  variables and  1231860 observations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Get loadings &lt;br /&gt;
&lt;br /&gt;
 princomp(spot.ms.nonas, cor=TRUE)$loadings&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Loadings:&lt;br /&gt;
           Comp.1 Comp.2 Comp.3&lt;br /&gt;
 spot.ms.1 -0.606 -0.323  0.727&lt;br /&gt;
 spot.ms.2 -0.598 -0.418 -0.684&lt;br /&gt;
 spot.ms.3 -0.525  0.849       &lt;br /&gt;
 &lt;br /&gt;
                Comp.1 Comp.2 Comp.3&lt;br /&gt;
 SS loadings     1.000  1.000  1.000&lt;br /&gt;
 Proportion Var  0.333  0.333  0.333&lt;br /&gt;
 Cumulative Var  0.333  0.667  1.000&lt;br /&gt;
&lt;br /&gt;
== SVD solution ==&lt;br /&gt;
&lt;br /&gt;
==== Using ''i.pca'' ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 i.pca input=spot.ms.1,spot.ms.2,spot.ms.3 out=pca.spot.ms rescale=0,0&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
  Eigen values, (vectors), and [percent importance]:&lt;br /&gt;
   PC1   '''1170.12''' (&amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.6251,-0.6536,-0.4268&amp;lt;/span&amp;gt;)[88.07%]&lt;br /&gt;
   PC2    152.49 ( 0.2328, 0.3658,-0.9011)[11.48%]&lt;br /&gt;
   PC3      6.01 ( 0.7450,-0.6626,-0.0765) [0.45%]&lt;br /&gt;
&lt;br /&gt;
==== Using R's ''prcomp()'' function ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following example replicates ''i.pca'''s solution using the same data '''with data centering and without scaling''' (options ''center=TRUE'' and ''scale=FALSE''). Note that these settings are the defaults.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 prcomp(spot.ms.nonas)&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Standard deviations:&lt;br /&gt;
 [1] 34.055032 12.103851  2.443469&lt;br /&gt;
 &lt;br /&gt;
 Rotation:&lt;br /&gt;
                  PC1        PC2         PC3&lt;br /&gt;
 spot.ms.1 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.6236808&amp;lt;/span&amp;gt;  0.2402770 -0.74383409&lt;br /&gt;
 spot.ms.2 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.6503302&amp;lt;/span&amp;gt;  0.3684685  0.66430538&lt;br /&gt;
 spot.ms.3 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.4336968&amp;lt;/span&amp;gt; -0.8980523  0.07354738&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Comments]]&lt;br /&gt;
&lt;br /&gt;
In this example ''i.pca'''s performance seems to be identical to R's ''prcomp()'' function which means that data centering is applied prior to the actual PCA.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The three SPOT bands used in this example have the following ranges:&lt;br /&gt;
&lt;br /&gt;
*spot.ms.1&lt;br /&gt;
&lt;br /&gt;
 min=24&lt;br /&gt;
 max=254&lt;br /&gt;
&lt;br /&gt;
*spot.ms.2&lt;br /&gt;
&lt;br /&gt;
 min=14&lt;br /&gt;
 max=254&lt;br /&gt;
*spot.ms.3&lt;br /&gt;
&lt;br /&gt;
 min=12&lt;br /&gt;
 max=254&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Nevertheless, as shown in the examples using MODIS surface reflectance products (read below) in which the range of the bands varies significantly, ''i.pca'''s results do not match the results of R's ''prcomp()'' function with the parameter ''center'' set to ''TRUE''. Instead, the results derived from ''i.pca'' are almost identical when the parameter ''center'' is set to ''FALSE''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following example performs PCA '''without data centering and scaling''' (options ''center=FALSE'' and ''scale=FALSE'').&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 prcomp(spot.ms.nonas, center=FALSE, scale=FALSE)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Standard deviations:&lt;br /&gt;
 [1] '''101.00927'''  15.79861   2.83775&lt;br /&gt;
 &lt;br /&gt;
 Rotation:&lt;br /&gt;
                  PC1        PC2        PC3&lt;br /&gt;
 spot.ms.1 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.5605487&amp;lt;/span&amp;gt; -0.3652694  0.7432116&lt;br /&gt;
 spot.ms.2 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.4726613&amp;lt;/span&amp;gt; -0.5958032 -0.6493149&lt;br /&gt;
 spot.ms.3 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.6799827&amp;lt;/span&amp;gt;  0.7152600 -0.1613280&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Comments]]&lt;br /&gt;
&lt;br /&gt;
+++&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following example performs PCA '''with data centering and scaling''' (options ''center=TRUE'' and ''scale=TRUE'')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 prcomp(spot.ms.nonas, center=TRUE, scale=TRUE)&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Standard deviations:&lt;br /&gt;
 [1] 1.6092826 0.6307795 0.1110256&lt;br /&gt;
 &lt;br /&gt;
 Rotation:&lt;br /&gt;
                  PC1        PC2         PC3&lt;br /&gt;
 spot.ms.1 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.6062688&amp;lt;/span&amp;gt;  0.3232856 -0.72658417&lt;br /&gt;
 spot.ms.2 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.5975823&amp;lt;/span&amp;gt;  0.4176378  0.68445170&lt;br /&gt;
 spot.ms.3 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.5247224&amp;lt;/span&amp;gt; -0.8491555  0.06001103&lt;br /&gt;
&lt;br /&gt;
= Examples using MODIS surface reflectance products =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Eigenvectors solution ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Based on the covariance matrix ===&lt;br /&gt;
&lt;br /&gt;
==== Using '''''m.eigensystem''''' ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command in one line&lt;br /&gt;
&lt;br /&gt;
 (echo 3; r.covar b02,b06,b07) | m.eigensystem&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E&amp;lt;/span&amp;gt; line is the eigen value. (Real part, imaginary part, percent importance)&lt;br /&gt;
* The &amp;lt;tt&amp;gt;V&amp;lt;/tt&amp;gt; lines are the eigen vectors associated with &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E&amp;lt;/span&amp;gt;.&lt;br /&gt;
* The &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N&amp;lt;/span&amp;gt; lines are the &amp;lt;tt&amp;gt;V&amp;lt;/tt&amp;gt; vectors normalized to have a magnitude of 1. '''These are the scaled eigen vectors that correspond to princomp()'s results presented in the following section.'''&lt;br /&gt;
* The &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W&amp;lt;/span&amp;gt; lines are the &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N&amp;lt;/span&amp;gt; vector multiplied by the square root of the magnitude of the eigen value (&amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E&amp;lt;/span&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
 r.covar: complete ...&lt;br /&gt;
 100%&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E    778244.0258462029          .0000000000    79.20&amp;lt;/span&amp;gt;&lt;br /&gt;
 V          .5006581842          .0000000000&lt;br /&gt;
 V          .8256483300          .0000000000&lt;br /&gt;
 V          .6155834548          .0000000000&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N          '''.4372107421'''          .0000000000&lt;br /&gt;
 N          '''.7210155161'''          .0000000000&lt;br /&gt;
 N          '''.5375717557'''          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W       385.6991853500          .0000000000&lt;br /&gt;
 W       636.0664787886          .0000000000&lt;br /&gt;
 W       474.2358050886          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E    192494.5769628266          .0000000000    19.59&amp;lt;/span&amp;gt;&lt;br /&gt;
 V         -.8689798010          .0000000000&lt;br /&gt;
 V          .0996340298          .0000000000&lt;br /&gt;
 V          .5731134848          .0000000000&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N         -.8309940700          .0000000000&lt;br /&gt;
 N          .0952787255          .0000000000&lt;br /&gt;
 N          .5480609638          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W      -364.5920328433          .0000000000&lt;br /&gt;
 W        41.8027823088          .0000000000&lt;br /&gt;
 W       240.4573848757          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E     11876.4548199713          .0000000000     1.21&amp;lt;/span&amp;gt;&lt;br /&gt;
 V          .2872248982          .0000000000&lt;br /&gt;
 V         -.5731591248          .0000000000&lt;br /&gt;
 V          .5351449518          .0000000000&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N          .3439413070          .0000000000&lt;br /&gt;
 N         -.6863370819          .0000000000&lt;br /&gt;
 N          .6408165005          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W        37.4824307850          .0000000000&lt;br /&gt;
 W       -74.7964308085          .0000000000&lt;br /&gt;
 W        69.8356366100          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In general, the solution to the eigen system results in complex&lt;br /&gt;
numbers (with both real and imaginary parts).  However, in the example&lt;br /&gt;
above, since the input matrix is symmetric (i.e., inverting the rows and columns&lt;br /&gt;
gives the same matrix) the eigen system has only real values (i.e., the&lt;br /&gt;
imaginary part is zero).&lt;br /&gt;
This fact makes it possible to use eigen vectors to perform principle component&lt;br /&gt;
transformation of data sets.  The covariance or correlation&lt;br /&gt;
matrix of any data set is symmetric&lt;br /&gt;
and thus has only real eigen values and vectors.&lt;br /&gt;
&lt;br /&gt;
'''Note''' The '''bold''' and &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;red&amp;lt;/span&amp;gt; colored eigen vectors of the first principal component, ease of the comparison with the results derived from R's ''princomp()'' function that follows.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Using the &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W&amp;lt;/span&amp;gt; vector, new maps can be created:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;B&amp;gt;r.mapcalc&amp;lt;/B&amp;gt; 'pc.1 =  &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;385.6992&amp;lt;/span&amp;gt;*map.1 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;+636.0665&amp;lt;/span&amp;gt;*map.2 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;+ 474.2358&amp;lt;/span&amp;gt;*map.3'&lt;br /&gt;
 &amp;lt;B&amp;gt;r.mapcalc&amp;lt;/B&amp;gt; 'pc.2 = &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;-364.5920&amp;lt;/span&amp;gt;*map.1 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;+ 41.8027&amp;lt;/span&amp;gt;*map.2 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;+ 240.4573&amp;lt;/span&amp;gt;*map.3'&lt;br /&gt;
 &amp;lt;B&amp;gt;r.mapcalc&amp;lt;/B&amp;gt; 'pc.3 =   &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;37.4824&amp;lt;/span&amp;gt;*map.1 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;- 74.7964&amp;lt;/span&amp;gt;*map.2 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;+  69.8356&amp;lt;/span&amp;gt;*map.3'&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Using R's '''''princomp()''''' function ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 princomp(modis)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Call:&lt;br /&gt;
 princomp(x = modis)&lt;br /&gt;
 Standard deviations:&lt;br /&gt;
   Comp.1   Comp.2   Comp.3&lt;br /&gt;
 857.5737 436.0922 108.5083&lt;br /&gt;
 3  variables and  350596 observations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Get loadings&lt;br /&gt;
&lt;br /&gt;
 (princomp(modis))$loadings&lt;br /&gt;
 Loadings:&lt;br /&gt;
     Comp.1 Comp.2 Comp.3&lt;br /&gt;
 b02 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.418'''&amp;lt;/span&amp;gt;  0.839  0.348&lt;br /&gt;
 b06 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.725'''&amp;lt;/span&amp;gt;        -0.684&lt;br /&gt;
 b07 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.547'''&amp;lt;/span&amp;gt; -0.539  0.641&lt;br /&gt;
&lt;br /&gt;
                Comp.1 Comp.2 Comp.3&lt;br /&gt;
 SS loadings     1.000  1.000  1.000&lt;br /&gt;
 Proportion Var  0.333  0.333  0.333&lt;br /&gt;
 Cumulative Var  0.333  0.667  1.000&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The '''bold''' and &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;red&amp;lt;/span&amp;gt; colored loadings, that is, the eigen vectors of the first principal component, ease of the comparison with the results derived from GRASS' ''m.eigensystem'' module above. Note the missing eigen value in row 2, column 2. For some reason R refused to yield it.&lt;br /&gt;
&lt;br /&gt;
=== Based on the correlation matrix ===&lt;br /&gt;
&lt;br /&gt;
==== Using '''''m.eigensystem'''''====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command in one line&lt;br /&gt;
&lt;br /&gt;
 (echo 3; r.covar -r MOD07_b02,MOD07_b06,MOD07_b07)|m.eigensystem&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 r.covar: complete ...&lt;br /&gt;
  100%&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E         2.2915877718          .0000000000    76.39&amp;lt;/span&amp;gt;&lt;br /&gt;
 V         -.5755655569          .0000000000&lt;br /&gt;
 V         -.7660355041          .0000000000&lt;br /&gt;
 V         -.6809380186          .0000000000&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N         -.4896413269          .0000000000&lt;br /&gt;
 N         -.6516766616          .0000000000&lt;br /&gt;
 N         -.5792830912          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W         -.7412186091          .0000000000&lt;br /&gt;
 W         -.9865075560          .0000000000&lt;br /&gt;
 W         -.8769182329          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E          .6740687010          .0000000000    22.47&amp;lt;/span&amp;gt;&lt;br /&gt;
 V          .8667178982          .0000000000&lt;br /&gt;
 V         -.1116525720          .0000000000&lt;br /&gt;
 V         -.6069908335          .0000000000&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N          '''.8145815825'''          .0000000000&lt;br /&gt;
 N         '''-.1049362531'''          .0000000000&lt;br /&gt;
 N         '''-.5704780699'''          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W          .6687852213          .0000000000&lt;br /&gt;
 W         -.0861544341          .0000000000&lt;br /&gt;
 W         -.4683721194          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#009000&amp;quot;&amp;gt;E          .0343435272          .0000000000     1.14&amp;lt;/span&amp;gt;&lt;br /&gt;
 V          .2486404469          .0000000000&lt;br /&gt;
 V         -.6006166822          .0000000000&lt;br /&gt;
 V          .4655120098          .0000000000&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;N          .3109794470          .0000000000&lt;br /&gt;
 N         -.7512029762          .0000000000&lt;br /&gt;
 N          .5822249325          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#000090&amp;quot;&amp;gt;W          .0576307320          .0000000000&lt;br /&gt;
 W         -.1392129859          .0000000000&lt;br /&gt;
 W          .1078979635          .0000000000&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The '''bold''' and &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;red&amp;lt;/span&amp;gt; colored eigen vectors of the second principal component, ease of the comparison with the results derived from R's ''princomp()'' function that follows.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Using R's '''''princomp()''''' function ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 princomp(mod07, cor=TRUE)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Call:&lt;br /&gt;
 princomp(x = mod07, cor = TRUE)&lt;br /&gt;
&lt;br /&gt;
 Standard deviations:&lt;br /&gt;
    Comp.1    Comp.2    Comp.3&lt;br /&gt;
 1.5030740 0.8397807 0.1885121&lt;br /&gt;
 &lt;br /&gt;
  3  variables and  350596 observations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Get loadings&lt;br /&gt;
&lt;br /&gt;
 (princomp(mod07, cor=TRUE))$loadings&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Loadings:&lt;br /&gt;
                              Comp.1 Comp.2 Comp.3&lt;br /&gt;
 MOD2007_242_500_sur_refl_b02 -0.481  &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''0.820'''&amp;lt;/span&amp;gt;  0.310&lt;br /&gt;
 MOD2007_242_500_sur_refl_b06 -0.656 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.102'''&amp;lt;/span&amp;gt; -0.748&lt;br /&gt;
 MOD2007_242_500_sur_refl_b07 -0.582 &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;'''-0.563'''&amp;lt;/span&amp;gt;  0.587&lt;br /&gt;
 &lt;br /&gt;
                Comp.1 Comp.2 Comp.3&lt;br /&gt;
 SS loadings     1.000  1.000  1.000&lt;br /&gt;
 Proportion Var  0.333  0.333  0.333&lt;br /&gt;
 Cumulative Var  0.333  0.667  1.000&lt;br /&gt;
&lt;br /&gt;
The '''bold''' and &amp;lt;span style=&amp;quot;color:#900000&amp;quot;&amp;gt;red&amp;lt;/span&amp;gt; colored loadings, that is, the eigen vectors of the second component, ease of the comparison with the results derived from GRASS' ''m.eigensystem'' module above.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Comments]]&lt;br /&gt;
'''Add comments here...'''&lt;br /&gt;
&lt;br /&gt;
== SVD solution ==&lt;br /&gt;
&lt;br /&gt;
==== Using ''i.pca'' ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 i.pca input=b2,b6,b7 output=pca.b267&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Eigen values, (vectors), and [percent importance]:&lt;br /&gt;
 PC1  '''6307563.04''' ( &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.64, -0.65, -0.42&amp;lt;/span&amp;gt; ) [ 98.71% ]&lt;br /&gt;
 PC2    78023.63 ( -0.71,  0.28,  0.64 ) [  1.22% ]&lt;br /&gt;
 PC3     4504.60 ( -0.30,  0.71, -0.64 ) [  0.07% ] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Using R's ''prcomp()'' function ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following example replicates ''i.pca'''s solution, that is, using the same data without data centering and/or scaling (options ''center=FALSE'' and ''scale=FALSE'').&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Command&lt;br /&gt;
&lt;br /&gt;
 prcomp(mod07, center=FALSE, scale=FALSE) &amp;lt;span style=&amp;quot;color:#006000&amp;quot;&amp;gt;&amp;lt;&amp;lt;== this corresponds to i.pca&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Output&lt;br /&gt;
&lt;br /&gt;
 Standard deviations:&lt;br /&gt;
 [1] '''4288.3788'''  476.8904  114.3971&lt;br /&gt;
 Rotation:&lt;br /&gt;
                                    PC1        PC2        PC3&lt;br /&gt;
 MOD2007_242_500_sur_refl_b02 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.6353238&amp;lt;/span&amp;gt;  0.7124070 -0.2980602&lt;br /&gt;
 MOD2007_242_500_sur_refl_b06 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.6485551&amp;lt;/span&amp;gt; -0.2826985  0.7067234&lt;br /&gt;
 MOD2007_242_500_sur_refl_b07 &amp;lt;span style=&amp;quot;color:#900090&amp;quot;&amp;gt;-0.4192135&amp;lt;/span&amp;gt; -0.6423066 -0.6416403&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Comments]]&lt;br /&gt;
&lt;br /&gt;
* The eigenvector matrices match although ''prcomp()'' reports loadings (=eigenvectors) column-wise and ''i.pca'' row-wise.&lt;br /&gt;
* The eigenvalues do '''not''' match. To exemplify, the standard deviation for PC1 reported by ''prcomp()'' is '''4288.3788''' and the variance reported by ''i.pca'' is 6307563.04 [ sqrt(6307563.04) = '''2511.486''' ]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''More examples to be added'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
Jon Shlens, &amp;quot;Tutorial on Principal Component Analysis, Dec 2005,&amp;quot; [http://www.snl.salk.edu/~shlens/pub/notes/pca.pdf] (accessed on March, 2009).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== e-mails in GRASS-user mailing list ==&lt;br /&gt;
&lt;br /&gt;
There are many posts concerning the functionality of ''i.pca''. Most of them are questioning the non-reporting of eigenvalues (an issue recently fixed).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Old posts'''&lt;br /&gt;
&lt;br /&gt;
[http://n2.nabble.com/i.pca-output-td1863271.html#a1863271]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Recent posts'''&lt;br /&gt;
&lt;br /&gt;
[http://n2.nabble.com/Testing-i.pca-~-prcomp()%2C-m.eigensystem-~-princomp()-td2413700.html#a2415727 Testing i.pca ~ prcomp(), m.eigensystem ~ princomp()]&lt;br /&gt;
&lt;br /&gt;
[http://n2.nabble.com/Calculating-eigen-values-and---variance-explained-after-PCA-analysis-td2383005.html#a2383165]&lt;br /&gt;
&lt;br /&gt;
[http://n2.nabble.com/Re%3A-Calculating-eigen-valuesand-varianceexplainedafter-PCA-analysis-td2413881.html#a2413881]&lt;br /&gt;
&lt;br /&gt;
[http://n2.nabble.com/Re%3A-Calculating-eigen-values-and--varianceexplainedafter-PCA-analysis-td2395558.html#a2409630]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''More sources to be added'''&lt;br /&gt;
&lt;br /&gt;
[[Category: Documentation]]&lt;/div&gt;</summary>
		<author><name>⚠️EdzerPebesma</name></author>
	</entry>
</feed>