Dear R-helpers, I have found a slightly annoying problem when trying to plot lines on graphs. I first created my data using tapply, thus:- y1=as.vector(fit1$coef$random$id) x1=tapply(o1,id,median,na.rm=T) x2=tapply(o2,id,median,na.rm=T) #then I plot the data, thus:- plot(x1[x2==0],y[x2==0]) #if I now try to fit the linear regression, R 'hangs up' abline(lm(y[x2==0]~x1[x2==0]),lty='solid') #but, curiously, the problem does not occur if I plot the lowess line lines(lowess(y[x2==0]~x1[x2==0])) I can also avoid the problem by coercing x1 and x2 to be vectors. So, I don't need help to solve the problem. But, it seems an odd problem since it affects one plotting method, but not the other, and it actually causes R to crash. Jonathan Williams OPTIMA Radcliffe Infirmary Woodstock Road OXFORD OX2 6HE Tel +1865 (2)24356
Within the last few weeks, someone else reported a similar problem when using the results of tapply in a call to rlm(). Note that the result of tapply is a 1D array, and it appears there is a general problem with using such a thing on the RHS in formula-based modeling functions: 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 (R 1.8.1 on Windows XP Pro) Rich Raubertas Merck & Co.> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of > Jonathan Williams > Sent: Tuesday, April 27, 2004 1:17 PM > To: Ethz. Ch > Subject: [R] R hang-up using lm > > > Dear R-helpers, > I have found a slightly annoying problem when trying to > plot lines on graphs. I first created my data using > tapply, thus:- > y1=as.vector(fit1$coef$random$id) > x1=tapply(o1,id,median,na.rm=T) > x2=tapply(o2,id,median,na.rm=T) > > #then I plot the data, thus:- > plot(x1[x2==0],y[x2==0]) > #if I now try to fit the linear regression, R 'hangs up' > abline(lm(y[x2==0]~x1[x2==0]),lty='solid') > #but, curiously, the problem does not occur if I plot the lowess line > lines(lowess(y[x2==0]~x1[x2==0])) > > I can also avoid the problem by coercing x1 and x2 to be vectors. > So, I don't need help to solve the problem. But, it seems an odd > problem since it affects one plotting method, but not the other, > and it actually causes R to crash. > > Jonathan Williams > OPTIMA > Radcliffe Infirmary > Woodstock Road > OXFORD OX2 6HE > Tel +1865 (2)24356 > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > >------------------------------------------------------------------------------ Notice: This e-mail message, together with any attachments,...{{dropped}}
Martin Maechler a ??crit :>>>>>>"kjetil" == kjetil <kjetil at acelerate.com> >>>>>> on Tue, 27 Apr 2004 19:19:59 -0400 writes: > > > kjetil> On 27 Apr 2004 at 16:46, Raubertas, Richard wrote: > >> Within the last few weeks, someone else reported a similar > >> problem when using the results of tapply in a call to rlm(). > >> Note that the result of tapply is a 1D array, and it appears > >> there is a general problem with using such a thing on the > >> RHS in formula-based modeling functions: > >> > >> 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 > >> > >> (R 1.8.1 on Windows XP Pro) > >> > > kjetil> What exactly do you mean by "crashes R" > > kjetil> Doing this in R1.9.0, windows XP pro, there is no indication of > kjetil> problems. > > nor is there with 1.9.0 or R-patched on Linux, > nor with R 1.8.1 on Linux. > > no warning, no error, no problem at all. > Is it really the above (reproducible, thank you!) example > that crashes your R 1.8.1 ?It does it for me: Windows XP Pro, R 1.9.0 (P IV, 2.4 GHz, 256 Mo RAM). It freezes RGui and a few seconds later, a Windows message appears saying that Rgui front-end met a problem and must be closed. Best, Renaud -- Dr Renaud Lancelot v??t??rinaire ??pid??miologiste Ambassade de France - SCAC BP 834 Antananarivo 101 Madagascar t??l. +261 (0)32 04 824 55 (cell) +261 (0)20 22 494 37 (home)
On Wed, Apr 28, 2004 at 11:46:51AM +0300, Renaud Lancelot wrote:> Martin Maechler a ??crit : > >>>>>>"kjetil" == kjetil <kjetil at acelerate.com> > >>>>>> on Tue, 27 Apr 2004 19:19:59 -0400 writes: > > > > > > kjetil> On 27 Apr 2004 at 16:46, Raubertas, Richard wrote: > > >> Within the last few weeks, someone else reported a similar > > >> problem when using the results of tapply in a call to rlm(). > > >> Note that the result of tapply is a 1D array, and it appears > > >> there is a general problem with using such a thing on the > > >> RHS in formula-based modeling functions: > > >> > > >> 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 > > >> > > >> (R 1.8.1 on Windows XP Pro) > > >> > > > > kjetil> What exactly do you mean by "crashes R" > > > > kjetil> Doing this in R1.9.0, windows XP pro, there is no indication > > of kjetil> problems. > > > >nor is there with 1.9.0 or R-patched on Linux, > >nor with R 1.8.1 on Linux. > > > >no warning, no error, no problem at all. > >Is it really the above (reproducible, thank you!) example > >that crashes your R 1.8.1 ? > > It does it for me: Windows XP Pro, R 1.9.0 (P IV, 2.4 GHz, 256 Mo RAM). > It freezes RGui and a few seconds later, a Windows message appears > saying that Rgui front-end met a problem and must be closed.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!? G??ran> > Best, > > Renaud > > -- > Dr Renaud Lancelot > v??t??rinaire ??pid??miologiste > Ambassade de France - SCAC > BP 834 Antananarivo 101 > Madagascar > > t??l. +261 (0)32 04 824 55 (cell) > +261 (0)20 22 494 37 (home) > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html-- G??ran Brostr??m tel: +46 90 786 5223 Department of Statistics fax: +46 90 786 6614 Ume?? University http://www.stat.umu.se/egna/gb/ SE-90187 Ume??, Sweden e-mail: gb at stat.umu.se