[Rd] improved pairs.formula?

From: Berwin A Turlach <berwin_at_maths.uwa.edu.au>
Date: Tue 29 Mar 2005 - 03:53:56 GMT

Dear all,

I would like to suggest changing the pairs.formula command such that a command like

        pairs(GNP ~ . - Year - GNP.deflator, longley)

would behave in a similar fashion as

        lm(GNP ~ . - Year - GNP.deflator, longley)

i.e., make a pairwise scatterplot of GNP and all other variables in the (longley) dataframe except for Year and GNP.deflator. The above command, with the current version of pairs.formula, produces a pairwise scatterplot of all variables in the (longley) dataframe.

After some tinkering around, I came up with the following replacement function of pairs.formula which seems to do the job:

    pairs.formula <-
    function (formula, data = NULL, ..., subset, na.action = stats::na.pass)     {

      m <- match.call(expand.dots = FALSE)
      if (is.matrix(eval(m$data, parent.frame()))) 
        m$data <- as.data.frame(data)
      m$... <- NULL
      m$na.action <- stats::na.pass
      m[[1]] <- as.name("model.frame")
      mf <- eval(m, parent.frame())
      mt <- attr(mf, "terms")
      tmp <- attr(mt, "factors")
      ind <- apply(tmp, 1, max)
      sv <- rownames(tmp)[ind>0]
      ind <- match(sv,
                   sapply(attr(mt, "variables"), deparse, width.cutoff=500)[-1])
      if( (tt <- attr(mt, "response")) != 0 ){
        ind <- c(tt, ind)
      pairs(mf[,ind], ...)


Would you please kindly consider replacing the current pairs.formula function (at the top of the file src/library/graphics/R/pairs.R) with the above function?

Best wishes,


R-devel@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Tue Mar 29 13:57:36 2005

This archive was generated by hypermail 2.1.8 : Mon 20 Feb 2006 - 03:21:02 GMT