From berwin at maths.uwa.edu.au  Mon Mar 27 11:39:50 2006
From: berwin at maths.uwa.edu.au (Berwin A Turlach)
Date: Mon, 27 Mar 2006 17:39:50 +0800
Subject: [Rd] Suggest patch for princomp.formula and prcomp.formula
In-Reply-To: <Pine.LNX.4.64.0603262108450.15505@gannet.stats.ox.ac.uk>
References: <17445.13216.869157.615441@bossiaea.maths.uwa.edu.au>
	<Pine.LNX.4.64.0603262108450.15505@gannet.stats.ox.ac.uk>
Message-ID: <17447.45798.736375.467072@bossiaea.maths.uwa.edu.au>

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 


[Rd] Suggest patch for princomp.formula and prcomp.formula
Berwin A Turlach