construct_model_points {insurancerating}R Documentation

Construct model points from Generalized Linear Model

Description

[Experimental] construct_model_points() is used to construct model points from generalized linear models, and must be preceded by model_data(). construct_model_points() can also be used in combination with a data.frame.

Usage

construct_model_points(
  x,
  exposure = NULL,
  exposure_by = NULL,
  agg_cols = NULL,
  drop_na = FALSE
)

Arguments

x

Object of class model_data or of class data.frame

exposure

column with exposure

exposure_by

split column exposure by (e.g. year)

agg_cols

list of columns to aggregate (sum) by, e.g. number of claims

drop_na

drop na values (default to FALSE)

Value

data.frame

Author(s)

Martin Haringa

Examples

## Not run: 
# With data.frame
library(dplyr)
mtcars |>
 select(cyl, vs) |>
 construct_model_points()

mtcars |>
  select(cyl, vs, disp) |>
  construct_model_points(exposure = disp)

mtcars |>
 select(cyl, vs, disp, gear) |>
 construct_model_points(exposure = disp, exposure_by = gear)

mtcars |>
 select(cyl, vs, disp, gear, mpg) |>
 construct_model_points(exposure = disp, exposure_by = gear,
   agg_cols = list(mpg))

# With glm
library(datasets)
data1 <- warpbreaks |>
 mutate(jaar = c(rep(2000, 10), rep(2010, 44))) |>
 mutate(exposure = 1) |>
 mutate(nclaims = 2)

pmodel <- glm(breaks ~ wool + tension, data1, offset = log(exposure),
 family = poisson(link = "log"))

model_data(pmodel) |>
 construct_model_points()

model_data(pmodel) |>
 construct_model_points(agg_cols = list(nclaims))

model_data(pmodel) |>
 construct_model_points(exposure = exposure, exposure_by = jaar) |>
 add_prediction(pmodel)
 
## End(Not run)


[Package insurancerating version 0.7.4 Index]