Re: [R] Long model formulae

2010-10-24 Thread Bill.Venables
Here is a dodge I often use.  This is a mock-up example.

___

bar - data.frame(matrix(rnorm(1001), nrow = 1))
names(bar)[1] - y  ## say
head(bar[,1:5])

nbar - names(bar)
form - as.formula(paste(nbar[1], ~, paste(nbar[-1], collapse = +)))
fitModel - substitute(tm - rpart(FORM, data = DATA), 
list(FORM = form, DATA = quote(bar)))
fitModel  ## the screen quietly erupts...

library(rpart)
eval(fitModel)  ## to do the job.
___

The advantage of proceeding this way is that the object you create, fm, has a 
meaningful (but large!) formula in it and the name of the dataframe from which 
the variables come.  This makes it easy, e.g. to use manipulation tools on it.


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of James Hirschorn
Sent: Sunday, 24 October 2010 11:51 AM
To: r-help@r-project.org
Subject: [R] Long model formulae


What is a good way to enter a very long model formula. For example:

y ~ Input.2 + Input.3 + ... + Input.1000

(assuming the corresponding dataframe has many other columns). 

Is there a way to convert a character string to a formula? Are there command 
line expansions in R besides the simple '.'?

Thanks.
  
[[alternative HTML version deleted]]

__
R-help@r-project.org 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.

__
R-help@r-project.org 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.


Re: [R] Long model formulae

2010-10-24 Thread James Hirschorn



 Here is a dodge I often use. This is a mock-up example.

Very instructive (and helpful) ...


 ___

 bar - data.frame(matrix(rnorm(1001), nrow = 1))
 names(bar)[1] - y ## say
 head(bar[,1:5])

 nbar - names(bar)
 form - as.formula(paste(nbar[1], ~, paste(nbar[-1], collapse = +)))
 fitModel - substitute(tm - rpart(FORM, data = DATA),
 list(FORM = form, DATA = quote(bar)))
 fitModel ## the screen quietly erupts...

 library(rpart)
 eval(fitModel) ## to do the job.
 ___

 The advantage of proceeding this way is that the object you create, fm, has a 
 meaningful (but large!) formula in it and the name of the dataframe from 
 which the variables come. This makes it easy, e.g. to use manipulation tools 
 on it.


  
__
R-help@r-project.org 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.


[R] Long model formulae

2010-10-23 Thread James Hirschorn

What is a good way to enter a very long model formula. For example:

y ~ Input.2 + Input.3 + ... + Input.1000

(assuming the corresponding dataframe has many other columns). 

Is there a way to convert a character string to a formula? Are there command 
line expansions in R besides the simple '.'?

Thanks.
  
[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


Re: [R] Long model formulae

2010-10-23 Thread Gabor Grothendieck
On Sat, Oct 23, 2010 at 9:51 PM, James Hirschorn
james.hirsch...@hotmail.com wrote:

 What is a good way to enter a very long model formula. For example:

 y ~ Input.2 + Input.3 + ... + Input.1000

 (assuming the corresponding dataframe has many other columns).

 Is there a way to convert a character string to a formula? Are there command 
 line expansions in R besides the simple '.'?


If y is in column 1 and Input.2, ..., Input.1000 are in columns 2
through 1000 then try this:

   lm(y ~., DF[1:1000])


-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

__
R-help@r-project.org 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.


Re: [R] Long model formulae

2010-10-23 Thread David Winsemius


On Oct 23, 2010, at 6:56 PM, Gabor Grothendieck wrote:


On Sat, Oct 23, 2010 at 9:51 PM, James Hirschorn
james.hirsch...@hotmail.com wrote:


What is a good way to enter a very long model formula. For example:

y ~ Input.2 + Input.3 + ... + Input.1000

(assuming the corresponding dataframe has many other columns).

Is there a way to convert a character string to a formula? Are  
there command line expansions in R besides the simple '.'?




If y is in column 1 and Input.2, ..., Input.1000 are in columns 2
through 1000 then try this:

  lm(y ~., DF[1:1000])


I guess the next logical(?) question would be: If the independent  
variables of interest are in columns 3,5,6,7,8,9,10,and 13 and the  
dependent variable is in column 20, would this work:


lm(y ~., data=DF[c(20, 3,5,6:10, 13)])
# ? with any consecutive columns specified with the : operator?

Or perhaps with grep(patt) in with the column indices?

--
David.

__
R-help@r-project.org 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.