This function is a wrapper around stats::glm() that uses a column from
data as an offset.
Arguments
- formula
A model formula
- family
A function or character string describing the link function and error distribution.
- data
Optional. A data frame containing variables used in the model.
- offset_col
Character string. The name of a column in
datacontaining offsets.- weights
Optional weights to use in the fitting process.
Value
A glm object. See stats::glm() for full details.
Details
Outside of the tidymodels ecosystem, glm_offset() has no advantages over
stats::glm() since that function allows for offsets to be specified
in the formula interface or its offset argument.
Within tidymodels, glm_offset() provides an advantage because it will
ensure that offsets are included in the data whenever resamples are created.
The formula, family, data, and weights arguments have the same
meanings as stats::glm(). See that function's documentation for full
details.
Examples
us_deaths$off <- log(us_deaths$population)
glm_offset(deaths ~ age_group + gender, family = "poisson",
us_deaths, offset_col = "off")
#>
#> Call: stats::glm(formula = formula, family = family, data = data, weights = weights,
#> offset = offset)
#>
#> Coefficients:
#> (Intercept) age_group35-44 age_group45-54 age_group55-64 age_group65-74
#> -6.8842 0.4426 1.2114 1.9908 2.7147
#> age_group75-84 age_group85+ genderMale
#> 3.6465 4.7707 0.3280
#>
#> Degrees of Freedom: 139 Total (i.e. Null); 132 Residual
#> Null Deviance: 51700000
#> Residual Deviance: 245000 AIC: 246900