[R] Problem with terms of the form (a >1) and subsetting of a terms object

peter dalgaard pdalgd at gmail.com
Thu Aug 26 15:16:17 CEST 2010


On Aug 26, 2010, at 10:35 AM, Niels Richard Hansen wrote:

> 
> 
> On 26/08/10 09.30, Dimitris Rizopoulos wrote:
>> I think you need an I(), i.e.,
>> 
>> form <- ~ I(a > 1) - 1
> 
> Yes, it solves the concrete problem, but does not really answer
> the question. Let me rephrase. Should the use of terms like (a>1)
> be discouraged in R and replaced by I(a>1) systematically, or is the
> behavior below unexpected?

I'd say "yes", and "maybe". I think the only constructs that are guaranteed to protect arithmetic expressions are function calls, including I(). So it is more or less coincidental that ~ (a>1) - 1 works in the first place; when updating it, you probably should "expect the unexpected".  

There could still be a bug -- it looks somewhat wrong that a>1 isn't retained as a call to "<" with arguments a and 1, parentheses or not, but the model formula expansion code involves deep and dark magic, and I'd just avoid going too near it.


-- 
Peter Dalgaard
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



More information about the R-help mailing list