Learn R Programming

insurancerating (version 0.6.3)

rating_factors: Include reference group in regression output

Description

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 = TRUE
)

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 the coefficient estimates. Defaults to TRUE.

signif_stars

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

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.

Examples

Run this code
# NOT RUN {
library(dplyr)
df <- MTPL2 %>%
    mutate_at(vars(area), as.factor) %>%
    mutate_at(vars(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)

# }

Run the code above in your browser using DataLab