[R] Plotting lm() attributes

Murray Jorgensen maj at stats.waikato.ac.nz
Wed Nov 12 23:40:03 CET 2003


Suppose you fit a linear model

 > model.1 ~ lm(v1 ~ ..., data=myframe)

and v2 is some other column of myframe typically not in the model. You 
will often want to try

 > plot(v2, model.1$residuals)

but this will fail if there are NAs in the response v1 as 
model.1$residuals has length equal to the number of nonmissing values in 
  v1. I suppose

 > plot(v2[!is.na(v1)], model.1$residuals)

does the job, but it seems irritating that model.1$residuals, does not 
have length agreeing with the number of rows in the data frame. It would 
be even more irritating for model.1$fitted.values, where the removed 
elements would often have nonmissing values.

Murray

-- 
Dr Murray Jorgensen      http://www.stats.waikato.ac.nz/Staff/maj.html
Department of Statistics, University of Waikato, Hamilton, New Zealand
Email: maj at waikato.ac.nz                                Fax 7 838 4155
Phone  +64 7 838 4773 wk    +64 7 849 6486 home    Mobile 021 1395 862




More information about the R-help mailing list