[R] R hang-up using lm

Roger Bivand Roger.Bivand at nhh.no
Wed Apr 28 12:07:37 CEST 2004


On 28 Apr 2004, Peter Dalgaard wrote:

> Göran Broström <gb at stat.umu.se> writes:
> 
> > > >    >> set.seed(3)
> > > >    >> yy <- rnorm(20)
> > > >    >> gg <- rep(1:10, 2)
> > > >    >> y <- tapply(yy, gg, median)
> > > >    >> x <- 1:10
> > > >    >> z <- lm(y ~ x)  # OK
> > > >    >> z <- lm(x ~ y)  # crashes R
> ....
> > I had to try it too: No crashes on Win2000 pro (1.8.1) or Linux (1.9.0),
> > but (in both cases):
> > 
> > 
> > >  lm(y ~ x)
> > 
> > Call:
> > lm(formula = y ~ x)
> > 
> > Coefficients:
> > (Intercept)            x  
> >     -0.8783       0.1293  
> > 
> > 
> > >  lm(x ~ y)
> > 
> > Call:
> > lm(formula = x ~ y)
> > 
> > Coefficients:
> > (Intercept)  
> >         5.5  
> > 
> > i.e., only an intercept estimate in the second case! Surely something is
> > wrong!? 
> 
> I just tried it on the 64-bit system and got Göran's result. However,
> repeating the lm(x~y) bit seems to have gotten itself stuck after the
> 3rd time (looks like a memory runaway problem, currently at 3.6GB and
> counting...). So perhaps those who couldn't reproduce should try it with
> replicate(100, lm(x~y)) or so.
> 

RHEL 3, R 1.9.0 seg.faults:

> set.seed(3)
> yy <- rnorm(20)
> gg <- rep(1:10, 2)
> y <- tapply(yy, gg, median)
> x <- 1:10
> z <- lm(y ~ x)  # OK
> str(y)
 num [, 1:10] -0.853 -0.712 -0.229 -0.450  0.174 ...
 - attr(*, "dimnames")=List of 1
  ..$ : chr [1:10] "1" "2" "3" "4" ...
> dim(y)
[1] 10
> z <- lm(x ~ y)
> replicate(100, lm(x~y))
Error in model.matrix.default(mt, mf, contrasts) : 
        invalid type for dimname (must be a vector)
> lm(x~y)

Program received signal SIGSEGV, Segmentation fault.
Rf_getAttrib (vec=0x8f71200, name=0x81f47d8) at attrib.c:99
99              if (TAG(s) == name) {
(gdb) bt
#0  Rf_getAttrib (vec=0x8f71200, name=0x81f47d8) at attrib.c:99
#1  0x08122363 in Rf_isArray (s=0x8f71200) at util.c:413
#2  0x08069aef in Rf_dimnamesgets (vec=0x8f71200, val=0x8f627c8)
    at attrib.c:581
#3  0x080cb845 in do_modelmatrix (call=0x8674200, op=0x8212f00, args=0x0, 
    rho=0x8f5eaf8) at model.c:1904
#4  0x080cc6dc in do_internal (call=0x4320, op=0x8204a78, args=0x8f710e8, 
    env=0x8f5eaf8) at names.c:1057
#5  0x080a74d2 in Rf_eval (e=0x86740b0, rho=0x8f5eaf8) at eval.c:375
#6  0x080a905b in do_set (call=0x8674040, op=0x82038c4, args=0x867405c, 
    rho=0x8f5eaf8) at eval.c:1271
#7  0x080a74d2 in Rf_eval (e=0x8674040, rho=0x8f5eaf8) at eval.c:375
#8  0x080a88ce in do_begin (call=0x867a068, op=0x82037c8, args=0x8674008, 
    rho=0x8f5eaf8) at eval.c:1046
#9  0x080a74d2 in Rf_eval (e=0x867a068, rho=0x8f5eaf8) at eval.c:375
#10 0x080a7779 in Rf_applyClosure (call=0x8f5ec80, op=0x867aaf4, 
    arglist=0x8f5ee5c, rho=0x8f5ed60, suppliedenv=0x8f5ecb8) at eval.c:566
#11 0x080cc9af in applyMethod (call=0x8f5ec80, op=0x867aaf4, 
    args=0x8f5ee5c, 
    rho=0x8f5ed60, newrho=0x8f5ecb8) at objects.c:119
#12 0x080cd01c in Rf_usemethod (generic=0x87aaf88 "model.matrix", 
    obj=0x8f5a18c, call=0x867aa14, args=0x81f4998, rho=0x8f5ed60, 
    callrho=0x8f3ab40, defrho=0x8b2a974, ans=0xbfffd288) at objects.c:326
#13 0x080cd4b5 in do_usemethod (call=0x867aa14, op=0x8212308, 
    args=0x867aa30, env=0x8f5ed60) at objects.c:389
#14 0x080a74d2 in Rf_eval (e=0x867aa14, rho=0x8f5ed60) at eval.c:375
#15 0x080a7779 in Rf_applyClosure (call=0x875c02c, op=0x867a838, 
    arglist=0x8f5ee5c, rho=0x8f3ab40, suppliedenv=0x81f4998) at eval.c:566
#16 0x080a72f5 in Rf_eval (e=0x875c02c, rho=0x8f3ab40) at eval.c:410
#17 0x080a905b in do_set (call=0x875be6c, op=0x82038c4, args=0x875bfd8, 
    rho=0x8f3ab40) at eval.c:1271
#18 0x080a74d2 in Rf_eval (e=0x875be6c, rho=0x8f3ab40) at eval.c:375
#19 0x080a88ce in do_begin (call=0x875d598, op=0x82037c8, args=0x875be50, 
    rho=0x8f3ab40) at eval.c:1046
#20 0x080a74d2 in Rf_eval (e=0x875d598, rho=0x8f3ab40) at eval.c:375
#21 0x080a74d2 in Rf_eval (e=0x875da20, rho=0x8f3ab40) at eval.c:375
#22 0x080a88ce in do_begin (call=0x8760a88, op=0x82037c8, args=0x875da04, 
    rho=0x8f3ab40) at eval.c:1046
#23 0x080a74d2 in Rf_eval (e=0x8760a88, rho=0x8f3ab40) at eval.c:375
#24 0x080a7779 in Rf_applyClosure (call=0x8f3ad38, op=0x8760804, 
    arglist=0x8f3ace4, rho=0x821546c, suppliedenv=0x81f4998) at eval.c:566
#25 0x080a72f5 in Rf_eval (e=0x8f3ad38, rho=0x821546c) at eval.c:410
#26 0x080c0eda in Rf_ReplIteration (rho=0x821546c, savestack=136268184, 
    browselevel=0, state=0xbfffdeb0) at main.c:250
#27 0x080c1083 in R_ReplConsole (rho=0x821546c, savestack=0, 
    browselevel=0) at main.c:298
#28 0x080c190f in run_Rmainloop () at main.c:653
#29 0x0812480c in main (ac=1, av=0xbfffe3c4) at system.c:99
(gdb) 



> 

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Breiviksveien 40, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 93 93
e-mail: Roger.Bivand at nhh.no




More information about the R-help mailing list