Dear list,
Given a linear mixed model (from lme4) I want to 1) first change the input
dataset and then 2) change the model formula. I want this to happen in a
function call;
Please see below. Options 1) and 2) below work whereas 3) fails with the
message
> foo()
Error in is.data.frame(data) : object 'beets2' not found
Question: What is it one must to in case 3) to have R look "inside" the
function to figure out what "beets2" is?
Best regards
Søren
________________
library(pbkrtest)
data(beets)
lgs <- lmer(sugpct~block+sow+harvest+(1|block:harvest), data=beets, REML=F)
foo <- function(){
## 1)
beets2 <- transform(beets, yy = sugpct * yield)
ma1 <- lmer(yy~block+sow+harvest+(1|block:harvest), data=beets2,
REML=F)
ma0 <- update(ma1, yy~.)
## 2)
cl <- getCall(lgs)
cl[["data"]] <- beets2
mb1 <- eval(cl)
mb0 <- update(mb1, yy~.)
mb0
## 3)
cl <- getCall(lgs)
cl[["data"]] <- as.name("beets2")
mc1 <- eval(cl)
mc0 <- update(mc1, yy~.)
mc0
}
foo()
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.