Nothing
#' The Kolmogorov-Smirnov statistic (D statistic) for the two-parameter exponential distribution.
#'
#' @description
#' The Kolmogorov-Smirnov statistic, also called the D statistic, measures the maximum vertical distance
#' between the empirical distribution function (ECDF) of a sample of data and the CDF of a reference distribution.
#' In this case, a reference distribution is the two-parameter exponential distribution.
#'
#' @param x a data vector (e.g., failure time, waiting time, etc.)
#' @param theta location parameter, where \eqn{\theta > 0}.
#' @param beta scale parameter, where \eqn{\beta > 0} and \eqn{rate=1/\beta}.
#'
#' @import stats
#'
#' @returns A value of the D statistic.
#'
#' @references D'Agostino, R. B., & Stephens, M. A. (Eds.). (1986). Goodness-of-fit techniques. Marcel Dekker. (ISBN 0-8247-8705-6).
#'
#' @export
#'
#' @examples
#' # Proschan (1963, Table I) has given some samples of data,
#' # consisting of intervals between failures of air conditioning equipment in aircraft
#' data <- c(12,21,26,27,29,29,48,57,59,70,74,153,326,386,502)
#' theta_hat <- min(data) #estimate theta
#' beta_hat <- mean(data)-min(data) #estimate beta
#' Dstat(data, theta_hat, beta_hat)
#'
Dstat <- function(x, theta, beta) {
n <- length(x)
Xs <- sort(x)
cdf_emp_upper <- (1:n) / n
cdf_emp_lower <- (0:(n - 1)) / n
cdf_theo <- 1 - exp(-(Xs - theta) / beta)
D <- max(c(cdf_emp_upper - cdf_theo, cdf_theo - cdf_emp_lower))
return(D)
}
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.