On Wed, 26 Jul 2017, Allin Cottrell wrote:
On Wed, 26 Jul 2017, Sven Schreiber wrote:
> Hi,
> perhaps there's a bug in princomp in the case of reduced rank. See this
> illustration:
[...]
Not sure, I'll defer to Jack on that. But I note that R's
princomp() and
prcomp() both choke on these data ("must be finite").
I guess that your script is not using princomp() in the intended way: what
you're supplying the function is the _covariance_ matrix of the data, not
the _data_; if you actually had a dataset with 4 variables and 4
observations, and variable 1 is all zeros, then it would have zero
variance, so I guess that in any real-life cases it wouldn't be considered
in the first place. But if you insist in doing so, the first principal
component on the covariances can be returned ok, as
<hansl>
matrix A = { 0, 0, 0, 0; \
0.0000 , 2.2790, -1.5619, -1.6955; \
0.0000 , -1.5619 , 1.2914 , 1.6958 ; \
0.0000 , -1.6955 , 1.6958 , 2.6103 }
matrix v = {}
matrix S = mcov(A)
eval eigensym(S, &v)
print v
eval A * v[,4]
</hansl>
OTOH, in this case a correlation matrix cannot be meaningfully defined, so
it's only fair that princomp() should choke.
-------------------------------------------------------
Riccardo (Jack) Lucchetti
Dipartimento di Scienze Economiche e Sociali (DiSES)
Università Politecnica delle Marche
(formerly known as Università di Ancona)
r.lucchetti(a)univpm.it
http://www2.econ.univpm.it/servizi/hpp/lucchetti
-------------------------------------------------------