Skip to contents

Extract coefficients in terms of the original levels of the coefficients rather than the coded variables.

Usage

rating_factors(
  ...,
  model_data = NULL,
  exposure = NULL,
  exponentiate = TRUE,
  signif_stars = FALSE,
  round_exposure = 0
)

Arguments

...

glm object(s) produced by glm()

model_data

data.frame used to create glm object(s), this should only be specified in case the exposure is desired in the output, default value is NULL

exposure

column in model_data with exposure, default value is NULL

exponentiate

logical indicating whether or not to exponentiate the coefficient estimates. Defaults to TRUE.

signif_stars

show significance stars for p-values (defaults to TRUE)

round_exposure

number of digits for exposure (defaults to 0)

Value

data.frame

Details

A fitted linear model has coefficients for the contrasts of the factor terms, usually one less in number than the number of levels. This function re-expresses the coefficients in the original coding. This function is adopted from dummy.coef(). Our adoption prints a data.frame as output. Use rating_factors_() for standard evaluation.

Author

Martin Haringa

Examples

df <- MTPL2 |>
dplyr::mutate(dplyr::across(c(area), as.factor)) |>
dplyr::mutate(dplyr::across(c(area), ~biggest_reference(., exposure)))

mod1 <- glm(nclaims ~ area + premium, offset = log(exposure),
family = poisson(), data = df)
mod2 <- glm(nclaims ~ area, offset = log(exposure), family = poisson(),
data = df)

rating_factors(mod1, mod2, model_data = df, exposure = exposure)
#>   risk_factor       level  est_mod1  est_mod2 exposure
#> 1 (Intercept) (Intercept) 0.1279538 0.1369930       NA
#> 2        area           0 0.5465581 0.5485629       13
#> 3        area           1 1.0000000 1.0000000     1066
#> 4        area           2 0.8728835 0.8739528      819
#> 5        area           3 1.0762334 1.0782596      765
#> 6     premium     premium 1.0012348        NA       NA