From groemping at bht-berlin.de  Tue Aug 25 17:13:59 2009
From: groemping at bht-berlin.de (Ulrike Groemping)
Date: Tue, 25 Aug 2009 08:13:59 -0700 (PDT)
Subject: [Rd]  Problem with correct usage of formula environment
Message-ID: <25136335.post@talk.nabble.com>


Dear all, 

I am working on a function formula.design that should automatically generate
reasonable lm formulae for a number of different designs. All works well as
long as all variables used are columns of the design data frame. For one
function, I would like to incorporate a dummy variable for center points
that is not a column of the design. Without this function, it would work
like this (at least version 0.97 of package FrF2):

require(FrF2)
plan <- FrF2(8,4,ncenter=6)
y <- rnorm(14)
r.plan<-add.response(plan,y)
lm(y~A+B+C+D+!iscube(r.plan), r.plan)

Building the formula from within function formula.design works OK at first
sight:
> formula(r.plan)
y ~ A + B + C + D + (!iscube(r.plan))

However, using the formula in a linear model call does not work in this
case: 
> lm(r.plan)
Fehler in inherits(x, "factor") : Objekt 'object' nicht gefunden
> traceback()
12: inherits(x, "factor")
11: is.factor(table)
10: match(x, table, nomatch = 0L)
9: "design" %in% class(design)
8: iscube(object)
7: eval(expr, envir, enclos)
6: eval(predvars, data, env)
5: model.frame.default(formula = r.plan, drop.unused.levels = TRUE)
4: model.frame(formula = r.plan, drop.unused.levels = TRUE)
3: eval(expr, envir, enclos)
2: eval(mf, parent.frame())
1: lm(r.plan)

9: of the traceback is the first line of function iscube, and it seems that
the object r.plan cannot be found here. I have no idea how to fix this. In
case it helps: The expression generating the formula in function
formula.design is

as.formula(paste(response, paste(c(names(factor.names),
paste("!iscube(",xnam,")",sep="")), collapse="+"),sep="~"))

I am grateful for any pointers that direct me to a fix for this problem
and/or to a better understanding of its root cause.

Thanks and regards,
Ulrike
-- 
View this message in context: http://www.nabble.com/Problem-with-correct-usage-of-formula-environment-tp25136335p25136335.html
Sent from the R devel mailing list archive at Nabble.com.



[Rd] Problem with correct usage of formula environment
Ulrike Groemping