[Rd] Documentation of biplot for princomp

From: Ravi Varadhan <rvaradhan_at_jhmi.edu>
Date: Mon, 31 May 2010 12:35:32 -0400


Hi,  

I think that the documentation for the biplot function `biplot.princomp' is inconsistent with what it actually does. Here is what the documentation states:  

pc.biplot

If true, use what Gabriel (1971) refers to as a "principal component biplot", with lambda = 1 and observations scaled up by sqrt(n) and variables scaled down by sqrt(n). Then inner products between variables approximate covariances and distances between observations approximate Mahalanobis distance.  

Here is what the code looks like:  

> getAnywhere("biplot.princomp")

A single object matching 'biplot.princomp' was found

It was found in the following places

  registered S3 method for biplot from namespace stats

  namespace:stats

with value  

function (x, choices = 1L:2L, scale = 1, pc.biplot = FALSE, ...)

{

    if (length(choices) != 2)

        stop("length of choices must be 2")

    if (!length(scores <- x$scores))

        stop(gettextf("object '%s' has no scores", deparse(substitute(x))),

            domain = NA)

    lam <- x$sdev[choices]

    if (is.null(n <- x$n.obs))

        n <- 1

    lam <- lam * sqrt(n)

    if (scale < 0 || scale > 1)

        warning("'scale' is outside [0, 1]")

    if (scale != 0)

        lam <- lam^scale

    else lam <- 1

    if (pc.biplot)

        lam <- lam/sqrt(n)

    biplot.default(t(t(scores[, choices])/lam), t(t(x$loadings[,

        choices]) * lam), ...)

    invisible()

}  

  1. Let us consider the default options: scale = 1 and pc.biplot = FALSE. Now, lam = x$sdev * sqrt(n). Hence, the observations (scores) are scaled down by eigenvalue * sqrt(n) and variables (loadings) are scaled up by eigenvalue * sqrt(n).
  2. Now consider: scale = 1 and pc.biplot = TRUE. We have, lam = x$sdev . The observations are scaled down by eigenvalue and variables are scaled up by eigenvalue.

Thus, in either case the documentation does not seem to be consistent with the implementation. Am I missing something here?  

Thanks & Best,

Ravi.    



Ravi Varadhan, Ph.D.

Assistant Professor,

Center on Aging and Health,

Johns Hopkins University School of Medicine

(410)502-2619

rvaradhan_at_jhmi.edu

http://www.jhsph.edu/agingandhealth/People/Faculty_personal_pages/Varadhan.h tml    

        [[alternative HTML version deleted]]



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Mon 31 May 2010 - 16:38:58 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 01 Jun 2010 - 05:10:54 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive