[Rd] ambiguous (duplicated) names in model.matrix() (PR#701)

cberry@tajo.ucsd.edu cberry@tajo.ucsd.edu
Mon, 23 Oct 2000 21:06:05 +0200 (MET DST)


Interaction terms in model.matrix() use "." to spearate the components
that are separate by ":" in the corresponding terms().

Not only is this (IMHO) visually unpleasing, but can lead to ambiguous
labelling. Notice that "x.a"  is duplicated and that "x.a.x.b" is
ambiguous in this context:

> lm( y~x.a*x.b+x*a, x=T, data=data.frame(y=rnorm(10),x=1:10,a=rep(1:2,5),x.a=(1:10)%%3,x.b=(1:10)%%4))$x
   (Intercept) x.a x.b  x a x.a.x.b x.a
1            1   1   1  1 1       1   1
2            1   2   2  2 2       4   4
3            1   0   3  3 1       0   3
4            1   1   0  4 2       0   8
5            1   2   1  5 1       2   5
6            1   0   2  6 2       0  12
7            1   1   3  7 1       3   7
8            1   2   0  8 2       0  16
9            1   0   1  9 1       0   9
10           1   1   2 10 2       2  20
attr(,"assign")
[1] 0 1 2 3 4 5 6
> terms(lm( y~x.a*x.b+x*a, x=T, data=data.frame(y=rnorm(10),x=1:10,a=rep(1:2,5),x.a=(1:10)%%3,x.b=(1:10)%%4)))
y ~ x.a + x.b + x + a + x.a:x.b + x:a
attr(,"variables")
list(y, x.a, x.b, x, a)
attr(,"factors")
    x.a x.b x a x.a:x.b x:a
y     0   0 0 0       0   0
x.a   1   0 0 0       1   0
x.b   0   1 0 0       1   0
x     0   0 1 0       0   1
a     0   0 0 1       0   1
attr(,"term.labels")
[1] "x.a"     "x.b"     "x"       "a"       "x.a:x.b" "x:a"    
attr(,"order")
[1] 1 1 1 1 2 2
attr(,"intercept")
[1] 1
attr(,"response")
[1] 1
>

The prototype uses ":" in both cases.

--please do not edit the information below--

Version:
 platform = sparc-sun-solaris2.7
 arch = sparc
 os = solaris2.7
 system = sparc, solaris2.7
 status = 
 major = 1
 minor = 1.0
 year = 2000
 month = June
 day = 15
 language = R

Search Path:
 .GlobalEnv, Autoloads, package:base

Chuck Berry
-- 
Charles C. Berry                        (858) 534-2098 
                                         Dept of Family/Preventive
Medicine
E mailto:cberry@tajo.ucsd.edu	         UC San Diego
http://hacuna.ucsd.edu/members/ccb.html  La Jolla, San Diego 92093-0645

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._