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 beNA
.- 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 aftertime
and.truncate
isFALSE
, an error will be raised.
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
.
Details
Uncensored observations must satisfy tmin <= xmin = x = xmax <= tmax
.
Censored observations must satisfy tmin <= xmin < xmax <= tmax
and x = NA
.
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)
#> # A tibble: 44 × 6
#> x xmin xmax tmin tmax w
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 NA 0.832 1 0.832 2.08 1
#> 2 NA 1 2 0.464 2.24 1
#> 3 1.46 1.46 1.46 0.450 2.36 1
#> 4 0.665 0.665 0.665 0.487 1.80 1
#> 5 0.979 0.979 0.979 0.0436 1.11 1
#> 6 1.03 1.03 1.03 0.560 2.19 1
#> 7 0.657 0.657 0.657 0.185 1.98 1
#> 8 NA 1 2 0.612 2.36 1
#> 9 0.526 0.526 0.526 0.240 2.03 1
#> 10 1.60 1.60 1.60 0.668 2.38 1
#> # ℹ 34 more rows
as_trunc_obs(c(1, 2, 3))
#> # A tibble: 3 × 6
#> x xmin xmax tmin tmax w
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 1 1 1 -Inf Inf 1
#> 2 2 2 2 -Inf Inf 1
#> 3 3 3 3 -Inf Inf 1
as_trunc_obs(data.frame(x = 1:3, tmin = 0, tmax = 10))
#> # A tibble: 3 × 6
#> x xmin xmax tmin tmax w
#> <int> <int> <int> <dbl> <dbl> <dbl>
#> 1 1 1 1 0 10 1
#> 2 2 2 2 0 10 1
#> 3 3 3 3 0 10 1
as_trunc_obs(data.frame(x = c(1, NA), xmin = c(1, 2), xmax = c(1, 3)))
#> # A tibble: 2 × 6
#> x xmin xmax tmin tmax w
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 1 1 1 -Inf Inf 1
#> 2 NA 2 3 -Inf Inf 1
truncate_obs(1:10, tmin_new = 2.0, tmax_new = 8.0)
#> # A tibble: 7 × 6
#> x xmin xmax tmin tmax w
#> <int> <int> <int> <dbl> <dbl> <dbl>
#> 1 2 2 2 2 8 1
#> 2 3 3 3 2 8 1
#> 3 4 4 4 2 8 1
#> 4 5 5 5 2 8 1
#> 5 6 6 6 2 8 1
#> 6 7 7 7 2 8 1
#> 7 8 8 8 2 8 1