[R] proper work-flow with 'formula' objects and lm()

2011-11-24 Thread Liviu Andronic
Dear all I have a work-flow issue with lm(). When I use lm(y1~x1, anscombe) Call: lm(formula = y1 ~ x1, data = anscombe) Coefficients: (Intercept) x1 3.0001 0.5001 I get as expected the formula, y1 ~ x1, in the print()ed results or summary(). However, if I pass through a

Re: [R] proper work-flow with 'formula' objects and lm()

2011-11-24 Thread Duncan Murdoch
On 24/11/2011 2:48 PM, Liviu Andronic wrote: Dear all I have a work-flow issue with lm(). When I use lm(y1~x1, anscombe) Call: lm(formula = y1 ~ x1, data = anscombe) Coefficients: (Intercept) x1 3.0001 0.5001 I get as expected the formula, y1 ~ x1, in the print()ed

Re: [R] proper work-flow with 'formula' objects and lm()

2011-11-24 Thread Liviu Andronic
On Thu, Nov 24, 2011 at 9:14 PM, Duncan Murdoch murdoch.dun...@gmail.com wrote: It is retained.  terms(fit) will give it to you, if fit is an lm object. Thank you. The following works nicely. (form - formula(y1~x1)) y1 ~ x1 x - lm(form, anscombe) formula(terms(x)) y1 ~ x1 However, I was

Re: [R] proper work-flow with 'formula' objects and lm()

2011-11-24 Thread Prof Brian Ripley
On Thu, 24 Nov 2011, Liviu Andronic wrote: On Thu, Nov 24, 2011 at 9:14 PM, Duncan Murdoch murdoch.dun...@gmail.com wrote: It is retained.  terms(fit) will give it to you, if fit is an lm object. Thank you. The following works nicely. (form - formula(y1~x1)) y1 ~ x1 x - lm(form,

Re: [R] proper work-flow with 'formula' objects and lm()

2011-11-24 Thread Liviu Andronic
On Thu, Nov 24, 2011 at 10:25 PM, Prof Brian Ripley rip...@stats.ox.ac.uk wrote: Yes.  That's a job for substitute (the second time today). form - formula(y1~x1) x - eval(substitute(lm(f, anscombe), list(f = form))) summary(x) Call: lm(formula = y1 ~ x1, data = anscombe) That's what I

Re: [R] proper work-flow with 'formula' objects and lm()

2011-11-24 Thread Gabor Grothendieck
On Thu, Nov 24, 2011 at 2:48 PM, Liviu Andronic landronim...@gmail.com wrote: Dear all I have a work-flow issue with lm(). When I use lm(y1~x1, anscombe) Call: lm(formula = y1 ~ x1, data = anscombe) Coefficients: (Intercept)           x1     3.0001       0.5001 I get as expected the

Re: [R] proper work-flow with 'formula' objects and lm()

2011-11-24 Thread Prof Brian Ripley
You would get exactly the same problem with ...,, anway. Here's a commonly used approach in R sources: x.lm - function(formula, data, ...) { Call - match.call(expand.dots = TRUE) Call[[1]] - as.name(lm) Call$formula - as.formula(terms(formula)) eval(Call) } On Thu, 24 Nov

Re: [R] proper work-flow with 'formula' objects and lm()

2011-11-24 Thread Liviu Andronic
On Thu, Nov 24, 2011 at 11:55 PM, Prof Brian Ripley rip...@stats.ox.ac.uk wrote: You would get exactly the same problem with ...,, anway. Here's a commonly used approach in R sources: x.lm - function(formula, data, ...) {    Call - match.call(expand.dots = TRUE)    Call[[1]] - as.name(lm)