# Run model
lm1 <- lm(log10(body)~log10(brain), data=Animals)
# Setup 2x2 graphics device
# Plot diagnostics, label the two most "extreme" points based on magnitude of residuals
Explanation of resulting plots:
Notice that the one of the two extreme points corresponding to the two largest dinosaurs
are labelled unintuitively, or counter to what is stated in the documentation for the
label.pos: positioning of labels, for the left half and right half of the graph
respectively, for plots 1-3.
The default value for this argument is c(4,2), where 4 means "to the right of" and 2
means "to the left of" as stated in the help page for text (see the 'pos' argument).
The Q-Q plot positions the label for Dipliodocus "to the right", but clearly it should
be placed "to the left" since it is clearly on the right half of the graph. Similarly
for the Leverage plot, the label for Brachiosaurus is placed "to the left" when clearly
it should be placed "to the right".
Reason for error and possible patch:
The fix is hard to explain, because changes are required in many places.
On line 85 (or thereabouts) of the plot.lm function, there is a function called text.id
which does the labelling:
And the repeated calls to this function are changed so that the choice of position is
based on whether the extreme points are greater than the mean of the range of ALL the
data points, not just the extreme ones as it is currently doing. For example, at line
145 for the Q-Q plot (which==2), the [show.rs] index should be removed in the first two
arguments, so the code should be:
text.id(qq$x, qq$y, show.rs)
and similar changes are required for plots 3, 4, and 5. For plots 1 and 6, the following
changes are needed:
I tested these changes and they seem to work without breaking anything. If you want me
to make a patch, then I can try. But I thought that these changes were quite significant
and better left to the experts.
Hope that all makes sense.
Prince of Songkla University,