Jarrett Byrnes
2010-Aug-11 22:03 UTC
[R] a question regarding updating formulas with coefficients
I have formulae with coefficents that I would like to update. However, I get some strange results. For example, see the following: For the formula y ~ d+ 3*r+t I want to add a variable p, so> update(y~d+0*r+t, .~.+p)produces y ~ d + t + p - 1 If the coefficient is not 0, but rather, something else - say, 3, I get the following:> update(y~d+3*r+t, .~.+p)Error in terms.formula(tmp, simplify = TRUE) : invalid model formula in ExtractVars>Is there a way to do this, or a different call I should be trying? -Jarrett
David Winsemius
2010-Aug-11 22:23 UTC
[R] a question regarding updating formulas with coefficients
On Aug 11, 2010, at 6:03 PM, Jarrett Byrnes wrote:> I have formulae with coefficents that I would like to update. > However, I get some strange results. For example, see the following: > > For the formula y ~ d+ 3*r+tDid you really get meaningful results from that formula? Care to provide an example? Maybe there is something more for me to learn.> I want to add a variable p, so > >> update(y~d+0*r+t, .~.+p)In formulas the "*" operator is an interaction creator. so you told R to make 0 + r + 0:r. Probably not what you thought you were doing. So what were you trying to do anyway?> > produces > > y ~ d + t + p - 1Which at least explains why you got the -1 (which in R formulas is that same as +0).> > If the coefficient is not 0, but rather, something else - say, 3,What do you think you are accomplishing when you put a scalar coefficient in the formula?> I get the following: > >> update(y~d+3*r+t, .~.+p) > > Error in terms.formula(tmp, simplify = TRUE) : > invalid model formula in ExtractVars >> > > > Is there a way to do this,> or a different call I should be trying?What you should be doing depends on what you want to happen. -- David Winsemius, MD West Hartford, CT
Charles C. Berry
2010-Aug-11 22:45 UTC
[R] a question regarding updating formulas with coefficients
On Wed, 11 Aug 2010, David Winsemius wrote:> > On Aug 11, 2010, at 6:03 PM, Jarrett Byrnes wrote: > >> I have formulae with coefficents that I would like to update. However, I >> get some strange results. For example, see the following: >> >> For the formula y ~ d+ 3*r+t > > Did you really get meaningful results from that formula? Care to provide an > example? Maybe there is something more for me to learn. > > >> I want to add a variable p, so >> >> > update(y~d+0*r+t, .~.+p) > > In formulas the "*" operator is an interaction creator. so you told R to make > 0 + r + 0:r. Probably not what you thought you were doing. So what were you > trying to do anyway? > >> >> produces >> >> y ~ d + t + p - 1 > > Which at least explains why you got the -1 (which in R formulas is that same > as +0). >> >> If the coefficient is not 0, but rather, something else - say, 3, > > What do you think you are accomplishing when you put a scalar coefficient in > the formula? >Maybe he wants ?I ?? Chuck>> I get the following: >> >> > update(y~d+3*r+t, .~.+p) >> >> Error in terms.formula(tmp, simplify = TRUE) : >> invalid model formula in ExtractVars >> > >> >> >> Is there a way to do this, > >> or a different call I should be trying? > > What you should be doing depends on what you want to happen. > > -- > > David Winsemius, MD > West Hartford, CT > > ______________________________________________ > R-help at 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. >Charles C. Berry (858) 534-2098 Dept of Family/Preventive Medicine E mailto:cberry at tajo.ucsd.edu UC San Diego http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901