[Rd] Enhanced version of plot.lm()

Martin Maechler maechler at stat.math.ethz.ch
Wed Apr 27 15:56:32 CEST 2005


>>>>> "MM" == Martin Maechler <maechler at stat.math.ethz.ch>
>>>>>     on Tue, 26 Apr 2005 12:13:38 +0200 writes:

>>>>> "JMd" == John Maindonald <john.maindonald at anu.edu.au>
>>>>>     on Tue, 26 Apr 2005 15:44:26 +1000 writes:

    JMd> The web page http://wwwmaths.anu.edu.au/~johnm/r/plot-lm/
    JMd> now includes files:
    JMd> plot.lm.RData: Image for file for plot6.lm, a version of plot.lm in 
    JMd> which
    JMd> David Firth's Cook's distance vs leverage/(1-leverage) plot is plot 6.
    JMd> The tick labels are in units of leverage, and the contour labels are
    JMd> in units of absolute values of the standardized residual.

    JMd> plot6.lm.Rd file: A matching help file

    JMd> Comments will be welcome.

    MM> Thank you John!

    MM> The *.Rd has the new references and a new example but
    MM> is not quite complete: the \usage{} has only 4 captions,
    MM> \arguments{ .. \item{which} ..}  only mentions '1:5' --- but
    MM> never mind.

    MM> One of the new examples is

    MM> ## Replace Cook's distance plot by Residual-Leverage plot
    MM> plot(lm.SR, which=c(1:3, 5))

    MM> and -- conceptually I'd really like to change the default from
    MM> 'which = 1:4' to the above
    MM> 'which=c(1:3, 5))' 

    MM> This would be non-compatible though for all those that have
    MM> always used the current default 1:4. 
    MM> OTOH, "MASS" or Peter Dalgaard's book don't mention  plot(<lm fit> )
    MM> or at least don't show it's result.

    MM> What do others think?
    MM> How problematic would a change be in the default plots that
    MM> plot.lm() produces?


    JMd> Another issue, discussed recently on r-help, is that when the model
    JMd> formula is long, the default sub.caption=deparse(x$call) is broken
    JMd> into multiple text elements and overwrites.  
    MM> good point!

    JMd> The only clean and simple way that I can see to handle
    JMd> is to set a default that tests whether the formula is
    JMd> broken into multiple text elements, and if it is then
    JMd> omit it.  Users can then use their own imaginative
    JMd> skills, and such suggestions as have been made on
    JMd> r-help, to construct whatever form of labeling best
    JMd> suits their case, their imaginative skills and their
    JMd> coding skills.

    MM> Hmm, yes, but I think we (R programmers) could try a bit harder
    MM> to provide a reasonable default, e.g., something along
 
    MM> cap <- deparse(x$call, width.cutoff = 500)[1]
    MM> if((nc <- nchar(cap)) > 53)	    
    MM>   cap <- paste(substr(cap, 1, 50), "....", substr(cap, nc-2, nc))

    MM> {untested;  some of the details will differ;
    MM> and the '53', '50' could depend on par("..") measures}

In the mean time, I came to quite a nice way of doing this:

    if(is.null(sub.caption)) { ## construct a default:
        cal <- x$call
        if (!is.na(m.f <- match("formula", names(cal)))) {
            cal <- cal[c(1, m.f)]
            names(cal)[2] <- "" # drop  " formula = "
        }
        cc <- deparse(cal, 80)
        nc <- nchar(cc[1])
        abbr <- length(cc) > 1 || nc > 75
        sub.caption <-
            if(abbr) paste(substr(cc[1], 1, min(75,nc)), "...") else cc[1]
    }


I'm about to commit the current proposal(s) to R-devel,
**INCLUDING** changing the default from 
	      'which = 1:4' to 'which = c(1:3,5)

and ellicit feedback starting from there.

One thing I think I would like is to use color for the Cook's
contours in the new 4th plot.

Martin


	<.............. lots deleted ..........>



More information about the R-devel mailing list