[R] Dots in models formulae

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Aug 16 19:48:27 CEST 2005


On Tue, 16 Aug 2005, Sundar Dorai-Raj wrote:

> Uwe Ligges wrote:
>> Laurent Valdes wrote:
>>
>>
>>> I have seen, several times, dots (like this: "y ~." ) in formula
>>> descriptions, noticeably in R help.
>>>
>>> I am unable to see what it does correspond to.
>>>
>>> Any ideas ?
>>
>> All other variables (except y) from the given data.frame...
>>
>> Uwe Ligges
>>
>
> Hi, Uwe,
>
> Doesn't this depend on the context? For example,
>
> z <- data.frame(y = rnorm(10), x = rnorm(10))
> fit <- lm(y ~ ., z)
> update(fit, y ~ . + I(x^2))
>
> The original poster did not say where he saw this formula. However, I
> think the reference in ?formula has the most authorative explanation.

(It does not cover this, as it is part of the interpretation of a 
formula.)

Yes, it must depend on context, as an R function can do anything it likes 
with a formula (including making y ~ x mean the regression of x on y).

If terms.formula() is used, y ~ . means what Uwe said, _if_ there is a 
'data' argument.  However, if not it has its literal meaning (a variable 
named '.'), at least until 2.2.0.

-- 
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 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list