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>
Dots in models formulae
8 messages · Laurent Valdes, Uwe Ligges, Sundar Dorai-Raj +2 more
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
On Tue, 2005-08-16 at 18:43 +0200, 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 ?
The "." is a short cut to mean all variables specified in the data argument. E.g.:
dat <- data.frame(y = 1:10, x = 1:10, z = 1:10) model.frame(y ~ ., data = dat)
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
model.frame(y ~ x + y + z, data = dat)
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 <- 1:10 model.frame(a ~ ., data = 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:
model.frame(a ~ .)
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
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Gavin Simpson [T] +44 (0)20 7679 5522 ENSIS Research Fellow [F] +44 (0)20 7679 7565 ENSIS Ltd. & ECRC [E] gavin.simpsonATNOSPAMucl.ac.uk UCL Department of Geography [W] http://www.ucl.ac.uk/~ucfagls/cv/ 26 Bedford Way [W] http://www.ucl.ac.uk/~ucfagls/ London. WC1H 0AP. %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
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. Thanks, --sundar
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
On Tue, 2005-08-16 at 12:24 -0500, 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.
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
Thanks, --sundar
______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Gavin Simpson [T] +44 (0)20 7679 5522 ENSIS Research Fellow [F] +44 (0)20 7679 7565 ENSIS Ltd. & ECRC [E] gavin.simpsonATNOSPAMucl.ac.uk UCL Department of Geography [W] http://www.ucl.ac.uk/~ucfagls/cv/ 26 Bedford Way [W] http://www.ucl.ac.uk/~ucfagls/ London. WC1H 0AP. %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
On Tue, 16 Aug 2005, Gavin Simpson wrote:
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...
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.
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
An embedded and charset-unspecified text was scrubbed... Name: not available Url: https://stat.ethz.ch/pipermail/r-help/attachments/20050817/f5062f49/attachment.pl