How it works...

Cook's D can be obtained using the formula:

This is essentially the square value of the difference between the predicted value for the full model (one with all of the observations) for observation i, and another one omitting observation i. In the denominator, we have the residual standard deviation for the full model times the number of parameters.

The leverage can be obtained by getting the diagonal elements of the so-called hat matrix. It is obtained by applying the same formula to the design matrix.

Get R Statistics Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.