Re: [Rd] formula(CO2)
About a month ago I had a similar issue related to 'formula': http://tolstoy.newcastle.edu.au/R/e2/devel/07/05/3329.html In summary: In S-Plus, the help for formula.data.frame says: This is a method for the function formula() for objects inheriting from class data.frame. If object is a model frame, the formula for the model frame is returned, otherwise a formula is deduced from the names of object. The first name is taken to be the response, and all the remaining names are pasted together additively. In R, the help for formula.data.frame is aliased to the help for formula, but does not clearly document the usage with data.frames. Kevin On 7/16/07, Gabor Grothendieck [EMAIL PROTECTED] wrote: The formula attribute of the builtin CO2 dataset seems a bit strange: formula(CO2) Plant ~ Type + Treatment + conc + uptake What is one supposed to do with that? Certainly its not suitable for input to lm and none of the examples in ?CO2 use the above. __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] formula(CO2)
The formula attribute of the builtin CO2 dataset seems a bit strange: formula(CO2) Plant ~ Type + Treatment + conc + uptake What is one supposed to do with that? Certainly its not suitable for input to lm and none of the examples in ?CO2 use the above. __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] formula(CO2)
On 16-Jul-07 13:28:50, Gabor Grothendieck wrote: The formula attribute of the builtin CO2 dataset seems a bit strange: formula(CO2) Plant ~ Type + Treatment + conc + uptake What is one supposed to do with that? Certainly its not suitable for input to lm and none of the examples in ?CO2 use the above. I think one is supposed to ignore it! (Or maybe be inspired to write a mail to the list ... ). I couldn't find anything that looked like the above formula from str(CO2). But I did spot that the order of terms in the formula: Plant, Type, treatment, conc, uptake, is the same as the order of the columns in the dataframe. So I tried: D-data.frame(x=(1:10),y=(1:10)) formula(D) x ~ y So, lo and behold, D has a formula! Or does it? Maybe if you give formula() a dataframe, it simply constructs one from the columns. Best wishes, Ted. E-Mail: (Ted Harding) [EMAIL PROTECTED] Fax-to-email: +44 (0)870 094 0861 Date: 16-Jul-07 Time: 14:57:28 -- XFMail -- __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] formula(CO2)
On 16-Jul-07 13:57:56, Ted Harding wrote: On 16-Jul-07 13:28:50, Gabor Grothendieck wrote: The formula attribute of the builtin CO2 dataset seems a bit strange: formula(CO2) Plant ~ Type + Treatment + conc + uptake What is one supposed to do with that? Certainly its not suitable for input to lm and none of the examples in ?CO2 use the above. I think one is supposed to ignore it! (Or maybe be inspired to write a mail to the list ... ). I couldn't find anything that looked like the above formula from str(CO2). But I did spot that the order of terms in the formula: Plant, Type, treatment, conc, uptake, is the same as the order of the columns in the dataframe. So I tried: D-data.frame(x=(1:10),y=(1:10)) formula(D) x ~ y So, lo and behold, D has a formula! Or does it? Maybe if you give formula() a dataframe, it simply constructs one from the columns. Now that I think about it, I can see a use for this phenomenon: formula(CO2) Plant ~ Type + Treatment + conc + uptake formula(CO2[,2:5]) Type ~ Treatment + conc + uptake formula(CO2[,3:5]) Treatment ~ conc + uptake formula(CO2[,4:5]) conc ~ uptake formula(CO2[,c(5,1,2,3,4)]) uptake ~ Plant + Type + Treatment + conc Could save a lot of typing! Best wishes, Ted. E-Mail: (Ted Harding) [EMAIL PROTECTED] Fax-to-email: +44 (0)870 094 0861 Date: 16-Jul-07 Time: 15:14:38 -- XFMail -- __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] formula(CO2)
Good point. It seems that the groupedData methods are all in the nlme package yet CO2 is in datasets. CO2 should probably be moved to nlme. Of course one still wonders whether the way formula currently works on data frames is really intended and desirable. Ted's point is well taken but I think formula.data.frame could still have the current default yet be user overridable via the formula attribute. On 7/16/07, Gavin Simpson [EMAIL PROTECTED] wrote: On Mon, 2007-07-16 at 14:57 +0100, [EMAIL PROTECTED] wrote: On 16-Jul-07 13:28:50, Gabor Grothendieck wrote: The formula attribute of the builtin CO2 dataset seems a bit strange: formula(CO2) Plant ~ Type + Treatment + conc + uptake What is one supposed to do with that? Certainly its not suitable for input to lm and none of the examples in ?CO2 use the above. I think one is supposed to ignore it! (Or maybe be inspired to write a mail to the list ... ). I couldn't find anything that looked like the above formula from str(CO2). But I did spot that the order of terms in the formula: Plant, Type, treatment, conc, uptake, is the same as the order of the columns in the dataframe. CO2 is a groupedData object not a data.frame per se. class(CO2) [1] nfnGroupedData nfGroupedData groupedDatadata.frame What Gabor saw was the result of formula.data.frame being applied to CO2, which, as you surmise Ted, is being produced from the columns of CO2. formula(CO2) Plant ~ Type + Treatment + conc + uptake stats:::formula.data.frame(CO2) Plant ~ Type + Treatment + conc + uptake But if we load nlme, we see that now (via a groupedData method for formula) a more useful formula is displayed. require(nlme) Loading required package: nlme [1] TRUE formula(CO2) uptake ~ conc | Plant as this can then be directly used in lme lme(CO2) Linear mixed-effects model fit by REML Data: CO2 Log-restricted-likelihood: -283.1447 Fixed: uptake ~ conc (Intercept)conc 19.50028981 0.01773059 snip / But like Gabor, I'm struggling to see where this [formula(data.frame)] might be used (useful)? G -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] formula(CO2)
Note that the formula uptake ~. will do the same thing so its not clear how useful this facility really is. On 7/16/07, Ted Harding [EMAIL PROTECTED] wrote: On 16-Jul-07 14:16:10, Gabor Grothendieck wrote: Following up on your comments it seems formula.data.frame just creates a formula whose lhs is the first column name and whose rhs is made up of the remaining column names. It ignores the formula attribute. In fact, CO2 does have a formula attribute but its not extracted by formula.data.frame: [EMAIL PROTECTED] uptake ~ conc | Plant formula(CO2) Plant ~ Type + Treatment + conc + uptake Indeed! And, following up yet again on my own follow-up comment: library(combinat) for(j in (1:4)){ for(i in combn((1:4),j,simplify=FALSE)){ print(formula(CO2[,c(5,i)])) } } uptake ~ Plant uptake ~ Type uptake ~ Treatment uptake ~ conc uptake ~ Plant + Type uptake ~ Plant + Treatment uptake ~ Plant + conc uptake ~ Type + Treatment uptake ~ Type + conc uptake ~ Treatment + conc uptake ~ Plant + Type + Treatment uptake ~ Plant + Type + conc uptake ~ Plant + Treatment + conc uptake ~ Type + Treatment + conc uptake ~ Plant + Type + Treatment + conc opening the door to automated fitting of all possible models (without interactions)! Now if only I could find out how to do the interactions as well, I would never need to think again! best wishes, Ted. E-Mail: (Ted Harding) [EMAIL PROTECTED] Fax-to-email: +44 (0)870 094 0861 Date: 16-Jul-07 Time: 15:40:36 -- XFMail -- __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] formula(CO2)
On 16-Jul-07 14:16:10, Gabor Grothendieck wrote: Following up on your comments it seems formula.data.frame just creates a formula whose lhs is the first column name and whose rhs is made up of the remaining column names. It ignores the formula attribute. In fact, CO2 does have a formula attribute but its not extracted by formula.data.frame: [EMAIL PROTECTED] uptake ~ conc | Plant formula(CO2) Plant ~ Type + Treatment + conc + uptake Indeed! And, following up yet again on my own follow-up comment: library(combinat) for(j in (1:4)){ for(i in combn((1:4),j,simplify=FALSE)){ print(formula(CO2[,c(5,i)])) } } uptake ~ Plant uptake ~ Type uptake ~ Treatment uptake ~ conc uptake ~ Plant + Type uptake ~ Plant + Treatment uptake ~ Plant + conc uptake ~ Type + Treatment uptake ~ Type + conc uptake ~ Treatment + conc uptake ~ Plant + Type + Treatment uptake ~ Plant + Type + conc uptake ~ Plant + Treatment + conc uptake ~ Type + Treatment + conc uptake ~ Plant + Type + Treatment + conc opening the door to automated fitting of all possible models (without interactions)! Now if only I could find out how to do the interactions as well, I would never need to think again! best wishes, Ted. E-Mail: (Ted Harding) [EMAIL PROTECTED] Fax-to-email: +44 (0)870 094 0861 Date: 16-Jul-07 Time: 15:40:36 -- XFMail -- __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] formula(CO2)
Yes. That's what I was referring to. On 7/16/07, Ted Harding [EMAIL PROTECTED] wrote: On 16-Jul-07 14:42:19, Gabor Grothendieck wrote: Note that the formula uptake ~. will do the same thing so its not clear how useful this facility really is. Hmmm... Do you mean somthing like lm(uptake ~ . , data=CO2[,i]) where i is a subset of (1:4) as in my code below? In which case I agree! Ted. On 7/16/07, Ted Harding [EMAIL PROTECTED] wrote: On 16-Jul-07 14:16:10, Gabor Grothendieck wrote: Following up on your comments it seems formula.data.frame just creates a formula whose lhs is the first column name and whose rhs is made up of the remaining column names. It ignores the formula attribute. In fact, CO2 does have a formula attribute but its not extracted by formula.data.frame: [EMAIL PROTECTED] uptake ~ conc | Plant formula(CO2) Plant ~ Type + Treatment + conc + uptake Indeed! And, following up yet again on my own follow-up comment: library(combinat) for(j in (1:4)){ for(i in combn((1:4),j,simplify=FALSE)){ print(formula(CO2[,c(5,i)])) } } uptake ~ Plant uptake ~ Type uptake ~ Treatment uptake ~ conc uptake ~ Plant + Type uptake ~ Plant + Treatment uptake ~ Plant + conc uptake ~ Type + Treatment uptake ~ Type + conc uptake ~ Treatment + conc uptake ~ Plant + Type + Treatment uptake ~ Plant + Type + conc uptake ~ Plant + Treatment + conc uptake ~ Type + Treatment + conc uptake ~ Plant + Type + Treatment + conc opening the door to automated fitting of all possible models (without interactions)! Now if only I could find out how to do the interactions as well, I would never need to think again! best wishes, Ted. E-Mail: (Ted Harding) [EMAIL PROTECTED] Fax-to-email: +44 (0)870 094 0861 Date: 16-Jul-07 Time: 15:40:36 -- XFMail -- __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel E-Mail: (Ted Harding) [EMAIL PROTECTED] Fax-to-email: +44 (0)870 094 0861 Date: 16-Jul-07 Time: 16:13:15 -- XFMail -- __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] formula(CO2)
On 16-Jul-07 14:42:19, Gabor Grothendieck wrote: Note that the formula uptake ~. will do the same thing so its not clear how useful this facility really is. Hmmm... Do you mean somthing like lm(uptake ~ . , data=CO2[,i]) where i is a subset of (1:4) as in my code below? In which case I agree! Ted. On 7/16/07, Ted Harding [EMAIL PROTECTED] wrote: On 16-Jul-07 14:16:10, Gabor Grothendieck wrote: Following up on your comments it seems formula.data.frame just creates a formula whose lhs is the first column name and whose rhs is made up of the remaining column names. It ignores the formula attribute. In fact, CO2 does have a formula attribute but its not extracted by formula.data.frame: [EMAIL PROTECTED] uptake ~ conc | Plant formula(CO2) Plant ~ Type + Treatment + conc + uptake Indeed! And, following up yet again on my own follow-up comment: library(combinat) for(j in (1:4)){ for(i in combn((1:4),j,simplify=FALSE)){ print(formula(CO2[,c(5,i)])) } } uptake ~ Plant uptake ~ Type uptake ~ Treatment uptake ~ conc uptake ~ Plant + Type uptake ~ Plant + Treatment uptake ~ Plant + conc uptake ~ Type + Treatment uptake ~ Type + conc uptake ~ Treatment + conc uptake ~ Plant + Type + Treatment uptake ~ Plant + Type + conc uptake ~ Plant + Treatment + conc uptake ~ Type + Treatment + conc uptake ~ Plant + Type + Treatment + conc opening the door to automated fitting of all possible models (without interactions)! Now if only I could find out how to do the interactions as well, I would never need to think again! best wishes, Ted. E-Mail: (Ted Harding) [EMAIL PROTECTED] Fax-to-email: +44 (0)870 094 0861 Date: 16-Jul-07 Time: 15:40:36 -- XFMail -- __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel E-Mail: (Ted Harding) [EMAIL PROTECTED] Fax-to-email: +44 (0)870 094 0861 Date: 16-Jul-07 Time: 16:13:15 -- XFMail -- __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] formula(CO2)
CO2 is apparently a groupedData object; the formula attribute is described by Pinheiro and Bates as a 'display formula'. Perhaps reference to the nlme package's groupedData help would be informative? Gabor Grothendieck [EMAIL PROTECTED] 16/07/2007 16:18:37 Yes. That's what I was referring to. On 7/16/07, Ted Harding [EMAIL PROTECTED] wrote: On 16-Jul-07 14:42:19, Gabor Grothendieck wrote: Note that the formula uptake ~. will do the same thing so its not clear how useful this facility really is. Hmmm... Do you mean somthing like lm(uptake ~ . , data=CO2[,i]) where i is a subset of (1:4) as in my code below? In which case I agree! Ted. On 7/16/07, Ted Harding [EMAIL PROTECTED] wrote: On 16-Jul-07 14:16:10, Gabor Grothendieck wrote: Following up on your comments it seems formula.data.frame just creates a formula whose lhs is the first column name and whose rhs is made up of the remaining column names. It ignores the formula attribute. In fact, CO2 does have a formula attribute but its not extracted by formula.data.frame: [EMAIL PROTECTED] uptake ~ conc | Plant formula(CO2) Plant ~ Type + Treatment + conc + uptake Indeed! And, following up yet again on my own follow-up comment: library(combinat) for(j in (1:4)){ for(i in combn((1:4),j,simplify=FALSE)){ print(formula(CO2[,c(5,i)])) } } uptake ~ Plant uptake ~ Type uptake ~ Treatment uptake ~ conc uptake ~ Plant + Type uptake ~ Plant + Treatment uptake ~ Plant + conc uptake ~ Type + Treatment uptake ~ Type + conc uptake ~ Treatment + conc uptake ~ Plant + Type + Treatment uptake ~ Plant + Type + conc uptake ~ Plant + Treatment + conc uptake ~ Type + Treatment + conc uptake ~ Plant + Type + Treatment + conc opening the door to automated fitting of all possible models (without interactions)! Now if only I could find out how to do the interactions as well, I would never need to think again! best wishes, Ted. E-Mail: (Ted Harding) [EMAIL PROTECTED] Fax-to-email: +44 (0)870 094 0861 Date: 16-Jul-07 Time: 15:40:36 -- XFMail -- __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel E-Mail: (Ted Harding) [EMAIL PROTECTED] Fax-to-email: +44 (0)870 094 0861 Date: 16-Jul-07 Time: 16:13:15 -- XFMail -- __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel *** This email and any attachments are confidential. Any use, co...{{dropped}} __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel