Solution (source code)

= Solution

Let $\widehat\beta_{(i)}$ be the least-squares estimate after deleting observation $i$, and put $\widehat Y=X\widehat\beta$ and $\widehat Y_{(i)}=X\widehat\beta_{(i)}$. <Cook's distance> is
$$
\boxed{
D_i
=\frac{\|\widehat Y_{(i)}-\widehat Y\|^2}
 {p\widehat\sigma^2}
=\frac{(\widehat\beta_{(i)}-\widehat\beta)^TX^TX
 (\widehat\beta_{(i)}-\widehat\beta)}
 {p\widehat\sigma^2}
}.
$$
Thus $D_i$ is the squared displacement caused by deleting observation $i$, measured in the same $X^TX$ metric and scale as the confidence ellipsoid. In particular, $\widehat\beta_{(i)}$ lies outside the $(1-\alpha)$ ellipsoid centered at $\widehat\beta$ exactly when
$$
D_i>F_{p,n-p}(1-\alpha).
$$