[R] formula parsing, using parts ...

Russell Senior seniorr at aracnet.com
Tue Oct 28 10:55:13 CET 2003


>>>>> "Uwe" == Uwe Ligges <ligges at statistik.uni-dortmund.de> writes:

Russell> I am writing a little abstraction for a series of tests.  For
Russell> example, I am running an anova and kruskal.test on a
Russell> one-factor model.  That isn't a particular problem, I have an
Russell> interface like: my.function <- function(model,data) {
Russell> print(deparse(substitute(data))) a <- anova(lm(formula,data))
Russell> print(a) if(a$"Pr(>F)"[1] < 0.05) { pairwise.t.test(???)  } b
Russell> <- kruskal.test(formula,data) print(b) if ...  } I want to
Russell> run each test, then depending on the resulting p-value, run
Russell> pairwise tests.  I am getting into trouble where I put the
Russell> ??? above.  The pairwise.t.test has a different interface,
Russell> that seems to want me to dismember the formula into
Russell> constituent parts to feed in.  The other alternative is to
Russell> give my.function the constituent parts and let it build the
Russell> model.  I haven't figured out how to do either one.  Can
Russell> someone give me some pointers?

Uwe> See ?formula and its "See Also" Section on how to do formula
Uwe> manipulation. There's also an example on how to construct a
Uwe> formula.

In order to use the 'as.formula(paste(response," ~ ",factor))'
approach, response and factor seem to need to be strings (at least
they seem to if response is "log(x)" or the like).  Whereas, for
pairwise.t.test they need to be names.  What is the proper way to do
that?

-- 
Russell Senior         ``I have nine fingers; you have ten.''
seniorr at aracnet.com




More information about the R-help mailing list