trunc_obs {reservr}R Documentation

Define a set of truncated observations

Description

If x is missing, both xmin and xmax must be specified.

Usage

trunc_obs(x, xmin = x, xmax = x, tmin = -Inf, tmax = Inf, w = 1)

as_trunc_obs(.data)

truncate_obs(.data, tmin_new = -Inf, tmax_new = Inf, .partial = FALSE)

repdel_obs(.data, accident, delay, time, .truncate = FALSE)

Arguments

x

Observations

xmin, xmax

Censoring bounds. If xmin != xmax, x must be NA.

tmin, tmax

Truncation bounds. May vary per observation.

w

Case weights

.data

A data frame or numeric vector.

tmin_new

New truncation minimum

tmax_new

New truncation maximum

.partial

Enable partial truncation of censored observations? This could potentially create inconsistent data if the actual observation lies outside of the truncation bounds but the censoring interval overlaps.

accident

accident time (unquoted, evaluated in .data)

delay

reporting delay (unquoted, evaluated in .data)

time

evaluation time (unquoted, evaluated in .data)

.truncate

Should claims reported after time be silently discarded? If there are claims reported after time and .truncate is FALSE, an error will be raised.

Details

Uncensored observations must satisfy tmin <= xmin = x = xmax <= tmax. Censored observations must satisfy ⁠tmin <= xmin < xmax <= tmax⁠ and x = NA.

Value

trunc_obs: A trunc_obs tibble with columns x, xmin, xmax, tmin and tmax describing possibly interval-censored observations with truncation

as_trunc_obs returns a trunc_obs tibble.

truncate_obs returns a trunc_obs tibble with possibly fewer observations than .data and updated truncation bounds.

repdel_obs returns a trunc_obs tibble corresponding to the reporting delay observations of each claim. If .truncate is FALSE, the result is guaranteed to have the same number of rows as .data.

Examples

N <- 100
x <- rexp(N, 0.5)

# Random, observation dependent truncation intervals
tmin <- runif(N, 0, 1)
tmax <- tmin + runif(N, 1, 2)

oob <- x < tmin | x > tmax
x <- x[!oob]
tmin <- tmin[!oob]
tmax <- tmax[!oob]

# Number of observations after truncation
N <- length(x)

# Randomly interval censor 30% of observations
cens <- rbinom(N, 1, 0.3) == 1L
xmin <- x
xmax <- x
xmin[cens] <- pmax(tmin[cens], floor(x[cens]))
xmax[cens] <- pmin(tmax[cens], ceiling(x[cens]))
x[cens] <- NA

trunc_obs(x, xmin, xmax, tmin, tmax)

as_trunc_obs(c(1, 2, 3))
as_trunc_obs(data.frame(x = 1:3, tmin = 0, tmax = 10))
as_trunc_obs(data.frame(x = c(1, NA), xmin = c(1, 2), xmax = c(1, 3)))
truncate_obs(1:10, tmin_new = 2.0, tmax_new = 8.0)

[Package reservr version 0.0.3 Index]