---
title: "Kolmogorov-Smirnov Goodness-of-Fit Test for Dependently Double-Truncated Durations"
author: "Shikhar Tyagi, Arvind Pandey, Bhupendra Singh, Vrijesh Tripathi"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Kolmogorov-Smirnov Goodness-of-Fit Test for Dependently Double-Truncated Durations}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r setup, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(DepDoubleTruncKS)
```

## Introduction

The `DepDoubleTruncKS` package provides methods for performing the two-dimensional Kolmogorov-Smirnov-type goodness-of-fit test for exponentially distributed durations subject to double truncation (left and right truncation), accounting for stochastic dependence between duration and truncation age via copulas.

This methodology was developed by Toparkus & Weißbach (2026) in *Lifetime Data Analysis*.

## Method Overview

Given double-truncated observations $(X_j^{\text{obs}}, T_j^{\text{obs}})_{j=1}^{m_n}$ falling inside the truncation parallelogram:
$$D = \{ (x, t)^T \mid 0 < t \le x \le t + s, t \le G \}$$

1. **Parameter Estimation**: Profile maximum likelihood / Z-estimation estimates rate $\hat{\theta}_n$ and copula parameter $\hat{\vartheta}_n$.
2. **2D KS Test Statistic**: Evaluated over observations, boundary projections, and discordant intersection points (Algorithm 1).
3. **Asymptotic Limit Process**: Critical values and p-values are obtained via Gaussian process field simulation (Algorithm 2).

## Quick Start Example

```{r example}
set.seed(2026)

# Load sample dataset
data("enterprise_data")

# Perform KS test under FGM copula dependent truncation
res <- ks_dep_trunc(
  x = enterprise_data$x[1:100],
  t = enterprise_data$t[1:100],
  s = 3,
  G = 24,
  model = "fgm",
  grid_dim = 15,
  n_sim = 100
)

# Print results summary
print(res)

# Plot observations and truncation boundaries
plot(res)
```

## Reference

Toparkus, A.-M. and Weißbach, R. (2026). Kolmogorov-Smirnov-type test for dependently double-truncated durations: A copula approach. *Lifetime Data Analysis*, 32, 41. <doi:10.1007/s10985-026-09722-0>.
