[R] Error in plot.lm

David Winsemius dwinsemius at comcast.net
Fri Mar 11 20:31:21 CET 2011


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 comments http://finzi.psych.upenn.edu/Rhelp10/2009-March/192018.html 
  if desiring higher authority.)

-- 
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:<jdnewmil at 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 at 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.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list