Re: [Rd] columnames changes behaviour of formula

From: Joshua Wiley <jwiley.psych_at_gmail.com>
Date: Thu, 24 May 2012 21:46:46 -0700

Hi Robin,

Seems like the intended behavior to me. From the docs: "There are two special interpretations of '.' in a formula. The usual one is in the context of a 'data' argument of model fitting functions and means 'all columns not otherwise in the formula' "

d is in the formula so the only column not in the formula is nd. the (.)^2 asks for all two way interactions, but with only one variable, there are none.

What were you expecting?

Josh

On Thu, May 24, 2012 at 9:25 PM, robin hankin <hankin.robin_at_gmail.com> wrote:
> Hello. precompiled R-2.15.0, svn58871, macosx 10.7.4.
>
>
> I have discovered that defining column names of a dataframe can alter the
> behaviour of lm():
>
>
> d <- c(4,7,6,4)
> x <- data.frame(cbind(0:3,5:2))
> coef(lm(d~ -1 + (.)^2,data=x))
>   X1    X2 X1:X2
> -1.77  0.83  1.25
> R>
> R>
>
>
> OK, so far so good.  But change the column names of 'x' and the behaviour
> changes:
>
>
> colnames(x) <- c("d","nd")   # 'd' == 'death' and 'nd' == 'no death'
> coef(lm(d~ -1 + (.)^2,data=x))
>       nd
> 0.2962963
>
>
>
> I am not sure if this is consistent with the special meaning of '.'
> described under ?formula.
>
> Is this the intended behaviour?
>
>
> --
> Robin Hankin
> Uncertainty Analyst
> hankin.robin_at_gmail.com
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-devel_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

-- 
Joshua Wiley
Ph.D. Student, Health Psychology
Programmer Analyst II, Statistical Consulting Group
University of California, Los Angeles
https://joshuawiley.com/

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Fri 25 May 2012 - 04:59:22 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 25 May 2012 - 14:01:36 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive