Sorry about the lack of detail. I am running R v.1.2.2. I can recast my question (which I think I have partially answered) more succinctly as follows: 1. This seems to work (note that group takes values 1,2,3,4, or 5): my.newfun <- function(x) myfile <- lm(award ~ ilogemp + ilogage, x) test.by <- by(wintemp, as.factor(wintemp$group), my.newfun) 2. This does not work (leaving aside whether I am using ppr correctly or not!):> my.pprfun <- function(x) mypprfile <- ppr(award ~ ilogemp + ilogage, data = x, nterms = 5,+ max.terms = 10, optlevel = 3)> test.by <- by(wintemp, as.factor(wintemp$group), my.pprfun)Error in model.frame.default(formula = award ~ ilogemp + ilogage, data = x) : Object "x" not found 3. However, this does seem to work, but I don't know enough about R to explain why:> my.pprfun <- function(x) mypprfile <- ppr(award ~ ilogemp + ilogage,+ data = eval.parent(substitute(x),3), nterms = 5, max.terms = 10, optlevel = 3)> test.by <- by(wintemp, as.factor(wintemp$group), my.pprfun)If I understand this (and p. 69 of S Programming by VR) correctly, it seems as though I have to evaluate x three environments up the call sequence from ppr, but I don't have to do so for lm. I don't yet fully understand how the environments work, and I'm afraid that only a little knowledge is dangerous! Can anyone explain the difference between lm and ppr in this context? --------------- david.beede at mail.doc.gov wrote:> > Dear R list: > > I want to make separate estimates for each level of the variable "group." > After consulting many sources I am stumped as to why the following doesnot work:> > > wintemp <- subset(alltemp, winner==1) > > my.ppr <- function(x) > + { > + if(nrow(x) >= 50) { > + pprfile <- ppr(award~ilogemp,data=x,nterms=5,max.terms=10,optlevel=3)> + summary(pprfile) > + } > + } > > test.by <- by(wintemp,as.factor(wintemp$group),my.ppr) > Error in model.frame.default(formula = award ~ ilogemp, data = x) : > Object "x" not found > > Any help would be greatly appreciated. > (I am sure I am misunderstanding some fundamental R concepts.)It is hard to help, if we don't know what all those variables stand for. I tried something similar and it worked. What version of R are you running? Uwe Ligges -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Tue, 20 Mar 2001 david.beede at mail.doc.gov wrote:> Sorry about the lack of detail. I am running R v.1.2.2. I can recast my > question > (which I think I have partially answered) more succinctly as follows: > > 1. This seems to work (note that group takes values 1,2,3,4, or 5): > my.newfun <- function(x) myfile <- lm(award ~ ilogemp + ilogage, x) > test.by <- by(wintemp, as.factor(wintemp$group), my.newfun) > > 2. This does not work (leaving aside whether I am using ppr correctly or not!): > > my.pprfun <- function(x) mypprfile <- ppr(award ~ ilogemp + ilogage, data = x, nterms = 5, > + max.terms = 10, optlevel = 3) > > test.by <- by(wintemp, as.factor(wintemp$group), my.pprfun) > Error in model.frame.default(formula = award ~ ilogemp + ilogage, data = x) : > Object "x" not found > > 3. However, this does seem to work, but I don't know enough about R to explain why: > > my.pprfun <- function(x) mypprfile <- ppr(award ~ ilogemp + ilogage, > + data = eval.parent(substitute(x),3), nterms = 5, max.terms = 10, optlevel = 3) > > test.by <- by(wintemp, as.factor(wintemp$group), my.pprfun) > > If I understand this (and p. 69 of S Programming by VR) correctly, it seems as though > I have to evaluate x three environments up the call sequence from ppr, but I don't have > to do so for lm. I don't yet fully understand how the environments work, and I'm afraid > that only a little knowledge is dangerous! Can anyone explain the difference between > lm and ppr in this context?There's a bug in ppr.formula: m <- eval(m, sys.parent()) should be (in R) m <- eval(m, parent.frame()) I think that will fix it, but please confirm. -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Prof. Ripley -- Thank you for your reply. I'm not sure how to confirm your suggestion. I found the line that you cited in ppr.formula in the ascii file containing the modreg R code -- can I simply change that line and rerun my example? Or is there more to it than that? Prof Brian D Ripley <ripley at stats.ox.ac.uk>@auk.stats> on 03/20/2001 03:08:48 PM Sent by: <ripley at auk.stats> To: <david.beede at mail.doc.gov> cc: <r-help at stat.math.ethz.ch> Subject: Re: [R] Newbie question about by() -- update On Tue, 20 Mar 2001 david.beede at mail.doc.gov wrote:> Sorry about the lack of detail. I am running R v.1.2.2. I can recast my > question > (which I think I have partially answered) more succinctly as follows: > > 1. This seems to work (note that group takes values 1,2,3,4, or 5): > my.newfun <- function(x) myfile <- lm(award ~ ilogemp + ilogage, x) > test.by <- by(wintemp, as.factor(wintemp$group), my.newfun) > > 2. This does not work (leaving aside whether I am using ppr correctly ornot!):> > my.pprfun <- function(x) mypprfile <- ppr(award ~ ilogemp + ilogage,data = x, nterms = 5,> + max.terms = 10, optlevel = 3) > > test.by <- by(wintemp, as.factor(wintemp$group), my.pprfun) > Error in model.frame.default(formula = award ~ ilogemp + ilogage, data x) : > Object "x" not found > > 3. However, this does seem to work, but I don't know enough about R toexplain why:> > my.pprfun <- function(x) mypprfile <- ppr(award ~ ilogemp + ilogage, > + data = eval.parent(substitute(x),3), nterms = 5, max.terms = 10,optlevel = 3)> > test.by <- by(wintemp, as.factor(wintemp$group), my.pprfun) > > If I understand this (and p. 69 of S Programming by VR) correctly, itseems as though> I have to evaluate x three environments up the call sequence from ppr,but I don't have> to do so for lm. I don't yet fully understand how the environments work,and I'm afraid> that only a little knowledge is dangerous! Can anyone explain thedifference between> lm and ppr in this context?There's a bug in ppr.formula: m <- eval(m, sys.parent()) should be (in R) m <- eval(m, parent.frame()) I think that will fix it, but please confirm. -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Prof. Ripley -- I made the change you suggested, and it works. Thank you very much for your help. Prof Brian D Ripley <ripley at stats.ox.ac.uk>@auk.stats> on 03/20/2001 05:21:28 PM Sent by: <ripley at auk.stats> To: <david.beede at mail.doc.gov> cc: <r-help at stat.math.ethz.ch> Subject: Re: [R] Newbie question about by() -- update On Tue, 20 Mar 2001 david.beede at mail.doc.gov wrote:> > Prof. Ripley -- > Thank you for your reply. > > I'm not sure how to confirm your suggestion. I found the line that you > cited in ppr.formula in the ascii file containing the modreg R code --can> I simply change that line and rerun my example? Or is there more to it > than that?Yes, no. You can also do library(modreg) fix(ppr.formula) # try example.> > > > > Prof Brian D Ripley <ripley at stats.ox.ac.uk>@auk.stats> on 03/20/2001 > 03:08:48 PM > > Sent by: <ripley at auk.stats> > > > To: <david.beede at mail.doc.gov> > cc: <r-help at stat.math.ethz.ch> > > Subject: Re: [R] Newbie question about by() -- update > > > On Tue, 20 Mar 2001 david.beede at mail.doc.gov wrote: > > > Sorry about the lack of detail. I am running R v.1.2.2. I can recastmy> > question > > (which I think I have partially answered) more succinctly as follows: > > > > 1. This seems to work (note that group takes values 1,2,3,4, or 5): > > my.newfun <- function(x) myfile <- lm(award ~ ilogemp + ilogage, x) > > test.by <- by(wintemp, as.factor(wintemp$group), my.newfun) > > > > 2. This does not work (leaving aside whether I am using ppr correctlyor> not!): > > > my.pprfun <- function(x) mypprfile <- ppr(award ~ ilogemp + ilogage, > data = x, nterms = 5, > > + max.terms = 10, optlevel = 3) > > > test.by <- by(wintemp, as.factor(wintemp$group), my.pprfun) > > Error in model.frame.default(formula = award ~ ilogemp + ilogage, data > x) : > > Object "x" not found > > > > 3. However, this does seem to work, but I don't know enough about R to > explain why: > > > my.pprfun <- function(x) mypprfile <- ppr(award ~ ilogemp + ilogage, > > + data = eval.parent(substitute(x),3), nterms = 5, max.terms = 10, > optlevel = 3) > > > test.by <- by(wintemp, as.factor(wintemp$group), my.pprfun) > > > > If I understand this (and p. 69 of S Programming by VR) correctly, it > seems as though > > I have to evaluate x three environments up the call sequence from ppr, > but I don't have > > to do so for lm. I don't yet fully understand how the environmentswork,> and I'm afraid > > that only a little knowledge is dangerous! Can anyone explain the > difference between > > lm and ppr in this context? > > There's a bug in ppr.formula: > > m <- eval(m, sys.parent()) > > should be (in R) > > m <- eval(m, parent.frame()) > > I think that will fix it, but please confirm. > > -- > Brian D. Ripley, ripley at stats.ox.ac.uk > Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ > University of Oxford, Tel: +44 1865 272861 (self) > 1 South Parks Road, +44 1865 272860 (secr) > Oxford OX1 3TG, UK Fax: +44 1865 272595 > > > > >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._