Applying the Gaussian model for generalized linear regression
Generalized Linear Model (GLM) is a generalization of linear regression, which can include a link
function to make a linear prediction. As a default setting, the family object for glm
is Gaussian, which makes the glm
function perform exactly the same as lm
. In this recipe, we first demonstrate how to fit the model into the data using the glm
function, and then show that glm
with a Gaussian model performs exactly the same as lm
.
Getting ready
Check whether the car
library is installed and loaded as we require the SLID dataset from this package.
How to do it...
Perform the following steps to fit a generalized linear regression model with the Gaussian model:
- Fit the independent variables,
age
,sex
, andeducation
, and dependent variable wages toglm
:
> lmfit1 = glm(wages ~ age + sex + education, data = SLID, fami ly=gaussian) > summary(lmfit1) Output: Call: glm(formula = wages ~ age...