GLM with Gaussian Variance

Let's learn about the generalized linear model with Gaussian variance.

The GLM with Gaussian variance function in R

We’ve demonstrated that the GLM function with the Gaussian variance function and identity link performs an analysis equivalent to the lm() function. In this lesson, we’ll see how to take advantage of its great flexibility.

Let’s model the mean and the variance. We know that the square root transformation produced the best fit in the normal least squares analysis, as was shown by the Box-Cox results. However, with this transformation, the variance increased as the mean increased. We can have the best of both worlds in our GLM if we use a square-root link function in combination with a distribution where the variance increases with the mean. It turns out that, for the gamma distribution, the variance increases as the square of the mean increases. We can fit a GLM with a square-root link and a gamma distribution variance function as follows:

janka.gamma <- glm(hardness ~ dens, data = janka,
    family = Gamma(link = "sqrt"))

We can then use the qplot() function to draw a graph of the resulting model, as shown in the code widget below:

Get hands-on with 1200+ tech skills courses.