This function models a delay (in days) random variable (e.g. in logistic, registration, report) using a supposed continuous distribution. First, the row-wise differences in days of the related date columns are calculated and then the parameter(s) of the assumed distribution is (are) estimated with maximum likelihood. See 'Details' for more information.

dist_delay(...)

# S3 method for wt_mcs_delay_data
dist_delay(..., x, distribution = c("lognormal", "exponential"))

Arguments

...

Further arguments passed to or from other methods. Currently not used.

x

A tibble with class wt_mcs_delay_data returned by mcs_delay_data.

distribution

Supposed distribution of the respective delay.

Value

A list with class wt_delay_estimation which contains:

  • coefficients : A named vector of estimated parameter(s).

  • delay : A numeric vector of element-wise computed differences in days.

  • distribution : Specified distribution.

If more than one delay was considered in mcs_delay_data, the resulting output is a list with class wt_delay_estimation_list. In this case each list element has class wt_delay_estimation and the items listed above, are included.

Details

The distribution parameter(s) is (are) determined on the basis of complete cases, i.e. there is no NA (row-wise) in one of the related date columns. Time differences less than or equal to zero are not considered as well.

Examples

# MCS data preparation:
## Data for delay in registration:
mcs_tbl_1 <- mcs_delay_data(
  field_data,
  date_1 = production_date,
  date_2 = registration_date,
  time = dis,
  status = status,
  id = vin
)

## Data for delay in report:
mcs_tbl_2 <- mcs_delay_data(
  field_data,
  date_1 = repair_date,
  date_2 = report_date,
  time = dis,
  status = status,
  id = vin
)

## Data for both delays:
mcs_tbl_both <- mcs_delay_data(
  field_data,
  date_1 = c(production_date, repair_date),
  date_2 = c(registration_date, report_date),
  time = dis,
  status = status,
  id = vin
)

# Example 1 - Delay in registration:
params_delay_regist  <- dist_delay(
  x = mcs_tbl_1,
  distribution = "lognormal"
)

# Example 2 - Delay in report:
params_delay_report  <- dist_delay(
  x = mcs_tbl_2,
  distribution = "exponential"
)
#> Warning: At least one of the date differences is less than or equal to 0 and is ignored for the estimation step!

# Example 3 - Delays in registration and report with same distribution:
params_delays  <- dist_delay(
  x = mcs_tbl_both,
  distribution = "lognormal"
)
#> Warning: At least one of the date differences is less than or equal to 0 and is ignored for the estimation step!

# Example 4 - Delays in registration and report with different distributions:
params_delays_2  <- dist_delay(
  x = mcs_tbl_both,
  distribution = c("lognormal", "exponential")
)
#> Warning: At least one of the date differences is less than or equal to 0 and is ignored for the estimation step!