model.matrix (Re: [R] R hang-up using lm)

Martin Maechler maechler at stat.math.ethz.ch
Wed Apr 28 16:40:00 CEST 2004


>>>>> "GB" == Göran Broström <gb at stat.umu.se>
>>>>>     on Wed, 28 Apr 2004 16:00:17 +0200 writes:


  <.........>

    GB> so,

    >> model.matrix(x ~ y)
    GB>    (Intercept) 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1
    GB> attr(,"assign") [1] 0

    GB> but


    >> model.matrix(x ~ as.vector(y))
    GB>    (Intercept) as.vector(y) 1 1 -0.853357506 2 1
    GB> -0.711872147 3 1 -0.228785137 4 1 -0.449739758 5 1
    GB> 0.173914266 6 1 -0.138766243 7 1 -0.433799800 8 1
    GB> 0.234183701 9 1 0.002728104 10 1 0.733590165
    GB> attr(,"assign") [1] 0 1

    GB> AND

    >> rr <- model.matrix.default(x ~ y)
    GB> Segmenteringsfel gb at tal:~$

 <..............>

    GB> (Don't ask me what's going on: but 'Segmenteringsfel'
    GB> means 'Segmentation fault':)

Thank you, Göran.

Yes, the bug is in model.matrix.default();  
one part of the problems happens in the line
    ans <- .Internal(model.matrix(t, data))
(which only returns the intercept part).
How to fix this is not yet clear to me, since we have to decide
if the internal C code should do more checking
or the R code in model.matrix.default.

BTW, a very simple reproducible example is

x <- 1:7; y. <- x ; y <- array(y, 7)

 model.matrix(x ~ y) # which behaves badly when called repeatedly;
		     # which for me means memory allocation problems
## as opposed to 

 model.matrix(x ~ y.) # which is all fine

----

I'll also file this as bug report.
Martin




More information about the R-help mailing list