2
$\begingroup$

Exercise :

Prove that for the generalized linear model, it is : $$\sum_{i=1}^n (y_i-\hat{y_i})(\hat{y_i} - \bar{y}) = 0$$

Question : How would one proceed with proving that for the generalized linear model ? I can prove it for the simple linear model but I seem to be stuck a bit for the generalized case.

$\endgroup$
3
  • $\begingroup$ Work on $\sum_{i=1}^n (y_i-\hat{y_i})(\hat{y_i} - \bar{y}) = (Y-\hat Y)'(\hat Y - \bar Y)$. $\endgroup$
    – user158565
    Commented Oct 30, 2018 at 19:12
  • $\begingroup$ @a_statistician If $ Y = X\beta + \epsilon$ then $\bar{Y} = \bar{X}\beta + \epsilon$ and $\hat{Y} = X\hat{\beta} + \hat{\epsilon}$ and then it is : $$(Y-\hat Y)'(\hat Y - \bar Y) = (X\beta + \epsilon - X\hat{\beta} + \hat{\epsilon})'(X\hat{\beta} + \hat{\epsilon}- \bar{X}\beta + \epsilon)$$ Now, what ? $\endgroup$
    – Rebellos
    Commented Oct 30, 2018 at 19:34
  • $\begingroup$ Generalized linear model can be ambiguous. What type of generalized linear model are you referring to? $\endgroup$ Commented Oct 30, 2018 at 22:57

2 Answers 2

1
$\begingroup$

In the linear model, $Y=X\beta +\epsilon$, $\hat \beta = (X'X)^{-1}X'Y$ and $\hat Y = X\hat \beta = X(X'X)^{-1}X'Y$

$\sum_{i=1}(y_i−\hat y_i)(\hat y_i−\bar y)=(Y−\hat Y)′(\hat Y−\bar Y) = Y'(I-H)(H-\frac 1 n J)Y = Y'(I-H)HY - Y(I-H)\frac 1 n JY $

where $H=X(X'X)^{-1}X'$ , and $J$ is matrix with elements 1.

$Y'(I-H)HY = Y'(H-HH)Y =0$

$Y'(I-H)\frac 1 n JY = Y'(I-H) \bar Y = \bar Y \sum_{i=1}(y_i−\hat y_i) = 0$

So $\sum_{i=1}(y_i−\hat y_i)(\hat y_i−\bar y) = 0$

$\endgroup$
4
  • 1
    $\begingroup$ Isn't the H matrix that you use for OLS instead of GLM? $\endgroup$ Commented Oct 30, 2018 at 20:56
  • $\begingroup$ $H=X(X'X)^{-1}X'$. I do not know it belongs to OLS or GLM or both. I think this conclusion just correct for general linear model. $\endgroup$
    – user158565
    Commented Oct 30, 2018 at 21:07
  • 2
    $\begingroup$ The conclusion might be correct but the $H$ that you use is the perpendicular projection matrix (shortest distance) which associates to least squares and Gaussian error distribution. It is not in general related to generalized linear models. $\endgroup$ Commented Oct 30, 2018 at 21:10
  • $\begingroup$ @MartijnWeterings Then how should be the correct approach ? $\endgroup$
    – Rebellos
    Commented Oct 30, 2018 at 21:24
1
$\begingroup$

$$\begin{array}{rcl} \sum_{i=1}^n (y_i-\hat{y_i})(\hat{y_i} - \bar{y}) = \sum_{i=1}^n \epsilon_i(\hat{y_i} - \bar{y}) = \underbrace{\sum_{i=1}^n \epsilon_i \hat{y_i}}_{\text{ equals zero if } \epsilon \perp \hat{y} } &-& \bar{y_i}\underbrace{ \sum_{i=1}^n \epsilon_i}_{ \text{equals zero} } \end{array}$$

I do not believe that you have $\epsilon \perp \hat{y}$ for GLM, this is only the case if you have the residual vector represent the shortest distance between $y$ and the solution space of all possible $\hat{y}$, which is the least squares solution and relates to the assumption of Gaussian distributed errors.

Neither is $ \sum_{i=1}^n \epsilon_i = 0 $ general. This means $\epsilon$ is perpendicular to the intercept term. Even in the case of a simple linear model this may not be true (simple linear regression without the intercept term).


(Computational) counter-examples:

> # some data
> x <- c(1.0, 2.0, 3.0, 4.0)
> y <- c(1.1, 2.1, 3.2, 4.0)
> 
> # OLS (minimize squared errors)
> hat_y <- predict(lm(y~x))
> sum((y-hat_y)*(hat_y-mean(y)))
[1] 6.366435e-16
> 
> # GLM (using Gamma)
> hat_y <- predict(glm(y~x, family = Gamma(link="identity")),type="response")
> sum((y-hat_y)*(hat_y-mean(y)))
[1] -0.1042444
> 
> # GLM (using Gaussian but different link)
> hat_y <- predict(glm(y~x, family = gaussian(link="log")),type="response")
> sum((y-hat_y)*(hat_y-mean(y)))
[1] 0.1504989
>
> # OLS without intercept term
> hat_y <- predict(lm(y~0+x))
> sum((y-hat_y)*(hat_y-mean(y)))
[1] -0.26
$\endgroup$
2
  • $\begingroup$ Interesting and indeed true. I assume the exercise wants us to work under the assumption of Gaussian distributed errors regarding a fitted generalized model, but that isn't mentioned, so I guess your statement is perfect ! $\endgroup$
    – Rebellos
    Commented Oct 30, 2018 at 22:26
  • $\begingroup$ Even if you consider only the link function : $$Y = g(X\beta) + \epsilon$$ with $\epsilon \sim N(0,\sigma^2)$, I do not think it works here as well. $\endgroup$ Commented Oct 30, 2018 at 22:29

Not the answer you're looking for? Browse other questions tagged or ask your own question.