Why are the contours of a linear regression residual sum of squares an ellipse? For the linear regression RSS:
$$
RSS = \sum_{i=1}^{n}\left(Y_i-\sum_{j=1}^{p} X_{ij}\beta_j\right)^2
$$
by decomposing it we have something like
$$
\beta_1^2X_{ij}^2 - \beta_2^2X_{ij}^2 - \beta_1X_{ij}Y_{i} - \beta_2X_{ij}Y_{i} + ....
$$
so that the terms are squared in the beta's. I have often seen plots of $\beta_1$ on the x-axis and $\beta_2$ on the y-axis being contours like

How exactly are these red circles constructed? Thank you
 A: Say we are in a simple linear regression setting, so $\beta = \left(\beta_1,\beta_2\right)$ and $Y_i = \beta_1 + X_i\beta_2 + \epsilon_i$ where $\epsilon_i ~ \sim N\left(0,1\right)$ then
\begin{align}
RSS & = \sum_{i=1}^{n}\left(Y_i - \beta_1 - X_i\beta_2 \right)^2\\
& =\sum_{i=1}^{n}\left( Y_i^2 - Y_i\beta_1 -Y_i X_i \beta_2 + 2\beta_1 X_i \beta_2 + \beta_1^2 + X_i^2\beta_2^2\right) \\
& = \sum_{i=1}^{n} Y_i^2 - \beta_1 \sum_{i=1}^{n} Y_i - \beta_2 \sum_{i=1}^{n} Y_i X_i + 2\beta_1\beta_2 \sum_{i=1}^{n} X_i + n\beta_1^2 + \beta_2^2 \sum_{i=1}^{n} X_i^2
\end{align}
Which is of the form
\begin{align}
A\beta_1^2 + B\beta_1\beta_2 + C\beta_2^2 + D\beta_1 + E\beta_2 + F = 0
\end{align}
for a fixed value of RSS. This is the equation of a conic https://en.wikipedia.org/wiki/Conic_section and we can find what type by considering the discriminant
\begin{align}
B^2 - 4AC & = \left(2\sum_{i=1}^{n}X_i\right)^2 - 4n\sum_{i=1}^n X_i^2 \\
& = -4 \left[ \left(\sum_{i=1}^n X_i\right)^2 - n \sum_{i=1}^n X_i^2 \right] \\
& = -4 \left[ \sum_{i = 1}^n \left( X_i - \sum_{i = 1}^n X_i \right)^2 \right] \leq 0
\end{align}
So assuming the $X_i$ are not all equal, the discriminant is strictly less than 0, and the equation gives an ellipse.
