Hi all,
I noticed some very odd behaviour in the termplot function of the
stats package due to the following lines :
18. if (is.null(data))
19. data <- eval(model$call$data, envir)
This one will look in the global environment, and renders the two
lines after this
20. if (is.null(data))
21. data <- mf
completely obsolete. If nothing is found, an error is returned. If
anything is found, data won't be NULL, so line 20, when reached, will
always return FALSE. Can it be that lines 18 and 19 should be removed
from the function?
This gives especially problems when called from other plot functions
on models made with wrapper functions. One example :
Data <- data.frame(
x1=rnorm(100),
x2=rnorm(100,3,2),
y=rnorm(100)
)
form <- as.formula(y~x1+x2)
test <- lm(form, data=Data)
termplot(test)
wrapper <- function(ff,x){
tt <- lm(ff,data=x)
}
test2 <- wrapper(form,Data)
termplot(test2)
For the non-smooth terms, termplot is called. In the first example,
this works perfectly well. In the second example, it either returns "x
not found" (when there is no x variable in the global) or "x2 not
found" when there is an x variable.
If both lines mentioned earlier are erased from the function, it works
as expected in this example code. Using the model frame seems the
logic choice here, I have no clue why one would want to look in the
global environment for the data related to a model.
Cheers
Joris
--
Joris Meys
Statistical consultant
Ghent University
Faculty of Bioscience Engineering
Department of Applied mathematics, biometrics and process control
tel : +32 9 264 59 87
Joris.Meys at Ugent.be
-------------------------------
Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php
peter dalgaard
2011-Jun-06 16:29 UTC
[Rd] Possible bug in termplot function (stats package) ?
On Jun 6, 2011, at 17:15 , Joris Meys wrote:> Hi all, > > I noticed some very odd behaviour in the termplot function of the > stats package due to the following lines : > > 18. if (is.null(data)) > 19. data <- eval(model$call$data, envir) > > This one will look in the global environment, and renders the two > lines after this > > 20. if (is.null(data)) > 21. data <- mf > > completely obsolete. If nothing is found, an error is returned. If > anything is found, data won't be NULL, so line 20, when reached, will > always return FALSE. Can it be that lines 18 and 19 should be removed > from the function?I think this is a false assumption. What keeps model$call$data from being NULL? No comments on the remainder, except that it wouldn't be the first time a wrapper function got into trouble with environments and modelling functions...> > This gives especially problems when called from other plot functions > on models made with wrapper functions. One example : > > Data <- data.frame( > x1=rnorm(100), > x2=rnorm(100,3,2), > y=rnorm(100) > ) > form <- as.formula(y~x1+x2) > test <- lm(form, data=Data) > termplot(test) > > wrapper <- function(ff,x){ > tt <- lm(ff,data=x) > } > test2 <- wrapper(form,Data) > termplot(test2) > > For the non-smooth terms, termplot is called. In the first example, > this works perfectly well. In the second example, it either returns "x > not found" (when there is no x variable in the global) or "x2 not > found" when there is an x variable. > > If both lines mentioned earlier are erased from the function, it works > as expected in this example code. Using the model frame seems the > logic choice here, I have no clue why one would want to look in the > global environment for the data related to a model. > > Cheers > Joris > > -- > Joris Meys > Statistical consultant > > Ghent University > Faculty of Bioscience Engineering > Department of Applied mathematics, biometrics and process control > > tel : +32 9 264 59 87 > Joris.Meys at Ugent.be > ------------------------------- > Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel-- Peter Dalgaard Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com
Possibly Parallel Threads
- stats::line() does not produce correct Tukey line when n mod 6 is 2 or 3
- Warning message when items of Hmisc are masked by loading a package.
- lag() not returning a time series object
- `[` not recognized as a primitive in certain cases.
- stats::line() does not produce correct Tukey line when n mod 6 is 2 or 3