R can find partial residuals for you. If you fit a model, you can use the
residuals function with the argument
type = "partial" to find the partial residuals for each term in the model. That is the residual variation in the response after accounting for all of the other variables in the model. Consider the example from class,
The result is a matrix with one row for every observation and one column for every term in our model. The numbers are the partial residual for the corresponding term in the model. Let’s add those column to our orginal data frame so we can plot them,
Now we can plot them as usual,
Remember, this shows you the relationship between the response, log brain mass, and log gestation length, after accounting for the other variables in the model (log(body mass)).
You might want to compare it to the relationship we see in the raw data
In order to investigate the case influence statistics, we will first extract the relevant quantities from the fitted model and store them in a new data.frame,
stdresid contain the leverage, Cook’s Distance and Studentized residuals respectively. It’s often useful to add a column that just indexes the observations:
Let’s take a look:
Statisticians use rough cutoffs of 2p/n (p is the number of parameters in the model) for leverage, 1 for Cook’s Distance and above 2 or below -2 for standardized residuals. Observations falling outside these ranges warrant further attention.
** Do any points warrant further investigation?**
We might want to investigate certain points, for example, which observations have a studentized residual greater than 2, this is easily achevied with subsetting:
Dolphins and human beings have log brain sizes that fall quite far above our line for the mean log brain size. We could also look for points with large negative studentized residuals:
** Subset out the two observations with the highest leverage?**
You can get all three plots on one page with:
Take a look at this data set, where
Y is the reponse and
X2 two explanatory variables:
We fit the model:
Would you expect the point highlighted to have high leverage, Cook’s Distance and/or studentized residuals?
Check your reasoning by plotting this: