[Rd] Suggest patch for princomp.formula and prcomp.formula

Berwin A Turlach berwin at maths.uwa.edu.au
Mon Mar 27 11:39:50 CEST 2006


G'day Brian,

>>>>> "BDR" == Prof Brian Ripley <ripley at stats.ox.ac.uk> writes:

    BDR> The proposed fix regretably will not work, since one can do
    BDR> things like

    BDR> library(MASS)
    BDR> prcomp(~ dist + dist:climb, hills)
Yes, I had the impression that this would work with the current
version but dismissed it as unintentional. ;-)

I wouldn't expect anyone to specify interaction terms in a principal
components analysis, but perhaps there are valid reasons to do so.

Attached is a slightly modified patch which still allows the above
example but also the changes that I proposed.  On my machine, R-devel
with this patch passes "make check FORCE=FORCE" and produces the
following output:

      > library(DAAG)
      > res <- prcomp(~ . - case - site - Pop - sex, possum)
      > res <- princomp(~ . - case - site - Pop - sex, possum)
      > res <- prcomp(~ . - case - site - Pop, possum)
      Error in prcomp.formula(~. - case - site - Pop, possum) : 
      	PCA applies only to numerical variables
      > res <- princomp(~ . - case - site - Pop, possum)
      Error in princomp.formula(~. - case - site - Pop, possum) : 
      	PCA applies only to numerical variables
      > library(MASS)
      
      Attaching package: 'MASS'
      
      
      	The following object(s) are masked from package:DAAG :
      
      	 hills 
      
      > prcomp(~ dist + dist:climb, hills)
      Standard deviations:
      [1] 29655.128279     3.101566
      
      Rotation:
                          PC1          PC2
      dist       -0.000154139 -0.999999988
      dist:climb -0.999999988  0.000154139

Cheers,

        Berwin

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: R-patch
Url: https://stat.ethz.ch/pipermail/r-devel/attachments/20060327/07c910e4/attachment.pl 


More information about the R-devel mailing list