Learn R Programming

weibulltools (version 2.0.0)

dist_delay: Parameter Estimation of a Delay Distribution

Description

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

Usage

dist_delay(date_1, date_2, distribution = c("lognormal", "exponential"))

Value

A list of class 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.

Arguments

date_1

A vector of class character or Date, in the format "yyyy-mm-dd", indicating the earlier of the two dates. Use NA for missing elements.

date_2

A vector of class character or Date, in the format "yyyy-mm-dd", indicating the later of the two dates. Use NA for missing elements.

distribution

Supposed distribution of the random variable.

Details

The distribution parameter(s) are determined on the basis of complete cases, i.e. there is no NA in one of the related vector elements c(date_1[i], date_2[i]). Time differences less than or equal to zero are not considered as well.

Examples

Run this code
# Example 1 - Delay in registration:
date_of_production   <- c("2014-07-28", "2014-02-17", "2014-07-14",
                          "2014-06-26", "2014-03-10", "2014-05-14",
                          "2014-05-06", "2014-03-07", "2014-03-09",
                          "2014-04-13", "2014-05-20", "2014-07-07",
                          "2014-01-27", "2014-01-30", "2014-03-17",
                          "2014-02-09", "2014-04-14", "2014-04-20",
                          "2014-03-13", "2014-02-23", "2014-04-03",
                          "2014-01-08", "2014-01-08")
date_of_registration <- c(NA, "2014-03-29", "2014-12-06", "2014-09-09",
                          NA, NA, "2014-06-16", NA, "2014-05-23",
                          "2014-05-09", "2014-05-31", NA, "2014-04-13",
                          NA, NA, "2014-03-12", NA, "2014-06-02",
                          NA, "2014-03-21", "2014-06-19", NA, NA)

params_delay_regist  <- dist_delay(
  date_1 = date_of_production,
  date_2 = date_of_registration,
  distribution = "lognormal"
)

# Example 2 - Delay in report:
date_of_repair <- c(NA, "2014-09-15", "2015-07-04", "2015-04-10", NA,
                    NA, "2015-04-24", NA, "2015-04-25", "2015-04-24",
                    "2015-06-12", NA, "2015-05-04", NA, NA,
                    "2015-05-22", NA, "2015-09-17", NA, "2015-08-15",
                    "2015-11-26", NA, NA)

date_of_report <- c(NA, "2014-10-09", "2015-08-28", "2015-04-15", NA,
                    NA, "2015-05-16", NA, "2015-05-28", "2015-05-15",
                    "2015-07-11", NA, "2015-08-14", NA, NA,
                    "2015-06-05", NA, "2015-10-17", NA, "2015-08-21",
                    "2015-12-02", NA, NA)

params_delay_report  <- dist_delay(
  date_1 = date_of_repair,
  date_2 = date_of_report,
  distribution = "exponential"
)

Run the code above in your browser using DataLab