Plot which parameter where in R?
Asked Answered
E

1

5

So... I'm looking at an example in a book that goes something like this:

library(daewr)
mod1 <- aov(height ~ time, data=bread)
summary(mod1)
...
par(mfrow=c(2,2))
plot(mod1, which=5)
plot(mod1, which=1)
plot(mod1, which=2)
plot(residuals(mod1) ~ loaf, main="Residuals vs Exp. Units", font.main=1, data=bread)
abline(h = 0, lty = 2)

That all works... but the text is a little vague about the purpose of the parameter 'which='. I dug around in the help (in Rstudio) on plot() and par(), looked around online... found some references to a different 'which()'... but nothing really referring me to the purpose/syntax for the parameter 'which=' inside plot().

A bit later (next page, figures) I found a mention of using names(mod1) to view the list of quantities calculated by aov... which I presume is what which= is refering to, i.e. which item in the list to plot where in the 2x2 matrix of plots. Yay. Now where the heck is that buried in the docs?!?

Earnest answered 14/3, 2015 at 0:27 Comment(5)
Look at class(mod1) and then search for the appropriate method in either methods(thatclass) or showMethods(class="thatclass"). Then read the help page for the function. Or perhaps just do this: help(plot, pack=daewr)Clarance
class(mod1) returns "aov" "lm". methods(lm) and methods(aov) didn't pan out. showMethods() for either didn't work, just complained that they weren't S4 generic functions. methods(lm) yielded something, but not quite. methods(plot) yielded another list... including plot.lm. help(plot.lm) yielded the answer I was looking for. Kind of a round-about way of finding what seems like it should have been a lot easier... but it worked. Thanks!Earnest
So, if you look at output from methods(plot) and see nothing for 'plot.aov' and do see a 'plot.lm' (perhaps with an asterisk after it if it is not "exported"), then you know that the mod1-object will be given to a function actually named plot.lm. So type ?plot.lm at the console and your question will be answered.Clarance
Thought that was pretty much what I said... ;)Earnest
It sounded to me that you were looking at the help page for plot.default and could not find the listing of the which parameter on the help page. At the top of the plot.lm help page is a listing of the six plots returned by plot.lm and then which is described as a vector containing one or more of the numbers corresponding to those descriptions. Further details are in the Details section. It's unclear what more is needed.Clarance
B
10

which selects which plot to be displayed:

  1. A plot of residuals against fitted values
  2. A normal Q-Q plot
  3. A Scale-Location plot of sqrt(| residuals |) against fitted values
  4. A plot of Cook's distances versus row labels
  5. A plot of residuals against leverages
  6. A plot of Cook's distances against leverage/(1-leverage)

By default, the first three and 5 are provided.

Check ?plot.lm in r for more details.

Brightman answered 18/4, 2017 at 18:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.