Skip to content

Dots in models formulae

8 messages · Laurent Valdes, Uwe Ligges, Sundar Dorai-Raj +2 more

#
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 ?

--
--~~ Toulouse, Grenoble, Auch, Arcachon, B??ziers, Paris,
Saragosse, L??vignac Sur Save, habitats naturel du Valdo. ~~--
< http://www.le-valdo.com>
#
Laurent Valdes wrote:

            
All other variables (except y) from the given data.frame...

Uwe Ligges
#
On Tue, 2005-08-16 at 18:43 +0200, Laurent Valdes wrote:
The "." is a short cut to mean all variables specified in the data
argument. E.g.:
y  x  z
1   1  1  1
2   2  2  2
3   3  3  3
4   4  4  4
5   5  5  5
6   6  6  6
7   7  7  7
8   8  8  8
9   9  9  9
10 10 10 10

If the response is also found on the rhs (right-hand-side) of the
formula (i.e via using ".") then it is silently droppped from the rhs.

So this is equivalent to the above formula
y  x  z
1   1  1  1
2   2  2  2
3   3  3  3
4   4  4  4
5   5  5  5
6   6  6  6
7   7  7  7
8   8  8  8
9   9  9  9
10 10 10 10

Here y isn't the response but is included as it is in ".", i.e. dat.
a  y  x  z
1   1  1  1  1
2   2  2  2  2
3   3  3  3  3
4   4  4  4  4
5   5  5  5  5
6   6  6  6  6
7   7  7  7  7
8   8  8  8  8
9   9  9  9  9
10 10 10 10 10

If we don't specify data and we don't have an object named "." (which
may be impossible - I don't know) you get an error:
Error in eval(expr, envir, enclos) : Object "." not found

I couldn't find "." documented for use in forumla (only for update(),
where it means something slightly different) but I remember seeing this
somewhere.

HTH

G
#
Uwe Ligges wrote:
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.

Thanks,

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

            
(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.
#
On Tue, 2005-08-16 at 12:24 -0500, Sundar Dorai-Raj wrote:
Not for "." in a formula in ?formula, at least in 

platform i686-pc-linux-gnu
arch     i686
os       linux-gnu
system   i686, linux-gnu
status   Patched
major    2
minor    1.1
year     2005
month    08
day      15
language R

I still can't find this documented for a formula (I found
update.formula, but the meaning of "." is different there, slightly, as
you indicate) - but it must be as I didn't imagine seeing it - or maybe
I did...

G
#
On Tue, 16 Aug 2005, Gavin Simpson wrote:

            
It _is_ in `An Introduction to R', both for lm() and update.formula(). 
Since this meaning does depend on using terms.formula(), it is on that 
functions' help page.