--- title: "Tests of cumulative incidence functions" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Tests of cumulative incidence functions} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- `ciftest()` compares survival or cumulative incidence curves between groups using a formula interface. For competing-risk outcomes, it provides the classical Gray test, score and augmented score tests, and tests combining multiple Fleming–Harrington (FH) temporal-weight directions. Use the Ditzhaus test for a quadratic statistic or MaxCombo for a maximum standardized score. This vignette focuses on **test selection, function calls, and interpreting `ciftest()` output**. For a complete analysis with CIF estimation and risk ratios, see [Worked examples](v5_examples.html). ## Run a single CIF comparison with `ciftest()` In `diabetes.complications`, `epsilon` denotes diabetic retinopathy (1), a competing macrovascular event (2), or censoring (0). The formula's right-hand side identifies the groups. The variable `fruitq1` compares the lowest fruit-intake quartile with the other quartiles. The event of interest defaults to `code.event1 = 1`. ```{r test-setup} library(cifmodeling) data(diabetes.complications) ``` Request the classical Gray test with `test = "gray"`: ```{r test-gray} fit_gray <- ciftest( Event(t, epsilon) ~ fruitq1, data = diabetes.complications, outcome.type = "competing-risk", test = "gray" ) fit_gray generics::tidy(fit_gray) ``` To fit the augmented score test, change `test` to `"augmented"`. This procedure uses working models for event and censoring distributions when constructing the score and its variance: ```{r test-augmented} fit_aug <- ciftest( Event(t, epsilon) ~ fruitq1, data = diabetes.complications, outcome.type = "competing-risk", test = "augmented" ) fit_aug generics::tidy(fit_aug) ``` Both fitted objects contain `statistic`, `parameter` (degrees of freedom), `p.value`, and `method`. Use `generics::tidy()` to collect these fields in a data frame. The p-value concerns differences between CIFs over follow-up, **not** a risk ratio at a fixed time. Because Gray and augmented tests use different scores and covariance estimators, their p-values may differ; neither test is uniformly more powerful. By default, `test = "auto"` selects the augmented score test for competing risks and the log-rank test for survival outcomes. Use `test = "gray"` when you specifically want the classical Gray test. These tests compare groups but do not, by themselves, establish causal effects. ## Select early or late weighting To emphasize differences early or late in follow-up, `ciftest()` accepts FH temporal weights of the form \[ w(t)=\{1-F_1(t-)\}^{\rho}F_1(t-)^{\gamma}, \] Here, \(F_1(t-)\) is the left-limit CIF used to construct the weight. Larger \(\rho\) emphasizes earlier differences, while larger \(\gamma\) emphasizes later differences. The **estimated weight process depends on the component test**: Gray and augmented score tests need not use the same estimated CIF. Inspect the process used in a fit through `fit$diagnostics$fh.weight.process`. For competing-risk outcomes, `test = "early"` and `test = "late"` select augmented score tests with FH(1,0) and FH(0,1), respectively: ```{r test-temporal-directions} fit_early <- ciftest( Event(t, epsilon) ~ fruitq1, data = diabetes.complications, outcome.type = "competing-risk", test = "early" ) fit_late <- ciftest( Event(t, epsilon) ~ fruitq1, data = diabetes.complications, outcome.type = "competing-risk", test = "late" ) fit_early fit_late ``` To use a different direction, specify `rho` and `gamma` alongside the test, for example, `test = "augmented", rho = 2, gamma = 0`. FH(0,0) is called `"unweighted"` because no additional temporal weight is applied; this does **not** mean that censoring adjustment is omitted. The terms `"early"` and `"late"` describe *when* differences are emphasized, not *which group* has the higher CIF. ## Combine directions with the Ditzhaus test `test = "ditzhaus"` (or `"d"`) runs a quadratic-form test. For competing-risk outcomes, the default combines augmented scores with FH(0,0), FH(0,1), and FH(2,0) weights to give one omnibus p-value. ```{r test-multiple} fit_ditzhaus <- ciftest( Event(t, epsilon) ~ fruitq1, data = diabetes.complications, outcome.type = "competing-risk", test = "ditzhaus" ) fit_ditzhaus generics::tidy(fit_ditzhaus) fit_ditzhaus$directions ``` `ciftest()` combines the scores into a quadratic-form statistic: \[ Q=U^\top V^+U. \] The fitted object stores the score vector \(U\) in `fit_ditzhaus$score` and its covariance matrix \(V\) in `fit_ditzhaus$vcov.score`. The test uses the generalized inverse \(V^+\) and a chi-squared reference distribution with degrees of freedom equal to the **numerical rank** of \(V\). Consequently, three directions need not yield three degrees of freedom. `fit_ditzhaus$directions` records the FH weights, and `fit_ditzhaus$components` contains the individual fits. This omnibus statistic does not estimate a risk difference or ratio. The `"early"` and `"late"` presets within `directions` use **FH(2,0)** and **FH(0,2)**. These differ from the single-direction shortcuts `test = "early"` and `test = "late"`. For custom weights, use `directions` and, if necessary, `component.test`: ```{r test-custom-multiple} fit_custom <- ciftest( Event(t, epsilon) ~ fruitq1, data = diabetes.complications, outcome.type = "competing-risk", component.test = "augmented", directions = rbind( early = c(rho = 1, gamma = 0), late = c(rho = 0, gamma = 1) ) ) fit_custom ``` Supplying `directions` alone selects the Ditzhaus test. For competing risks, the default component test is `"augmented"`; set `component.test = "gray"` or `"score"` to change the score and covariance calculation. For survival outcomes, you can use `component.test = "logrank"`. ## Run MaxCombo with `test = "maxcombo"` For two groups with competing risks, `test = "maxcombo"` (or `"m"`) combines augmented scores using FH(0,0), FH(2,0), and FH(0,1) by default. Supply `directions` to change the weights. The default two-sided test uses the largest absolute standardized score and a joint normal reference. ```{r test-maxcombo} fit_maxcombo <- ciftest( Event(t, epsilon) ~ fruitq1, data = diabetes.complications, outcome.type = "competing-risk", test = "m", code.exposure.ref = 0 ) fit_maxcombo ``` For a prespecified lower CIF in the comparison group, set `alternative = "less"`. Use `"greater"` for a higher CIF. `code.exposure.ref` selects the reference group by its code or factor level. The default is the first factor level present in the analysis data. The returned comparison identifies the two groups. ```{r test-maxcombo-one-sided} ciftest( Event(t, epsilon) ~ fruitq1, data = diabetes.complications, outcome.type = "competing-risk", test = "maxcombo", alternative = "less", code.exposure.ref = 0 ) ``` ## Choosing a test Use this table to select a `ciftest()` option: | Goal | Call or result | What you obtain | |:--|:--|:--| | Standard survival-curve comparison | `ciftest(..., outcome.type = "survival", test = "auto")` | Log-rank test | | Classical CIF comparison | `ciftest(..., test = "gray")` | Gray test statistic and p-value | | Augmented CIF comparison (default) | `ciftest(..., test = "augmented")` | Augmented score test and p-value | | Unaugmented score test | `ciftest(..., test = "score")` | Score test using the null-score IID variance | | Focus on an earlier or later difference | `ciftest(..., test = "early")` or `"late"` | Single-direction FH-weighted test | | Combine directions in a quadratic form | `ciftest(..., test = "ditzhaus")` or `directions = ...` | Omnibus quadratic statistic, rank-based df, p-value | | Use the largest signed or absolute standardized score | `ciftest(..., test = "maxcombo", alternative = ...)` | MaxCombo statistic and global p-value | These options test related but distinct alternatives. For confirmatory analyses, prespecify the test and weight directions; choosing the smallest p-value after inspecting the data does not preserve the nominal significance level. The built-in Ditzhaus test uses an asymptotic chi-squared reference. Ditzhaus and Friedrich (2020) studied permutation calibration for weighted log-rank combinations. See [Worked examples](v5_examples.html) for a simpler comparison using this dataset and [Function reference](v9_arguments.html) for the full argument list. ## References - Gray RJ (1988). A class of K-sample tests for comparing the cumulative incidence of a competing risk. *The Annals of Statistics*, **16**, 1141--1154. - Ditzhaus M, Friedrich S (2020). More powerful logrank permutation tests for two-sample survival data. *Journal of Statistical Computation and Simulation*, **90**, 2209--2227. [doi:10.1080/00949655.2020.1773463](https://doi.org/10.1080/00949655.2020.1773463).