Reputation: 21
I'm trying to produce a scale-location plot for a negative binomial model in R. Ideally, this graph will plot the square root of the standardized Pearson residuals on the y-axis. However, in my case, the y-axis is labelled as "standardized Deviance residuals". I can't seem to be able to coerce this in any way.
It's concerning, as my friend running the exact same code obtains a different plot, as his plot (correctly, for our purposes) uses the standardized Pearson residuals for the scale-location plot.
I was hoping it would be an easy fix to write, for example:
plot(glm.out, 3, type = "pearson")
Or something of the sort, but after investigating all possible arguments of the plot.lm function, I've been unable to find a way to specify this.
I've been unable to find anyone with a similar problem online.
Has anyone encountered this issue before, and if so, have you found an easy fix?
Thanks in advance!
Upvotes: 2
Views: 337
Reputation: 3335
I couldn't find an option in plot.glm
to choose the type of residual either. However, it is not so difficult to create a Scale-Location plot yourself by accessing the residuals using the residuals
function (to access the help file, go from ?plot.lm
to residuals
). You can specify pearson, deviance, working, etc.
clotting <- data.frame(
u = c(5,10,15,20,30,40,60,80,100),
lot1 = c(118,58,42,35,27,25,21,19,18),
lot2 = c(69,35,26,21,18,16,13,12,12))
m=glm(lot1 ~ log(u), data = clotting, family = Gamma)
par(mfrow=c(3,2))
plot(m)
f = fitted(m)^(-1)
pearson = residuals(m, type="pearson")
stdpearson = sqrt(abs(scale(pearson)))
stdpearson[1] = 1.6
plot(f, stdpearson, main="Scale-Location", xlab="Predicted values", ylab=expression(sqrt("|Std. Pearson resid|")))
ss5 = smooth.spline(f, stdpearson, df=5)
lines(ss5, lty=2, col="red")
Upvotes: 2