# non-constant variance of $\hat{\epsilon}$ against $\hat{y}$

In Faraways Linear Models (2ed.) page 77, he mention: "when non-constant variance is seen in the plot of $$\hat{\epsilon}$$ against $$\hat{y}$$", a transformation of the response $$y$$ to $$h(y)$$ where $$h()$$(a comment on what h() means here is appreciated) can be chosen so that $$\operatorname{var}(h(y))$$ is constant."

Then he gives an example on how to consider $$h$$

$$h(y) = h(Ey) + (y-Ey)h'(Ey)+ \cdots \\ \operatorname{var}(h(y)) = 0+h'(Ey)2\operatorname{var}(y)+ \cdots$$ We ignore higher order terms. For $$var(h(y))$$to be constant we need

$$h'(Ey) \propto (\operatorname{var}(y))^{-\frac{1}{2}}$$ which suggests: $$h(y) = \int\frac{dy}{\operatorname{var}(y)} == \int\frac{dy}{\text{SD}y}$$ (a comment on what the '$$==$$' means here is appreciated).

By an example with R, how exactly would this transformation plan out on data with non-constant variance?

The very next sentence in Faraway gives you two examples:

For example if $$\operatorname{var} y=\operatorname{var}\varepsilon\propto(Ey)^2,$$ then $$h(y)=\log y$$ is suggested while if $$\operatorname{var}\varepsilon\propto(Ey),$$ then $$h(y)=\sqrt{y}.$$

Furthermore, on page 219 you can see an example of the logarithm transformation done in R:

lmodu <- lm(log(longevity) ~ activity, fruitfly)


I imagine the $$==$$ just means "is equivalent to", similar to $$\equiv$$ in logic.

• How do we test for $var(y) = var(\epsilon)$, he uses the example of var.test before this paragraph, but he's testing the variances between residuals. Do we suppose something like var.test(data$response, residuals(lmod)) where lmod is a fitted linear model? Jun 9, 2022 at 20:45 • Faraway prefers, and I think I agree with him, graphical methods to check for constant variance: plot(fitted(lmod), residuals(lmod)) or plot(<predictor>,residuals(lmod)). You're looking for patterns. Does the spread tend to stay the same from left to right? If you see no discernable patterns, that's a good sign for that particular model. Jun 9, 2022 at 20:50 • oh I see, I agree also however I am working on a function that performs the calculations for these test to give some output for decisions prior to plotting. I might have got slightly confused with the notation and misguided myself with the dependent variable and the predictor. Thanks for showing me the example! Jun 9, 2022 at 20:54 • I have an additional question, what does it mean to plot$\hat{\epsilon}$against$x_i$, I understand that$\hat{\epsilon}$is the residuals, and$x_i$are the independent variables? Therefore, plotting the residuals against the variables used in the model, something like plot(data$predictor, residuals(lmod))? But because it's $x_i$ we plot against all the predictors used in the model? <- What is the importance behind this, or perhaps I should open a new post? Jun 9, 2022 at 21:46
• You've got it exactly: plot(data\$predictor, residuals(lmod)), and you're looking for the same thing as when you do plot(fitted(lmod), residuals(lmod)): patterns. If you see random behavior, that's generally good. Jun 10, 2022 at 15:13