Skip to content

mva:princomp.default not set correctly (PR#3168)

3 messages · irwin@imcs.rutgers.edu, Brian Ripley, Peter Dalgaard

#
Full_Name: Andrew Irwin
Version: 1.7.0
OS: Win98
Submission from: (NULL) (165.230.175.97)



It is impossible to set both xlim and ylim in princomp or princomp.default.

For example
  data(USArrests)
  biplot(princomp(USArrests))
works fine, but
  biplot(princomp(USArrests), xlim=c(-0.4, 0.4), ylim=c(-0.5,0.4) )
does not do what I would expect -- the ylim gets ignored.

The offending bit of code from mva:princomp.default seems to be

    if (missing(xlim) && missing(ylim)) 
        xlim <- ylim <- rangx1 <- rangx2 <- range(rangx1, rangx2)
    else if (missing(xlim)) 
        xlim <- rangx1
    else ylim <- rangx2


This if .. else if .. else clause is not written the way I think it should be
written.  The else clause should only be executed if ylim is missing, but it
will be executed if xlim and ylim are both present.

Suggested rewrite:

    if (missing(xlim) && missing(ylim)) 
        xlim <- ylim <- rangx1 <- rangx2 <- range(rangx1, rangx2)
    else if (missing(xlim)) 
        xlim <- rangx1
    else if (missing(ylim))
        ylim <- rangx2

ifelse clause might be better, but less readable.

Cheers,

Andrew
#
This is not about princomp.default at all!  That snippet of code does not
appear there.

Please do check against the S-PLUS original of biplot.default: this is in
biplot.default.  I very much doubt if you understand the intentions
(not that I do either).
On Mon, 2 Jun 2003 irwin@imcs.rutgers.edu wrote:

            
Since when were your expectations the determinant of a bug?

  
    
#
Prof Brian Ripley <ripley@stats.ox.ac.uk> writes:
Sorry, Brian, but: Pot, kettle....
As far as I can see, this is not equivalent to S-PLUS's logic. For
that, the 3rd line should read

        if (!missing(ylim))

So in S-PLUS, xlim gets ignored if ylim is specified, whereas in R it
is vice versa. I suspect that neither case is desirable?