[Rd] termplot fails for composite non-factor terms (PR#828)
john.maindonald@anu.edu.au
john.maindonald@anu.edu.au
Sat, 27 Jan 2001 01:57:38 +0100 (MET)
I am running R 1.2.1 under Windows 98SE.
termplot() currently fails when there are composite terms, thus:
> library(mass)
> data(hills)
> hills.lm <- lm(time ~ climb + poly(dist, 2), data = hills)
> termplot(hills.lm)
Hit <Return> to see next plot:
Error in eval(expr, envir, enclos) : Object "dist" not found
The call
> termplot(hills.lm,data=hills)
does run without generating an error message, i.e. there is a
problem with the default setting for the parameter 'data'.
However the x-axis for the term poly(dist,2) is then incorrectly
labelled as poly(dist,2), rather than dist
The label poly(dist,2) surely belongs as part of the y-axis label.
Here are suggested fixes
1. In the default parameters for the function call change
data = model.frame(model)
to
data = get(as.character(model$call$data))
[This does not work if the variable values are specified in the
function call. It is not clear to me how to fix that.]
2. A few lines from the beginning, replace
if (is.null(xlabs))
xlabs <- nmt
if (is.null(ylab))
ylab <- substitute(link(foo), list(foo = formula(model)[[2]]))
with
if (is.null(xlabs))
xlabs <- unlist(lapply(cn,function(x)
if(length(x)>1)as.character(x[[2]]) else as.character(x)))
if (is.null(ylab))
ylab <- paste("Partial for", nmt)
[The current y-label is "link(<yvar>)". If it is thought necessary
to specify this, it should be additional to e.g., in my example,
"Partial for poly(dist,2)"]
Replace ylab = ylab with
ylab = ylab[i]
in the two places (arguments to plot()) where it appears.
John Maindonald email : john.maindonald@anu.edu.au
Statistical Consulting Unit, phone : (6125)3998
c/o CMA, SMS, fax : (6125)5549
John Dedman Mathematical Sciences Building
Australian National University
Canberra ACT 0200
Australia
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._