Does anybody know, how to grab the single cooks distance plot that you get from this code:
treatment <- factor(rep(c(1, 2), c(43, 41)), levels = c(1, 2), labels = c("placebo","treated"))
improved <- factor(rep(c(1, 2, 3, 1, 2, 3), c(29, 7, 7, 13, 7, 21)), levels = c(1, 2,3),labels = c("none", "some", "marked"))
numberofdrugs <- rpois(84, 5)+1
healthvalue <- rpois(84,5)
y <- data.frame(healthvalue, numberofdrugs, treatment, improved)
test <- glm(healthvalue~numberofdrugs+treatment+improved, y, family=poisson)
par(mfrow=c(2,2))
plot(test) # how to grab plot 2.1 ?
What I don’t like to have is this
par(mfrow=c(1, 1))
plot(test, which=c(4))
because it doesn’t have residuals on the y axis and leverage on the x axis!
Thanks guys
I’m not quite sure what your problem is. You seem to want the plot with residuals on the y axis and leverage on the x axis. Isn’t that just the 5th (of 6) plot generated:
You can read more about this at ?plot.lm
Edit to address OP’s question about setting y axis labels:
Usually, simply adding ylab=”My Label” to the plot() call would work, but these graphs are designed to be produced “automatically” and so certain graphical parameters are ‘hard coded’. If you pass your own ylab value, you’ll get an error, as plot.lm() will be presented with two ylab’s and won’t know which one to use. If you really don’t like the y axis label, your only option here is to grab the plot.lm code (just type ‘plot.lm’ at the console and hit enter) copy and paste it into a text file and look for this section:
and modify it with your own y axis label. Rename the function (say, plotLMCustomY, or something) and it should work.