Thank you for indicating more precisely where the bug arises. I disagree with the blanket assertion that the I() is not needed. The example is purposely simplified to illustrate the problem, which lm has no difficulty with but which plot.lm does. plot.lm manages to deal with I() on the right side, why doesn't it deal similarly with the left side?
--------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN:<jdnew...@dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity. Peter Ehlers <ehl...@ucalgary.ca> wrote: On 2011-03-11 11:31, David Winsemius wrote: > On Mar 11, 2011, at 2:06 PM, Jeff Newmiller wrote: > >> > I am encountering an error with plot.lm: >> > >>> >> tstdf<- data.frame( y=c(1.01,1.98,3.02,3.99),x=c(1,2,3,4)) >>> >> plot(lm(I(y) ~ x, data=tstdf)) >> > Hit<Return> to see next plot: >> > Hit<Return> to see next plot: >> > Error in object$coefficients : $ operator is invalid for atomic >> > vectors >> > >> > Obviously I don't need the I() in this example, but I have been >> > working >> > with regressions that involve an expression on the left side of the >> > formula, for which I do need the I(). > Are you sure you need I() on the LHS? The I function is designed to > avoid the confusion related to the dual use of the arithmetic > operator symbols affecting the construction of the model matrix, but I > don't think that applies to the LHS of the formula. > > (See Dalgaard's commentshttp://finzi.psych.upenn.edu/Rhelp10/2009-March/192018.html > if desiring higher authority.) Agreed that I() is not needed. For anyone interested in why the (non)problem arises: the residuals component of the model will have a class attribute ("AsIs") which causes abline() (called by qqline()) to choke. Peter Ehlers > > -- David. >> > I can work around by declaring a new actual column with the computed >> > result, but this seems otherwise unnecessary. >> > >> > Is this behaviour intended? >> > >>> >> R.Version() >> > $platform >> > [1] "i386-pc-mingw32" >> > >> > $arch >> > [1] "i386" >> > >> > $os >> > [1] "mingw32" >> > >> > $system >> > [1] "i386, mingw32" >> > >> > $status >> > [1] "" >> > >> > $major >> > [1] "2" >> > >> > $minor >> > [1] "12.1" >> > >> > $year >> > [1] "2010" >> > >> > $month >> > [1] "12" >> > >> > $day >> > [1] "16" >> > >> > $`svn rev` >> > [1] "53855" >> > >> > $language >> > [1] "R" >> > >> > $version.string >> > [1] "R version 2.12.1 (2010-12-16)" >> > >> > >> >_____________________________________________ >> > Jeff Newmiller The ..... ..... Go >> > Live... >> > >> > DCN:<jdnew...@dcn.davis.ca.us> Basics: ##.#. ##.#. >> > Live Go... >> > >> > Live: OO#.. Dead: OO#.. >> > Playing >> > Research Engineer >> > (Solar/Batteries O.O#. #.O#. with >> > /Software/Embedded Controllers) >> > .OO#. .OO#. >> > rocks...1k >> > >> >> > >_____________________________________________ >> > R-help@r-project.org mailing list >> > >> > https://stat.ethz.ch/mailman/listinfo/r-help >> > PLEASE do read the >> > posting guidehttp://www.R-project.org/posting-guide.html >> > and provide >> > commented, minimal, self-contained, reproducible code. > David Winsemius, >> > MD > West Hartford, CT > >_____________________________________________ > R-help@r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting > guidehttp://www.R-project.org/posting-guide.html > and provide commented, > minimal, self-contained, reproducible code. [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.