fragility of MASS::boxcox

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

fragility of MASS::boxcox

bbolker
   MASS::boxcox fails if (1) the data is a data frame called 'attr' (2)
user doesn't specify y=TRUE, qr=TRUE in the initial lm() fit.

   boxcox.lm() calls update(), which apparently finds the built-in
'attr' object instead of the data frame in the global environment.

   Is there anything to be done about this (other than the old "don't
use names for your objects that are the same as built-in R functions") ?

   cheers
    Ben Bolker


library(MASS)
m1 <- lm(height~age, data=Loblolly)
boxcox(m1)
attr <- Loblolly
m3 <- update(m1, data=attr, y=TRUE, qr=TRUE)  ## fine
m2 <- update(m1, data=attr)
boxcox(m2)

 > Error in model.frame.default(formula = height ~ age, data = attr,
drop.unused.levels = TRUE) :
   'data' must be a data.frame, environment, or list

Error in model.frame.default(formula = height ~ age, data = attr,
drop.unused.levels = TRUE) :
   'data' must be a data.frame, environment, or list
 > traceback()
12: stop("'data' must be a data.frame, environment, or list")
11: model.frame.default(formula = height ~ age, data = attr,
drop.unused.levels = TRUE)
10: stats::model.frame(formula = height ~ age, data = attr,
drop.unused.levels = TRUE)
9: eval(mf, parent.frame())
8: eval(mf, parent.frame())
7: lm(formula = height ~ age, data = attr, y = TRUE, qr = TRUE)
6: eval(call, parent.frame())
5: eval(call, parent.frame())
4: update.default(object, y = TRUE, qr = TRUE, ...)
3: update(object, y = TRUE, qr = TRUE, ...)
2: boxcox.lm(m2)
1: boxcox(m2)

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel