In statistics, Cook's distance or Cook's D is a commonly used estimate of the influence of a data point when performing a least-squares regression analysis. In a practical ordinary least squares analysis, Cook's distance can be used in several ways: to indicate influential data points that are particularly worth checking for validity; or to indicate regions of the design space where it would be good to be able to obtain more data points. It is named after the American statistician R. Dennis Cook, who introduced the concept in 1977.
Data points with large residuals (outliers) and/or high leverage may distort the outcome and accuracy of a regression. Cook's distance measures the effect of deleting a given observation. Points with a large Cook's distance are considered to merit closer examination in the analysis.
For the algebraic expression, first define
where ε ∼ N ( 0 , σ 2 I ) {\displaystyle {\boldsymbol {\varepsilon }}\sim {\mathcal {N}}\left(0,\sigma ^{2}\mathbf {I} \right)} is the error term, β = [ β 0 β 1 … β p − 1 ] T {\displaystyle {\boldsymbol {\beta }}=\left[\beta _{0}\,\beta _{1}\dots \beta _{p-1}\right]^{\mathsf {T}}} is the coefficient matrix, p {\displaystyle p} is the number of covariates or predictors for each observation, and X {\displaystyle \mathbf {X} } is the design matrix including a constant. The least squares estimator then is b = ( X T X ) − 1 X T y {\displaystyle \mathbf {b} =\left(\mathbf {X} ^{\mathsf {T}}\mathbf {X} \right)^{-1}\mathbf {X} ^{\mathsf {T}}\mathbf {y} } , and consequently the fitted (predicted) values for the mean of y {\displaystyle \mathbf {y} } are
where H ≡ X ( X T X ) − 1 X T {\displaystyle \mathbf {H} \equiv \mathbf {X} (\mathbf {X} ^{\mathsf {T}}\mathbf {X} )^{-1}\mathbf {X} ^{\mathsf {T}}} is the projection matrix (or hat matrix). The i {\displaystyle i} -th diagonal element of H {\displaystyle \mathbf {H} \,} , given by h i i ≡ x i T ( X T X ) − 1 x i {\displaystyle h_{ii}\equiv \mathbf {x} _{i}^{\mathsf {T}}(\mathbf {X} ^{\mathsf {T}}\mathbf {X} )^{-1}\mathbf {x} _{i}} , is known as the leverage of the i {\displaystyle i} -th observation. Similarly, the i {\displaystyle i} -th element of the residual vector e = y − y ^ = ( I − H ) y {\displaystyle \mathbf {e} =\mathbf {y} -\mathbf {\widehat {y\,}} =\left(\mathbf {I} -\mathbf {H} \right)\mathbf {y} } is denoted by e i {\displaystyle e_{i}} .
Cook's distance D i {\displaystyle D_{i}} of observation i ( for i = 1 , … , n ) {\displaystyle i\;({\text{for }}i=1,\dots ,n)} is defined as the sum of all the changes in the regression model when observation i {\displaystyle i} is removed from it
where p is the rank of the model (i.e., number of independent variables in the design matrix) and y ^ j ( i ) {\displaystyle {\widehat {y\,}}_{j(i)}} is the fitted response value obtained when excluding i {\displaystyle i} , and s 2 = e ⊤ e n − p {\displaystyle s^{2}={\frac {\mathbf {e} ^{\top }\mathbf {e} }{n-p}}} is the mean squared error of the regression model.
Equivalently, it can be expressed using the leverage ( h i i {\displaystyle h_{ii}} ):
There are different opinions regarding what cut-off values to use for spotting highly influential points. Since Cook's distance is in the metric of an F distribution with p {\displaystyle p} and n − p {\displaystyle n-p} (as defined for the design matrix X {\displaystyle \mathbf {X} } above) degrees of freedom, the median point (i.e., F 0.5 ( p , n − p ) {\displaystyle F_{0.5}(p,n-p)} ) can be used as a cut-off. Since this value is close to 1 for large n {\displaystyle n} , a simple operational guideline of D i > 1 {\displaystyle D_{i}>1} has been suggested.
Note that in general the Cook's distance does not measure correctly the influence of observations.
D i {\displaystyle D_{i}} can be expressed using the leverage ( 0 ≤ h i i ≤ 1 {\displaystyle 0\leq h_{ii}\leq 1} ) and the square of the internally Studentized residual ( 0 ≤ t i 2 {\displaystyle 0\leq t_{i}^{2}} ), as follows:
The benefit in the last formulation is that it clearly shows the relationship between t i 2 {\displaystyle t_{i}^{2}} and h i i {\displaystyle h_{ii}} to D i {\displaystyle D_{i}} (while p and n are the same for all observations). If t i 2 {\displaystyle t_{i}^{2}} is large then it (for non-extreme values of h i i {\displaystyle h_{ii}} ) will increase D i {\displaystyle D_{i}} . If h i i {\displaystyle h_{ii}} is close to 0 then D i {\displaystyle D_{i}} will be small, while if h i i {\displaystyle h_{ii}} is close to 1 then D i {\displaystyle D_{i}} will become very large (as long as t i 2 > 0 {\displaystyle t_{i}^{2}>0} , i.e.: that the observation i {\displaystyle i} is not exactly on the regression line that was fitted without observation i {\displaystyle i} ).
D i {\displaystyle D_{i}} is related to DFFITS through the following relationship (note that σ ^ σ ^ ( i ) t i = t i ( i ) {\displaystyle {{\widehat {\sigma }} \over {\widehat {\sigma }}_{(i)}}t_{i}=t_{i(i)}} is the externally studentized residual, and σ ^ , σ ^ ( i ) {\displaystyle {\widehat {\sigma }},{\widehat {\sigma }}_{(i)}} are defined here):
D i {\displaystyle D_{i}} can be interpreted as the distance one's estimates move within the confidence ellipsoid that represents a region of plausible values for the parameters.[clarification needed] This is shown by an alternative but equivalent representation of Cook's distance in terms of changes to the estimates of the regression parameters between the cases, where the particular observation is either included or excluded from the regression analysis.
An alternative to D i {\displaystyle D_{i}} has been proposed. Instead of considering the influence a single observation has on the overall model, the statistics S i {\displaystyle S_{i}} serves as a measure of how sensitive the prediction of the i {\displaystyle i} -th observation is to the deletion of each observation in the original data set. It can be formulated as a weighted linear combination of the D j {\displaystyle D_{j}} 's of all data points. Again, the projection matrix is involved in the calculation to obtain the required weights:
In this context, ρ i j {\displaystyle \rho _{ij}} ( ≤ 1 {\displaystyle \leq 1} ) resembles the correlation between the predictions y ^ i {\displaystyle {\widehat {y\,}}_{i}} and y ^ j {\displaystyle {\widehat {y\,}}_{j}} . In contrast to D i {\displaystyle D_{i}} , the distribution of S i {\displaystyle S_{i}} is asymptotically normal for large sample sizes and models with many predictors. In absence of outliers the expected value of S i {\displaystyle S_{i}} is approximately p − 1 {\displaystyle p^{-1}} . An influential observation can be identified if
with med ⁡ ( S ) {\displaystyle \operatorname {med} (S)} as the median and MAD ⁡ ( S ) {\displaystyle \operatorname {MAD} (S)} as the median absolute deviation of all S {\displaystyle S} -values within the original data set, i.e., a robust measure of location and a robust measure of scale for the distribution of S i {\displaystyle S_{i}} . The factor 4.5 covers approx. 3 standard deviations of S {\displaystyle S} around its centre. When compared to Cook's distance, S i {\displaystyle S_{i}} was found to perform well for high- and intermediate-leverage outliers, even in presence of masking effects for which D i {\displaystyle D_{i}} failed. Interestingly, D i {\displaystyle D_{i}} and S i {\displaystyle S_{i}} are closely related because they can both be expressed in terms of the matrix T {\displaystyle \mathbf {T} } which holds the effects of the deletion of the j {\displaystyle j} -th data point on the i {\displaystyle i} -th prediction:
With T {\displaystyle \mathbf {T} } at hand, D {\displaystyle \mathbf {D} } is given by:
where H T H = H {\displaystyle \mathbf {H} ^{\mathsf {T}}\mathbf {H} =\mathbf {H} } if H {\displaystyle \mathbf {H} } is symmetric and idempotent, which is not necessarily the case. In contrast, S {\displaystyle \mathbf {S} } can be calculated as:
where diag ⁡ ( A ) {\displaystyle \operatorname {diag} (\mathbf {A} )} extracts the main diagonal of a square matrix A {\displaystyle \mathbf {A} } . In this context, M = p − 1 s − 2 G E H T H E G {\displaystyle \mathbf {M} =p^{-1}s^{-2}\mathbf {G} \mathbf {E} \mathbf {H} ^{\mathsf {T}}\mathbf {H} \mathbf {E} \mathbf {G} } is referred to as the influence matrix whereas P = p − 1 s − 2 H E G G E H T {\displaystyle \mathbf {P} =p^{-1}s^{-2}\mathbf {H} \mathbf {E} \mathbf {G} \mathbf {G} \mathbf {E} \mathbf {H} ^{\mathsf {T}}} resembles the so-called sensitivity matrix. An eigenvector analysis of M {\displaystyle \mathbf {M} } and P {\displaystyle \mathbf {P} } - which both share the same eigenvalues – serves as a tool in outlier detection, although the eigenvectors of the sensitivity matrix are more powerful.
Many programs and statistics packages, such as R, Python, Julia, etc., include implementations of Cook's distance.
High-dimensional Influence Measure (HIM) is an alternative to Cook's distance for when p > n {\displaystyle p>n} (i.e., when there are more predictors than observations). While the Cook's distance quantifies the individual observation's influence on the least squares regression coefficient estimate, the HIM measures the influence of an observation on the marginal correlations.
A general class of influence measures for multivariate linear models with several response variable has been given by Barrett & Ling (1992). These are implemented for R in the mvinfluence package
Outlier
Leverage (statistics)
Partial leverage
DFFITS
Studentized residual
