Cook's Distance

The formula of Cook's distance is $$D_i=\frac{(\hat Y-\hat Y(i))^{\prime}(\hat Y-\hat Y(i))}{p\times MSE}$$

where, $\hat Y$ is the prediction from the full regression model and $\hat Y$ is a $(n\times 1)$ matrix

$\hat Y(i)$ is the prediction from a refitted regression model in which observation $i$ has been omitted. That is , $\hat Y(i)$ is a $((n-1)\times 1)$ matrix.

So the order of $\hat Y$ and $\hat Y(i)$ is not same. Then How can i subtract this two matrix since for subtracting we need equal order of two matrices.

-

You can exclude the $i{^\mathrm{th}}$ observation while estimating the model and include it again when predicting $\hat{Y}(i)$, thus resulting in a matrix of the same order as $\hat{Y}$.