# Help with partial derivative of a summation

So, I have this function that represents the mean squared error for a multiple regerssion:

$$f(\beta) = \frac{1}{n} \sum(Y_i-B_0-B_1D_i-B_2C_i)^2$$

I am trying to find the partial derivative for $$\beta_0$$ and $$\beta_1$$.

What I got was this for the partial derivative with respect to $$\beta_0$$:

$$\frac{1}{n} \sum2(Y_i-B_0-B_1D_i-B_2C_i)(-1) = \frac{-2}{n} \sum(Y_i-B_0-B_1D_i-B_2C_i)$$

And with respect to $$\beta_1$$:

$$\frac{1}{n} \sum2(Y_i-B_0-B_1D_i-B_2C_i)(-D_i) = \frac{2}{n} \sum{Y_i}\sum{D_i} - \beta_0\sum{D_i} - \beta_1\sum{D_i}\sum{D_i} - \beta_2\sum{C_i}\sum{D_i}$$

Does everything look correct? Thanks!

The first is okay, the second is not correct.

You have performed the partial derivation correctly; they are applications of the chain rule; of the form: $$\dfrac{\partial ~~}{\partial \beta_0}\sum_i(a_i+b_i\beta_0+c_i\beta_1)^2=\sum_i 2b_i(a_i+b_i\beta_0+c_i\beta_1)$$

However, the distribution is not correct. The sum of a product does not equal the product of sums. $$\sum_i X_iY_i\neq \left(\sum_i X_i\right)\left(\sum_i Y_i\right)$$

Just leave everything at the sum of products.