I'm just learning to use function pca in the statistics toolbox, when I tried the simple example below it returned an error but I can't find anything wrong?
pca_test_2=[1 1 1 1 1 ; 1.9 2.1 2 2 1.8]
I them multiple it by its transpose to get:
pca_test_2=pca_test_2*pca_test_2';
>> [coeff,score,latent]=pca(pca_test_2);
??? Undefined function or method 'pca' for input arguments of type 'double'.
I have looked but can't find anything that describes how to solve such an error?
The toolbox is definitely installed. When I use pcacov on a covariance matrix it works (for a different data set)?
Can someone please explain what I am doing wrong?
When I use the same data with svd with the same data set it also works?
[u s v]=svd(pca_test_2)
u =
-0.4537 -0.8912
-0.8912 0.4537
s =
24.2493 0
0 0.0107
v =
-0.4537 -0.8912
-0.8912 0.4537
As advised I ran it again using princomp() see below;
However when comparing the results to those from scd I'm still a little confused: why are "u" of "coeff" not the same? (They are clearly similar though).
Why is latent not equal to the diagonal of s? Clearly they are completely different (I'm assuming its a scaling thing but given that the second eigenvalue on latent is zero its hard to see what scaling could have been used?)
[u s v]=svd(pca_test_3)
u =
-0.4537 -0.8912
-0.8912 0.4537
s =
24.2493 0
0 0.0107
v =
-0.4537 -0.8912
-0.8912 0.4537
[coeff,score,latent]=princomp(pca_test_2)
coeff =
0.4525 0.8918
0.8918 -0.4525
score =
-5.3040 0
5.3040 0
latent =
56.2658
0
princompinstead ofpca