| Title: | Design and Analysis of Hierarchical Composite Endpoints |
|---|---|
| Description: | Simulate and analyze hierarchical composite endpoints. Includes implementation for the kidney hierarchical composite endpoint as defined in Heerspink HL et al (2023) “Development and validation of a new hierarchical composite end point for clinical trials of kidney disease progression” (Journal of the American Society of Nephrology 34 (2): 2025–2038, <doi:10.1681/ASN.0000000000000243>). Win odds, also called Wilcoxon-Mann-Whitney or success odds, is the main analysis method. Other win statistics (win probability, win ratio, net benefit) are also implemented in the univariate case, provided there is no censoring. The win probability analysis is based on the Brunner-Munzel test and uses the DeLong-DeLong-Clarke-Pearson variance estimator, as described by Brunner and Konietschke (2025) in “An unbiased rank-based estimator of the Mann–Whitney variance including the case of ties” (Statistical Papers 66 (1): 20, <doi:10.1007/s00362-024-01635-0>). Includes implementation of a new Wilson-type, compatible confidence interval for the win odds, as proposed by Schüürhuis, Konietschke, Brunner (2025) in “A new approach to the nonparametric Behrens–Fisher problem with compatible confidence intervals.” (Biometrical Journal 67 (6), <doi:10.1002/bimj.70096>). Stratification and covariate adjustment are performed based on the methodology presented by Koch GG et al. in “Issues for covariance analysis of dichotomous and ordered categorical data from randomized clinical trials and non-parametric strategies for addressing them” (Statistics in Medicine 17 (15-16): 1863–92). For a review, see Gasparyan SB et al (2021) “Adjusted win ratio with stratification: Calculation methods and interpretation” (Statistical Methods in Medical Research 30 (2): 580–611, <doi:10.1177/0962280220942558>). |
| Authors: | Samvel B. Gasparyan [aut, cre] (ORCID: <https://orcid.org/0000-0002-4797-2208>) |
| Maintainer: | Samvel B. Gasparyan <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.9.3 |
| Built: | 2026-05-12 19:57:04 UTC |
| Source: | https://github.com/samve/hce |
A dataset with multiple kidney outcomes over time scale outcomes of 1500 patients in the ADSL dataset.
ADETADET
a data frame with 604 rows (events) and 6 variables:
patient identifiers, numeric
occurence time of the event, numeric
name of the event, character
coded name of the event, character
type of the event, outcomes 1-7, where a higher value means a better outcome, numeric
treatment values, 1 Active or 2 Placebo, numeric
Heerspink HL et al "Development and validation of a new hierarchical composite endpoint for clinical trials of kidney disease progression." Journal of the American Society of Nephrology (2023): https://doi.org/10.1681/ASN.0000000000000243.
head(ADET) # Number of unique patients length(unique(ADET$ID)) # Number of events per event type barplot(table(ADET$PARAM))head(ADET) # Number of unique patients length(unique(ADET$ID)) # Number of events per event type barplot(table(ADET$PARAM))
A dataset of laboratory measurements of kidney function over time for the 1500 patients in the ADSL dataset.
ADLBADLB
a data frame with 13980 rows and 8 variables:
patient identifiers, numeric
treatment values, 1 Active or 2 Placebo, numeric
measurement value, numeric
measurement day in the study, numeric
hospital visit number, numeric
name of the event, GFR measurements, character
coded name of the event, GFR, character
type of the event is set to 7 for all measurements, numeric
Heerspink HL et al "Development and validation of a new hierarchical composite endpoint for clinical trials of kidney disease progression." Journal of the American Society of Nephrology (2023): https://doi.org/10.1681/ASN.0000000000000243.
head(ADLB)head(ADLB)
A data frame with baseline characteristics for 1500 patients used to derive KHCE dataset.
ADSLADSL
a data frame with 1500 rows and 4 variables:
patient identifiers, numeric
treatment values, 1 Active or 2 Placebo, numeric
Baseline GFR values of patients, numeric
strata 1-4, higher value means a higher risk for kidney disease progression, numeric
Heerspink HL et al "Development and validation of a new hierarchical composite endpoint for clinical trials of kidney disease progression." Journal of the American Society of Nephrology (2023): https://doi.org/10.1681/ASN.0000000000000243.
head(ADSL)head(ADSL)
hce objectsA generic function for coercing data structures to hce objects
as_hce(x, ...)as_hce(x, ...)
x |
an object used to select a method. |
... |
additional parameters. |
an hce object.
as_hce.data.frame(), as_hce.default().
### data frames data(HCE1) HCE <- as_hce(HCE1) calcWINS(HCE)### data frames data(HCE1) HCE <- as_hce(HCE1) calcWINS(HCE)
hce objectCoerce a data frame to an hce object
## S3 method for class 'data.frame' as_hce(x, ...)## S3 method for class 'data.frame' as_hce(x, ...)
x |
a data frame. |
... |
additional parameters. |
an hce object.
# The case when all required variables `AVAL0`, `GROUP`, `PADY`, and `TRTP` are present. KHCE <- as_hce(KHCE) ## Converts to an `adhce` object class(KHCE) calcWO(KHCE) # The case when only `AVAL` and `TRTP`. ## Converts to an `hce` object dat <- KHCE[, c("TRTP", "AVAL")] dat <- as_hce(dat) class(dat) summaryWO(dat)# The case when all required variables `AVAL0`, `GROUP`, `PADY`, and `TRTP` are present. KHCE <- as_hce(KHCE) ## Converts to an `adhce` object class(KHCE) calcWO(KHCE) # The case when only `AVAL` and `TRTP`. ## Converts to an `hce` object dat <- KHCE[, c("TRTP", "AVAL")] dat <- as_hce(dat) class(dat) summaryWO(dat)
hce objectCoerce a data frame to an hce object
## Default S3 method: as_hce(x, ...)## Default S3 method: as_hce(x, ...)
x |
an object. |
... |
additional parameters. |
an hce object.
as_hce(), as_hce.data.frame().
dat <- KHCE class(dat) <- "moo" # non-existent class as_hce(dat) # tries to convert to an hce object ## It still works because the inheritance converted it to a data framedat <- KHCE class(dat) <- "moo" # non-existent class as_hce(dat) # tries to convert to an hce object ## It still works because the inheritance converted it to a data frame
A generic function for calculating win statistics
calcWINS(x, ...)calcWINS(x, ...)
x |
an object used to select a method. |
... |
further arguments passed to or from other methods. |
a data frame containing calculated values.
calcWINS.hce(), calcWINS.formula(), calcWINS.data.frame() methods.
Win statistics calculation using a data frame
## S3 method for class 'data.frame' calcWINS( x, AVAL, TRTP, ref, alpha = 0.05, WOnull = 1, SE_WP_Type = c("biased", "unbiased"), ... )## S3 method for class 'data.frame' calcWINS( x, AVAL, TRTP, ref, alpha = 0.05, WOnull = 1, SE_WP_Type = c("biased", "unbiased"), ... )
x |
a data frame containing subject-level data. |
AVAL |
variable in the data with ordinal analysis values. |
TRTP |
the treatment variable in the data. |
ref |
the reference treatment group. |
alpha |
2-sided significance level. The default is 0.05. |
WOnull |
the null hypothesis. The default is 1. |
SE_WP_Type |
biased or unbiased standard error for win probability. The default is biased. |
... |
additional parameters. |
When SE_WP_Type = "unbiased", the calculations for win proportion, net benefit, and win odds utilize the unbiased standard error from Brunner-Konietschke (2025) paper which is a reformulation of the original formula proposed by Bamber (1975). In this case, Wilson-type confidence intervals are calculated for the win probability, net benefit, and win odds, following the approach proposed by Schüürhuis, Konietschke, and Brunner (2025).
a list containing win statistics and their confidence intervals. It contains the following named data frames:
summary a data frame containing number of wins, losses, and ties of the active treatment group and the overall number of comparisons.
WP a data frame containing the win probability and its confidence interval.
NetBenefit a data frame containing the net benefit and its confidence interval. This is just a 2x-1 transformation of WP and its CI.
WO a data frame containing the win odds and its confidence interval.
WR1 a data frame containing the win ratio and its confidence interval, using the transformed standard error of the gamma statistic.
WR2 a data frame containing the win ratio and its confidence interval, using the standard error calculated using Pties.
gamma a data frame containing Goodman Kruskal's gamma and its confidence interval.
SE a data frame containing standard errors used to calculated the Confidence intervals for win statistics.
When SE_WP_Type = "unbiased", the WP, WO and NetBenefit estimators use the unbiased variance estimator of WP. Additionally, a Wilson-type range-preserving confidence interval is provided:
WP_W a data frame containing the win probability and its range-preserving confidence interval.
NetBenefit_W a data frame containing the net benefit and its range-preserving confidence interval.
WO_W a data frame containing the win odds and its range-preserving confidence interval.
The theory of win statistics is covered in the following papers:
Win proportion and win odds confidence interval calculation:
Somers RH (1962) “A New Asymmetric Measure of Association for Ordinal Variables." American Sociological Review 27.6: 799-811. https://doi.org/10.2307/2090408.
Bamber D (1975) "The area above the ordinal dominance graph and the area below the receiver operating characteristic graph." Journal of Mathematical Psychology 12.4: 387-415. https://doi.org/10.1016/0022-2496(75)90001-2.
DeLong ER et al. (1988) "Comparing the Areas Under Two or More Correlated Receiver Operating Characteristic Curves: A Nonparametric Approach." Biometrics 44.3: 837-845. https://doi.org/10.2307/2531595.
Brunner E et al. (2021) "Win odds: an adaptation of the win ratio to include ties." Statistics in Medicine 40.14: 3367-3384. https://doi.org/10.1002/sim.8967.
Gasparyan SB et al. (2021) "Adjusted win ratio with stratification: calculation methods and interpretation." Statistical Methods in Medical Research 30.2: 580-611. https://doi.org/10.1177/0962280220942558.
Gasparyan SB et al. (2021) "Power and sample size calculation for the win odds test: application to an ordinal endpoint in COVID-19 trials." Journal of Biopharmaceutical Statistics 31.6: 765-787. https://doi.org/10.1080/10543406.2021.1968893.
Brunner E, Konietschke F. (2025) "An unbiased rank-based estimator of the Mann–Whitney variance including the case of ties." Statistical Papers 66.20. https://doi.org/10.1007/s00362-024-01635-0.
Win ratio: the first CI utilizes the standard error derived from the gamma statistic standard error as outlined by:
Gasparyan SB, Kowalewski EK, Buenconsejo J, Koch GG. (2023) "Hierarchical Composite Endpoints in COVID-19: The DARE-19 Trial." In Case Studies in Innovative Clinical Trials, Chapter 7, 95–148. Chapman; Hall/CRC. https://doi.org/10.1201/9781003288640-7.
Win ratio: the second CI utilizes the standard error presented by:
Yu RX, Ganju J. (2022) "Sample size formula for a win ratio endpoint." Statistics in Medicine 41.6: 950-63. https://doi.org/10.1002/sim.9297.
Goodman Kruskal's gamma and CI: matches implementation in DescTools::GoodmanKruskalGamma() and based on:
Agresti A. (2002) Categorical Data Analysis. John Wiley & Sons, pp. 57-59. https://doi.org/10.1002/0471249688.
Brown MB, Benedetti JK. (1977) "Sampling Behavior of Tests for Correlation in Two-Way Contingency Tables." Journal of the American Statistical Association 72, 309-315. https://doi.org/10.1080/01621459.1977.10480995.
Goodman LA, Kruskal WH. (1954) "Measures of association for cross classifications." Journal of the American Statistical Association 49, 732-764. https://doi.org/10.1080/01621459.1954.10501231.
Goodman LA, Kruskal WH. (1963) "Measures of association for cross classifications III: Approximate sampling theory." Journal of the American Statistical Association 58, 310-364. https://doi.org/10.1080/01621459.1963.10500850.
Unbiased variance estimator for WP and Wilson-type range -preserving confidence intervals are based on:
Brunner E, Konietschke F. (2025) "An unbiased rank-based estimator of the Mann–Whitney variance including the case of ties." Statistical Papers 66: 20. https://doi.org/10.1007/s00362-024-01635-0.
Schüürhuis S, Konietschke F, Brunner E. (2025) "A New Approach to the Nonparametric Behrens–Fisher Problem With Compatible Confidence Intervals." Biometrical Journal 67.6. https://doi.org/10.1002/bimj.70096.
calcWINS(), calcWINS.hce(), calcWINS.formula().
# Example 1 - Simple use calcWINS(x = COVID19b, AVAL = "GROUP", TRTP = "TRTP", ref = "Placebo") calcWINS(x = COVID19b, AVAL = "GROUP", TRTP = "TRTP", ref = "Placebo", SE_WP_Type = "unbiased") # Example 2 - Different variance estimators FREQ <- c(16, 5, 0, 1, 0, 4, 1, 5, 7, 2) dat0 <- data.frame(AVAL = rep(5:1, 2), TRTP = rep(c('A', 'P'), each = 5)) dat <- dat0[rep(row.names(dat0), FREQ),] ## By default, the variance estimator applies a 1/n weighting to the coefficients ## This approach matches the Somers' D (C|R) estimator, where `C|R` indicates that ## the column variable Y is treated as the independent variable and the row ## variable X is treated as the dependent variable. calcWINS(AVAL ~ TRTP, data = dat)$WP ## The Brunner-Konietschke estimator UNB <- calcWINS(AVAL ~ TRTP, data = dat, SE_WP_Type = "unbiased") cbind(UNB$WP, SE = UNB$SE$WP_SE) ## The Brunner-Munzel test, based on the DeLong-Clarke-Pearson formula for the variance estimation, ## applies 1/(n - 1) weighting to the coefficients. dat1 <- IWP(data = dat, AVAL = "AVAL", TRTP = "TRTP", ref = "P") WP <- tapply(dat1$AVAL_, dat1$TRTP, mean) VAR <- tapply(dat1$AVAL_, dat1$TRTP, var) N <- tapply(dat1$AVAL_, dat1$TRTP, length) SE <- sqrt(sum(VAR/N)) c(WP = WP[[1]], SE = SE) # Example 3 - Simulations: Biased vs unbiased vs Wilson confidence intervals for Win Probability set.seed(1) n0 <- 5; n1 <- 7; p0 <- 0.2; p1 <- 0.5; x <- 1:20; delta <- 0.15 WP0 <- (p1 - p0)/2 + 0.5 DAT <- NULL for(i in x){ dat <- data.frame(AVAL = c(rbinom(n1, size = 1, p1), rbinom(n0, size = 1, p0)), TRTP = c(rep("A", n1), rep("P", n0))) CL1 <- calcWINS(x = dat, AVAL = "AVAL", TRTP = "TRTP", ref = "P")$WP CL1$Type <- "biased" fit <- calcWINS(x = dat, AVAL = "AVAL", TRTP = "TRTP", ref = "P", SE_WP_Type = "unbiased") CL2 <- fit$WP CL2$Type <- "unbiased" CL3 <- fit$WP_W CL3$Type <- "Wilson" DAT <- rbind(DAT, CL1, CL2, CL3) } WP <- DAT$WP[DAT$Type == "unbiased"] plot(x, WP, pch = 19, xlab = "Simulations", ylab = "Win Probability", ylim = c(0., 1.1), xlim = c(0, max(x) + 1)) points(x + delta, WP, pch = 19) points(x + 2*delta, WP, pch = 19) arrows(x, DAT$LCL[DAT$Type == "unbiased"], x, DAT$UCL[DAT$Type == "unbiased"], angle = 90, code = 3, length = 0.05, "green") arrows(x + delta, DAT$LCL[DAT$Type == "biased"], x + delta, DAT$UCL[DAT$Type == "biased"], angle = 90, code = 3, length = 0.05, col = "orange") arrows(x + 2*delta, DAT$LCL[DAT$Type == "Wilson"], x + 2*delta, DAT$UCL[DAT$Type == "Wilson"], angle = 90, code = 3, length = 0.05, col = "blue") abline(h = c(WP0, 1), col = c("darkgreen", "darkred"), lty = c(3, 4)) legend("bottomleft", legend = c("True WP", "UnBiased", "Biased", "Wilson", "Null"), col = c("darkgreen", "green", "orange", "blue", "darkred"), lty = c(3, 1, 1, 1, 4), cex = 0.75, ncol = 3) title("Win Probability: Biased vs Unbiased vs Wilson CI") # End of Example 3# Example 1 - Simple use calcWINS(x = COVID19b, AVAL = "GROUP", TRTP = "TRTP", ref = "Placebo") calcWINS(x = COVID19b, AVAL = "GROUP", TRTP = "TRTP", ref = "Placebo", SE_WP_Type = "unbiased") # Example 2 - Different variance estimators FREQ <- c(16, 5, 0, 1, 0, 4, 1, 5, 7, 2) dat0 <- data.frame(AVAL = rep(5:1, 2), TRTP = rep(c('A', 'P'), each = 5)) dat <- dat0[rep(row.names(dat0), FREQ),] ## By default, the variance estimator applies a 1/n weighting to the coefficients ## This approach matches the Somers' D (C|R) estimator, where `C|R` indicates that ## the column variable Y is treated as the independent variable and the row ## variable X is treated as the dependent variable. calcWINS(AVAL ~ TRTP, data = dat)$WP ## The Brunner-Konietschke estimator UNB <- calcWINS(AVAL ~ TRTP, data = dat, SE_WP_Type = "unbiased") cbind(UNB$WP, SE = UNB$SE$WP_SE) ## The Brunner-Munzel test, based on the DeLong-Clarke-Pearson formula for the variance estimation, ## applies 1/(n - 1) weighting to the coefficients. dat1 <- IWP(data = dat, AVAL = "AVAL", TRTP = "TRTP", ref = "P") WP <- tapply(dat1$AVAL_, dat1$TRTP, mean) VAR <- tapply(dat1$AVAL_, dat1$TRTP, var) N <- tapply(dat1$AVAL_, dat1$TRTP, length) SE <- sqrt(sum(VAR/N)) c(WP = WP[[1]], SE = SE) # Example 3 - Simulations: Biased vs unbiased vs Wilson confidence intervals for Win Probability set.seed(1) n0 <- 5; n1 <- 7; p0 <- 0.2; p1 <- 0.5; x <- 1:20; delta <- 0.15 WP0 <- (p1 - p0)/2 + 0.5 DAT <- NULL for(i in x){ dat <- data.frame(AVAL = c(rbinom(n1, size = 1, p1), rbinom(n0, size = 1, p0)), TRTP = c(rep("A", n1), rep("P", n0))) CL1 <- calcWINS(x = dat, AVAL = "AVAL", TRTP = "TRTP", ref = "P")$WP CL1$Type <- "biased" fit <- calcWINS(x = dat, AVAL = "AVAL", TRTP = "TRTP", ref = "P", SE_WP_Type = "unbiased") CL2 <- fit$WP CL2$Type <- "unbiased" CL3 <- fit$WP_W CL3$Type <- "Wilson" DAT <- rbind(DAT, CL1, CL2, CL3) } WP <- DAT$WP[DAT$Type == "unbiased"] plot(x, WP, pch = 19, xlab = "Simulations", ylab = "Win Probability", ylim = c(0., 1.1), xlim = c(0, max(x) + 1)) points(x + delta, WP, pch = 19) points(x + 2*delta, WP, pch = 19) arrows(x, DAT$LCL[DAT$Type == "unbiased"], x, DAT$UCL[DAT$Type == "unbiased"], angle = 90, code = 3, length = 0.05, "green") arrows(x + delta, DAT$LCL[DAT$Type == "biased"], x + delta, DAT$UCL[DAT$Type == "biased"], angle = 90, code = 3, length = 0.05, col = "orange") arrows(x + 2*delta, DAT$LCL[DAT$Type == "Wilson"], x + 2*delta, DAT$UCL[DAT$Type == "Wilson"], angle = 90, code = 3, length = 0.05, col = "blue") abline(h = c(WP0, 1), col = c("darkgreen", "darkred"), lty = c(3, 4)) legend("bottomleft", legend = c("True WP", "UnBiased", "Biased", "Wilson", "Null"), col = c("darkgreen", "green", "orange", "blue", "darkred"), lty = c(3, 1, 1, 1, 4), cex = 0.75, ncol = 3) title("Win Probability: Biased vs Unbiased vs Wilson CI") # End of Example 3
Win statistics calculation using formula syntax
## S3 method for class 'formula' calcWINS(x, data, ...)## S3 method for class 'formula' calcWINS(x, data, ...)
x |
an object of class formula. |
data |
a data frame. |
... |
additional parameters. |
a list containing win statistics and their confidence intervals. It contains the following named data frames:
summary a data frame containing number of wins, losses, and ties of the active treatment group and the overall number of comparisons.
WP a data frame containing the win probability and its confidence interval.
NetBenefit a data frame containing the net benefit and its confidence interval. This is just a 2x-1 transformation of WP and its CI.
WO a data frame containing the win odds and its confidence interval.
WR1 a data frame containing the win ratio and its confidence interval, using the transformed standard error of the gamma statistic.
WR2 a data frame containing the win ratio and its confidence interval, using the standard error calculated using Pties.
gamma a data frame containing Goodman Kruskal's gamma and its confidence interval.
SE a data frame containing standard errors used to calculated the Confidence intervals for win statistics.
When SE_WP_Type = "unbiased", the WP, WO and NetBenefit estimators use the unbiased variance estimator of WP. Additionally, a Wilson-type range-preserving confidence interval is provided:
WP_W a data frame containing the win probability and its range-preserving confidence interval.
NetBenefit_W a data frame containing the net benefit and its range-preserving confidence interval.
WO_W a data frame containing the win odds and its range-preserving confidence interval.
The theory of win statistics is covered in the following papers:
Win proportion and win odds confidence interval calculation:
Somers RH (1962) “A New Asymmetric Measure of Association for Ordinal Variables." American Sociological Review 27.6: 799-811. https://doi.org/10.2307/2090408.
Bamber D (1975) "The area above the ordinal dominance graph and the area below the receiver operating characteristic graph." Journal of Mathematical Psychology 12.4: 387-415. https://doi.org/10.1016/0022-2496(75)90001-2.
DeLong ER et al. (1988) "Comparing the Areas Under Two or More Correlated Receiver Operating Characteristic Curves: A Nonparametric Approach." Biometrics 44.3: 837-845. https://doi.org/10.2307/2531595.
Brunner E et al. (2021) "Win odds: an adaptation of the win ratio to include ties." Statistics in Medicine 40.14: 3367-3384. https://doi.org/10.1002/sim.8967.
Gasparyan SB et al. (2021) "Adjusted win ratio with stratification: calculation methods and interpretation." Statistical Methods in Medical Research 30.2: 580-611. https://doi.org/10.1177/0962280220942558.
Gasparyan SB et al. (2021) "Power and sample size calculation for the win odds test: application to an ordinal endpoint in COVID-19 trials." Journal of Biopharmaceutical Statistics 31.6: 765-787. https://doi.org/10.1080/10543406.2021.1968893.
Brunner E, Konietschke F. (2025) "An unbiased rank-based estimator of the Mann–Whitney variance including the case of ties." Statistical Papers 66.20. https://doi.org/10.1007/s00362-024-01635-0.
Win ratio: the first CI utilizes the standard error derived from the gamma statistic standard error as outlined by:
Gasparyan SB, Kowalewski EK, Buenconsejo J, Koch GG. (2023) "Hierarchical Composite Endpoints in COVID-19: The DARE-19 Trial." In Case Studies in Innovative Clinical Trials, Chapter 7, 95–148. Chapman; Hall/CRC. https://doi.org/10.1201/9781003288640-7.
Win ratio: the second CI utilizes the standard error presented by:
Yu RX, Ganju J. (2022) "Sample size formula for a win ratio endpoint." Statistics in Medicine 41.6: 950-63. https://doi.org/10.1002/sim.9297.
Goodman Kruskal's gamma and CI: matches implementation in DescTools::GoodmanKruskalGamma() and based on:
Agresti A. (2002) Categorical Data Analysis. John Wiley & Sons, pp. 57-59. https://doi.org/10.1002/0471249688.
Brown MB, Benedetti JK. (1977) "Sampling Behavior of Tests for Correlation in Two-Way Contingency Tables." Journal of the American Statistical Association 72, 309-315. https://doi.org/10.1080/01621459.1977.10480995.
Goodman LA, Kruskal WH. (1954) "Measures of association for cross classifications." Journal of the American Statistical Association 49, 732-764. https://doi.org/10.1080/01621459.1954.10501231.
Goodman LA, Kruskal WH. (1963) "Measures of association for cross classifications III: Approximate sampling theory." Journal of the American Statistical Association 58, 310-364. https://doi.org/10.1080/01621459.1963.10500850.
Unbiased variance estimator for WP and Wilson-type range -preserving confidence intervals are based on:
Brunner E, Konietschke F. (2025) "An unbiased rank-based estimator of the Mann–Whitney variance including the case of ties." Statistical Papers 66: 20. https://doi.org/10.1007/s00362-024-01635-0.
Schüürhuis S, Konietschke F, Brunner E. (2025) "A New Approach to the Nonparametric Behrens–Fisher Problem With Compatible Confidence Intervals." Biometrical Journal 67.6. https://doi.org/10.1002/bimj.70096.
calcWINS(), calcWINS.hce(), calcWINS.data.frame().
# Example 1 calcWINS(x = GROUP ~ TRTP, data = COVID19b) # Example 2 calcWINS(x = GROUP ~ TRTP, data = COVID19, ref = "Placebo", alpha = 0.01, WOnull = 1.2) #' Example 3 calcWINS(x = GROUP ~ TRTP, data = COVID19)$WP calcWINS(x = GROUP ~ TRTP, data = COVID19, SE_WP_Type = "unbiased")$WP# Example 1 calcWINS(x = GROUP ~ TRTP, data = COVID19b) # Example 2 calcWINS(x = GROUP ~ TRTP, data = COVID19, ref = "Placebo", alpha = 0.01, WOnull = 1.2) #' Example 3 calcWINS(x = GROUP ~ TRTP, data = COVID19)$WP calcWINS(x = GROUP ~ TRTP, data = COVID19, SE_WP_Type = "unbiased")$WP
hce objectsWin statistics calculation for hce objects
## S3 method for class 'hce' calcWINS(x, ...)## S3 method for class 'hce' calcWINS(x, ...)
x |
an |
... |
additional parameters. |
a list containing win statistics and their confidence intervals. It contains the following named data frames:
summary a data frame containing number of wins, losses, and ties of the active treatment group and the overall number of comparisons.
WP a data frame containing the win probability and its confidence interval.
NetBenefit a data frame containing the net benefit and its confidence interval. This is just a 2x-1 transformation of WP and its CI.
WO a data frame containing the win odds and its confidence interval.
WR1 a data frame containing the win ratio and its confidence interval, using the transformed standard error of the gamma statistic.
WR2 a data frame containing the win ratio and its confidence interval, using the standard error calculated using Pties.
gamma a data frame containing Goodman Kruskal's gamma and its confidence interval.
SE a data frame containing standard errors used to calculated the Confidence intervals for win statistics.
When SE_WP_Type = "unbiased", the WP, WO and NetBenefit estimators use the unbiased variance estimator of WP. Additionally, a Wilson-type range-preserving confidence interval is provided:
WP_W a data frame containing the win probability and its range-preserving confidence interval.
NetBenefit_W a data frame containing the net benefit and its range-preserving confidence interval.
WO_W a data frame containing the win odds and its range-preserving confidence interval.
The theory of win statistics is covered in the following papers:
Win proportion and win odds confidence interval calculation:
Somers RH (1962) “A New Asymmetric Measure of Association for Ordinal Variables." American Sociological Review 27.6: 799-811. https://doi.org/10.2307/2090408.
Bamber D (1975) "The area above the ordinal dominance graph and the area below the receiver operating characteristic graph." Journal of Mathematical Psychology 12.4: 387-415. https://doi.org/10.1016/0022-2496(75)90001-2.
DeLong ER et al. (1988) "Comparing the Areas Under Two or More Correlated Receiver Operating Characteristic Curves: A Nonparametric Approach." Biometrics 44.3: 837-845. https://doi.org/10.2307/2531595.
Brunner E et al. (2021) "Win odds: an adaptation of the win ratio to include ties." Statistics in Medicine 40.14: 3367-3384. https://doi.org/10.1002/sim.8967.
Gasparyan SB et al. (2021) "Adjusted win ratio with stratification: calculation methods and interpretation." Statistical Methods in Medical Research 30.2: 580-611. https://doi.org/10.1177/0962280220942558.
Gasparyan SB et al. (2021) "Power and sample size calculation for the win odds test: application to an ordinal endpoint in COVID-19 trials." Journal of Biopharmaceutical Statistics 31.6: 765-787. https://doi.org/10.1080/10543406.2021.1968893.
Brunner E, Konietschke F. (2025) "An unbiased rank-based estimator of the Mann–Whitney variance including the case of ties." Statistical Papers 66.20. https://doi.org/10.1007/s00362-024-01635-0.
Win ratio: the first CI utilizes the standard error derived from the gamma statistic standard error as outlined by:
Gasparyan SB, Kowalewski EK, Buenconsejo J, Koch GG. (2023) "Hierarchical Composite Endpoints in COVID-19: The DARE-19 Trial." In Case Studies in Innovative Clinical Trials, Chapter 7, 95–148. Chapman; Hall/CRC. https://doi.org/10.1201/9781003288640-7.
Win ratio: the second CI utilizes the standard error presented by:
Yu RX, Ganju J. (2022) "Sample size formula for a win ratio endpoint." Statistics in Medicine 41.6: 950-63. https://doi.org/10.1002/sim.9297.
Goodman Kruskal's gamma and CI: matches implementation in DescTools::GoodmanKruskalGamma() and based on:
Agresti A. (2002) Categorical Data Analysis. John Wiley & Sons, pp. 57-59. https://doi.org/10.1002/0471249688.
Brown MB, Benedetti JK. (1977) "Sampling Behavior of Tests for Correlation in Two-Way Contingency Tables." Journal of the American Statistical Association 72, 309-315. https://doi.org/10.1080/01621459.1977.10480995.
Goodman LA, Kruskal WH. (1954) "Measures of association for cross classifications." Journal of the American Statistical Association 49, 732-764. https://doi.org/10.1080/01621459.1954.10501231.
Goodman LA, Kruskal WH. (1963) "Measures of association for cross classifications III: Approximate sampling theory." Journal of the American Statistical Association 58, 310-364. https://doi.org/10.1080/01621459.1963.10500850.
Unbiased variance estimator for WP and Wilson-type range -preserving confidence intervals are based on:
Brunner E, Konietschke F. (2025) "An unbiased rank-based estimator of the Mann–Whitney variance including the case of ties." Statistical Papers 66: 20. https://doi.org/10.1007/s00362-024-01635-0.
Schüürhuis S, Konietschke F, Brunner E. (2025) "A New Approach to the Nonparametric Behrens–Fisher Problem With Compatible Confidence Intervals." Biometrical Journal 67.6. https://doi.org/10.1002/bimj.70096.
calcWINS(), calcWINS.formula(), calcWINS.data.frame().
# Example 1 COVID19HCE <- hce(GROUP = COVID19$GROUP, TRTP = COVID19$TRTP) calcWINS(COVID19HCE) # Example 2 COVID19bHCE <- hce(GROUP = COVID19b$GROUP, TRTP = COVID19b$TRTP) calcWINS(COVID19bHCE, ref = "Placebo", WOnull = 1.1, alpha = 0.01) # Example 3 calcWINS(COVID19HCE, SE_WP_Type = "unbiased")$WP calcWINS(COVID19HCE, SE_WP_Type = "biased")$WP# Example 1 COVID19HCE <- hce(GROUP = COVID19$GROUP, TRTP = COVID19$TRTP) calcWINS(COVID19HCE) # Example 2 COVID19bHCE <- hce(GROUP = COVID19b$GROUP, TRTP = COVID19b$TRTP) calcWINS(COVID19bHCE, ref = "Placebo", WOnull = 1.1, alpha = 0.01) # Example 3 calcWINS(COVID19HCE, SE_WP_Type = "unbiased")$WP calcWINS(COVID19HCE, SE_WP_Type = "biased")$WP
A generic function for calculating win odds
calcWO(x, ...)calcWO(x, ...)
x |
an object used to select a method. |
... |
further arguments passed to or from other methods. |
a data frame containing calculated values.
calcWO.hce(), calcWO.formula(), calcWO.data.frame() methods.
Win odds calculation using a data frame
## S3 method for class 'data.frame' calcWO(x, AVAL, TRTP, ref, alpha = 0.05, WOnull = 1, ...)## S3 method for class 'data.frame' calcWO(x, AVAL, TRTP, ref, alpha = 0.05, WOnull = 1, ...)
x |
a data frame containing subject-level data. |
AVAL |
variable in the data with ordinal analysis values. |
TRTP |
the treatment variable in the data. |
ref |
the reference treatment group. |
alpha |
significance level. The default is 0.05. |
WOnull |
the null hypothesis. The default is 1. |
... |
additional parameters. |
a data frame containing the win odds and its confidence interval. It contains the following columns:
WO calculated win odds.
LCL lower confidence limit.
UCL upper confidence limit.
SE standard error of the win odds.
WOnull win odds of the null hypothesis (specified in the WOnull argument).
alpha two-sided significance level for calculating the confidence interval (specified in the alpha argument).
Pvalue p-value associated with testing the null hypothesis.
WP calculated win probability.
LCL_WP lower confidence limit for WP.
UCL_WP upper confidence limit for WP.
SE_WP standard error of the win probability.
SD_WP standard deviation of the win probability, calculated as SE_WP multiplied by sqrt(N).
N total number of patients in the analysis.
Gasparyan SB et al. "Adjusted win ratio with stratification: calculation methods and interpretation." Statistical Methods in Medical Research 30.2 (2021): 580-611. https://doi.org/10.1177/0962280220942558.
calcWO(), calcWO.hce(), calcWO.formula().
data(HCE4) calcWO(x = HCE4, AVAL = "AVAL", TRTP = "TRTP", ref = "P")data(HCE4) calcWO(x = HCE4, AVAL = "AVAL", TRTP = "TRTP", ref = "P")
Win odds calculation using formula syntax
## S3 method for class 'formula' calcWO(x, data, ...)## S3 method for class 'formula' calcWO(x, data, ...)
x |
an object of class formula. |
data |
a data frame. |
... |
additional parameters. |
a data frame containing the win odds and its confidence interval. It contains the following columns:
WO calculated win odds.
LCL lower confidence limit.
UCL upper confidence limit.
SE standard error of the win odds.
WOnull win odds of the null hypothesis (specified in the WOnull argument).
alpha two-sided significance level for calculating the confidence interval (specified in the alpha argument).
Pvalue p-value associated with testing the null hypothesis.
WP calculated win probability.
LCL_WP lower confidence limit for WP.
UCL_WP upper confidence limit for WP.
SE_WP standard error of the win probability.
SD_WP standard deviation of the win probability, calculated as SE_WP multiplied by sqrt(N).
N total number of patients in the analysis.
formula returning the specified formula in the x argument.
ref showing how the reference group was selected. Can be modifying by specifying the ref argument.
Gasparyan SB et al. "Adjusted win ratio with stratification: calculation methods and interpretation." Statistical Methods in Medical Research 30.2 (2021): 580-611. https://doi.org/10.1177/0962280220942558.
calcWO(), calcWO.hce(), calcWO.data.frame().
#Example 1 data(HCE1) calcWO(AVAL ~ TRTP, data = HCE1) #Example 2 calcWO(GROUP ~ TRTP, data = COVID19, ref = "Placebo", alpha = 0.01)#Example 1 data(HCE1) calcWO(AVAL ~ TRTP, data = HCE1) #Example 2 calcWO(GROUP ~ TRTP, data = COVID19, ref = "Placebo", alpha = 0.01)
hce objectsWin odds calculation for hce objects
## S3 method for class 'hce' calcWO(x, ...)## S3 method for class 'hce' calcWO(x, ...)
x |
an |
... |
additional parameters. |
a data frame containing the win odds and its confidence interval. It contains the following columns:
WO calculated win odds.
LCL lower confidence limit.
UCL upper confidence limit.
SE standard error of the win odds.
WOnull win odds of the null hypothesis (specified in the WOnull argument).
alpha two-sided significance level for calculating the confidence interval (specified in the alpha argument).
Pvalue p-value associated with testing the null hypothesis.
WP calculated win probability.
LCL_WP lower confidence limit for WP.
UCL_WP upper confidence limit for WP.
SE_WP standard error of the win probability.
SD_WP standard deviation of the win probability, calculated as SE_WP multiplied by sqrt(N).
N total number of patients in the analysis.
Gasparyan SB et al. "Adjusted win ratio with stratification: calculation methods and interpretation." Statistical Methods in Medical Research 30.2 (2021): 580-611. https://doi.org/10.1177/0962280220942558.
calcWO(), calcWO.formula(), calcWO.data.frame().
Rates_A <- c(1, 1.5) Rates_P <- c(2, 2) dat <- simHCE(n = 500, TTE_A = Rates_A, TTE_P = Rates_P, CM_A = 1.25, CM_P = 1) calcWO(dat) calcWO(dat, ref = "A", WOnull = 1, alpha = 0.01)Rates_A <- c(1, 1.5) Rates_P <- c(2, 2) dat <- simHCE(n = 500, TTE_A = Rates_A, TTE_P = Rates_P, CM_A = 1.25, CM_P = 1) calcWO(dat) calcWO(dat, ref = "A", WOnull = 1, alpha = 0.01)
A dataset with COVID-19 ordinal scale outcomes for 1062 patients.
COVID19COVID19
a data frame with 1062 rows and 2 variables:
type of the event, ordinal outcomes 1-8, where a higher value means a better outcome
treatment values, A Active or P Placebo, character
Beigel JH et al. "Remdesivir for the treatment of Covid-19-final report." New England Journal of Medicine 383.19 (2020): 1813-1836. https://doi.org/10.1056/NEJMoa2007764.
#Frequencies table(COVID19) mosaicplot(table(COVID19), col = c(1, 8, 6, 2, 4, 5, 3, 7), xlab = "Treatment", ylab = "Ordinal Scale", main = "COVID-19 ordinal scale") # Convert to an hce object COVID19HCE <- hce(GROUP = COVID19$GROUP, TRTP = COVID19$TRTP) # Summary wins, losses, and ties with win odds summaryWO(COVID19HCE, ref = "Placebo")#Frequencies table(COVID19) mosaicplot(table(COVID19), col = c(1, 8, 6, 2, 4, 5, 3, 7), xlab = "Treatment", ylab = "Ordinal Scale", main = "COVID-19 ordinal scale") # Convert to an hce object COVID19HCE <- hce(GROUP = COVID19$GROUP, TRTP = COVID19$TRTP) # Summary wins, losses, and ties with win odds summaryWO(COVID19HCE, ref = "Placebo")
A dataset with COVID-19 ordinal scale outcomes for 844 patients.
COVID19bCOVID19b
a data frame with 844 rows and 2 variables:
type of the event, ordinal outcomes 1-8, where a higher value means a better outcome
treatment values, Active or Placebo, character
Beigel JH et al. "Remdesivir for the treatment of Covid-19-final report." New England Journal of Medicine 383.19 (2020): 1813-1836. https://doi.org/10.1056/NEJMoa2007764.
#Frequencies table(COVID19b) mosaicplot(table(COVID19b), col = c(1, 8, 6, 2, 4, 5, 3, 7), xlab = "Treatment", ylab = "Ordinal Scale", main = "COVID-19 ordinal scale") # Calculate win statistics calcWINS(x = COVID19b, AVAL = "GROUP", TRTP = "TRTP", ref = "Placebo")#Frequencies table(COVID19b) mosaicplot(table(COVID19b), col = c(1, 8, 6, 2, 4, 5, 3, 7), xlab = "Treatment", ylab = "Ordinal Scale", main = "COVID-19 ordinal scale") # Calculate win statistics calcWINS(x = COVID19b, AVAL = "GROUP", TRTP = "TRTP", ref = "Placebo")
A dataset with COVID-19 ordinal scale outcomes for 1033 patients.
COVID19plusCOVID19plus
a data frame with 1033 rows and 4 variables:
patient identifiers, numeric
treatment values, A Active or P Placebo, character
type of the event, ordinal outcomes 1-8, where a higher value means a better outcome
baseline ordinal values
Kalil AC et al. "Baricitinib plus Remdesivir for Hospitalized Adults with Covid-19." New England Journal of Medicine 384.9 (2021): 795-807. https://doi.org/10.1056/NEJMoa2031994.
COVID19HCE <- hce(GROUP = COVID19plus$GROUP, TRTP = COVID19plus$TRTP) # Summary wins, losses, and ties with win odds summaryWO(COVID19HCE, ref = "P")COVID19HCE <- hce(GROUP = COVID19plus$GROUP, TRTP = COVID19plus$TRTP) # Summary wins, losses, and ties with win odds summaryWO(COVID19HCE, ref = "P")
A generic function for calculating win odds based on a threshold
deltaWO(x, delta, ...)deltaWO(x, delta, ...)
x |
an object used to select a method. |
delta |
a numeric threshold. |
... |
further arguments passed to or from other methods. |
a data frame containing calculated values.
deltaWO.adhce() method.
adhce objectsWin odds calculation based on a threshold for adhce objects
## S3 method for class 'adhce' deltaWO(x, delta, ref = unique(x$TRTP)[1], alpha = 0.05, WOnull = 1, ...)## S3 method for class 'adhce' deltaWO(x, delta, ref = unique(x$TRTP)[1], alpha = 0.05, WOnull = 1, ...)
x |
an |
delta |
a numeric threshold. |
ref |
the reference treatment group. |
alpha |
significance level. The default is 0.05. |
WOnull |
the null hypothesis. The default is 1. |
... |
additional parameters. |
a data frame containing the win odds and its confidence interval. It contains the following columns:
WO calculated win odds.
LCL lower confidence limit.
UCL upper confidence limit.
SE standard error of the win odds.
WOnull win odds of the null hypothesis (specified in the WOnull argument).
alpha two-sided significance level for calculating the confidence interval (specified in the alpha argument).
Pvalue p-value associated with testing the null hypothesis.
WP calculated win probability.
LCL_WP lower confidence limit for WP.
UCL_WP upper confidence limit for WP.
SE_WP standard error of the win probability.
SD_WP standard deviation of the win probability, calculated as SE_WP multiplied by sqrt(N).
N total number of patients in the analysis.
ref the reference group.
delta the threshold.
# Example using the kidney dataset dat <- as_hce(KHCE) calcWO(dat, ref = "P") ## The exact same result deltaWO(dat, delta = 0, ref = "P") ## A large threshold deltaWO(dat, delta = 10, ref = "P")# Example using the kidney dataset dat <- as_hce(KHCE) calcWO(dat, ref = "P") ## The exact same result deltaWO(dat, delta = 0, ref = "P") ## A large threshold deltaWO(dat, delta = 10, ref = "P")
Density, distribution function, quantile function, hazard, cumulative hazard, and random generation for the generalized log-logistic distribution.
dGLL(x, rate, shape = 1, theta = 0, log = FALSE) pGLL(q, rate, shape = 1, theta = 0) qGLL(p, rate, shape = 1, theta = 0) rGLL(n, rate, shape = 1, theta = 0) hGLL(x, rate, shape = 1, theta = 0) HGLL(x, rate, shape = 1, theta = 0)dGLL(x, rate, shape = 1, theta = 0, log = FALSE) pGLL(q, rate, shape = 1, theta = 0) qGLL(p, rate, shape = 1, theta = 0) rGLL(n, rate, shape = 1, theta = 0) hGLL(x, rate, shape = 1, theta = 0) HGLL(x, rate, shape = 1, theta = 0)
x, q
|
vector of quantiles. |
rate |
positive rate parameter of the distribution. |
shape |
positive shape parameter of the distribution. |
theta |
non-negative additional parameter of the distribution, with default
value |
log |
logical; if |
p |
vector of probabilities. |
n |
number of observations. Must be a single non-negative integer. |
The generalized log-logistic distribution with rate parameter ,
shape parameter , and parameter has survival
function
The corresponding cumulative distribution function is
The quantile function is
The cumulative hazard function is
The density function is
For dGLL(..., log = TRUE), the logarithm of the density is returned. For
,
The hazard function is
Random generation is performed by inverse transform sampling. If
, then
has the generalized log-logistic distribution.
As , this reduces to the Weibull distribution with survival
function
The corresponding quantile function is
In this case, dGLL(..., log = TRUE) returns the corresponding Weibull
log-density.
This corresponds to the Weibull distribution in stats::dweibull(),
stats::pweibull(), stats::qweibull(), and stats::rweibull() with
shape = shape and scale = rate^(-1 / shape).
When , the survival function becomes
corresponding to the log-logistic distribution.
For dGLL(), pGLL(), qGLL(), hGLL(), and HGLL(), a numeric vector of
the same length as the main input (x, q, or p). For rGLL(), a numeric
vector of length n.
Wienke A. Frailty Models in Survival Analysis. Chapman and Hall/CRC (2010).
rweibullGF() for simulation of a Weibull distribution with gamma frailty.
## Example 1: Compare the density of GLL with different values of `theta` x <- seq(0, 10, length.out = 100) y1 <- pGLL(x, rate = 0.5, shape = 2, theta = 1) y0 <- pGLL(x, rate = 0.5, shape = 2, theta = 0) plot(x, y1, type = "l", ylab = "Cumulative distribution function") lines(x, y0, col = "red", lty = 2)## Example 1: Compare the density of GLL with different values of `theta` x <- seq(0, 10, length.out = 100) y1 <- pGLL(x, rate = 0.5, shape = 2, theta = 1) y0 <- pGLL(x, rate = 0.5, shape = 2, theta = 0) plot(x, y1, type = "l", ylab = "Cumulative distribution function") lines(x, y0, col = "red", lty = 2)
hce objectsHelper function for hce objects
hce(GROUP, TRTP, AVAL0 = NULL, PADY = NULL)hce(GROUP, TRTP, AVAL0 = NULL, PADY = NULL)
GROUP |
a character vector or a factor containing events. If a factor, its levels are used to define the hierarchy. Otherwise, the vector is converted to a factor. |
TRTP |
a character vector of the same length as |
AVAL0 |
a numeric vector of the same length as |
PADY |
numeric specifying the length of follow-up in years. |
an object of class hce or adhce (if AVAL0 is provided). The result
is a subject-level data frame, where each row corresponds to one subject,
as_hce() for coercing to hce objects.
# Example 1 - Both `AVAL0` and `PADY` are provided. The output is an `adhce` object. GROUP <- COVID19$GROUP TRTP <- rep(c("A", "P"), each = 531) dat <- hce(GROUP, TRTP, PADY = 10, AVAL0 = rnorm(1062)) class(dat) calcWO(dat) summaryWO(dat) # Uses the `GROUP` variable for summary. # Example 2 - Only `AVAL0` is provided, `PADY` is calculated as the maximum of `AVAL0`. # The output is an `adhce` object. set.seed(2022) d <- hce(GROUP = sample(x = c("A", "B", "C"), size = 10, replace = TRUE), TRTP = rep(c("Active", "Control"), each = 5), AVAL0 = c(rnorm(5, mean = 1), rnorm(5))) calcWO(d, ref = "Control") ## modify the hierarchy by proving a factor for the GROUP variable. ## calcWO() applied to an hce rederives `AVAL` based on the `GROUP` variable. d$GROUP <- factor(d$GROUP, levels = c("C", "B", "A")) calcWO(d, ref = "Control") # Example 3 - Provide only `PADY` and not `AVAL0` will not make any difference. GROUP <- COVID19$GROUP TRTP <- rep(c("A", "P"), each = 531) dat <- hce(GROUP, TRTP, PADY = 10) class(dat) calcWO(dat) dat <- hce(GROUP, TRTP) class(dat) calcWO(dat)# Example 1 - Both `AVAL0` and `PADY` are provided. The output is an `adhce` object. GROUP <- COVID19$GROUP TRTP <- rep(c("A", "P"), each = 531) dat <- hce(GROUP, TRTP, PADY = 10, AVAL0 = rnorm(1062)) class(dat) calcWO(dat) summaryWO(dat) # Uses the `GROUP` variable for summary. # Example 2 - Only `AVAL0` is provided, `PADY` is calculated as the maximum of `AVAL0`. # The output is an `adhce` object. set.seed(2022) d <- hce(GROUP = sample(x = c("A", "B", "C"), size = 10, replace = TRUE), TRTP = rep(c("Active", "Control"), each = 5), AVAL0 = c(rnorm(5, mean = 1), rnorm(5))) calcWO(d, ref = "Control") ## modify the hierarchy by proving a factor for the GROUP variable. ## calcWO() applied to an hce rederives `AVAL` based on the `GROUP` variable. d$GROUP <- factor(d$GROUP, levels = c("C", "B", "A")) calcWO(d, ref = "Control") # Example 3 - Provide only `PADY` and not `AVAL0` will not make any difference. GROUP <- COVID19$GROUP TRTP <- rep(c("A", "P"), each = 531) dat <- hce(GROUP, TRTP, PADY = 10) class(dat) calcWO(dat) dat <- hce(GROUP, TRTP) class(dat) calcWO(dat)
HCE1, HCE2, HCE3, HCE4 datasets for 1000 patients with different treatment effects.A simulated dataset containing the ordinal values and other attributes for 1000 patients. HCE1
HCE1HCE1
a data frame with 1000 rows and 6 variables:
subject ID, numbers from 1 to 1000
treatment values, A Active or P Placebo, character
type of the event, either Time-To-Event (TTE) or Continuous (C), character
type of the event, for the ordering of outcomes in the GROUP variable, numeric
the timing of the time-to-event outcomes, numeric
original values for each type of the event, time for TTE outcomes, numeric values for Continuous outcomes, numeric
AVAL = AVAL0 + GROUPN, ordinal analysis values for the HCE analysis. For the continuous outcome the values of AVAL0 are shifted to start always from 0. Numeric, but caution NOT to apply numeric operations; will give meaningless results
primary analysis day, the length of fixed follow-up in days, numeric
HCE1, HCE2, HCE3, HCE4 datasets for 1000 patients with different treatment effects.A simulated dataset containing the ordinal values and other attributes for 1000 patients. HCE2
HCE2HCE2
a data frame with 1000 rows and 6 variables:
subject ID, numbers from 1 to 1000
treatment values, A Active or P Placebo, character
type of the event, either Time-To-Event (TTE) or Continuous (C), character
type of the event, for the ordering of outcomes in the GROUP variable, numeric
the timing of the time-to-event outcomes, numeric
original values for each type of the event, time for TTE outcomes, numeric values for Continuous outcomes, numeric
AVAL = AVAL0 + GROUPN, ordinal analysis values for the HCE analysis. For the continuous outcome the values of AVAL0 are shifted to start always from 0. Numeric, but caution NOT to apply numeric operations; will give meaningless results
primary analysis day, the length of fixed follow-up in days, numeric
HCE1, HCE2, HCE3, HCE4 datasets for 1000 patients with different treatment effects.A simulated dataset containing the ordinal values and other attributes for 1000 patients. HCE3
HCE3HCE3
a data frame with 1000 rows and 6 variables:
subject ID, numbers from 1 to 1000
treatment values, A Active or P Placebo, character
type of the event, either Time-To-Event (TTE) or Continuous (C), character
type of the event, for the ordering of outcomes in the GROUP variable, numeric
the timing of the time-to-event outcomes, numeric
original values for each type of the event, time for TTE outcomes, numeric values for Continuous outcomes, numeric
AVAL = AVAL0 + GROUPN, ordinal analysis values for the HCE analysis. For the continuous outcome the values of AVAL0 are shifted to start always from 0. Numeric, but caution NOT to apply numeric operations; will give meaningless results
primary analysis day, the length of fixed follow-up in days, numeric
HCE1, HCE2, HCE3, HCE4 datasets for 1000 patients with different treatment effects.A simulated dataset containing the ordinal values and other attributes for 1000 patients. HCE4
HCE4HCE4
a data frame with 1000 rows and 6 variables:
subject ID, numbers from 1 to 1000
treatment values, A Active or P Placebo, character
type of the event, either Time-To-Event (TTE) or Continuous (C), character
type of the event, for the ordering of outcomes in the GROUP variable, numeric
the timing of the time-to-event outcomes, numeric
original values for each type of the event, time for TTE outcomes, numeric values for Continuous outcomes, numeric
AVAL = AVAL0 + GROUPN, ordinal analysis values for the HCE analysis. For the continuous outcome the values of AVAL0 are shifted to start always from 0. Numeric, but caution NOT to apply numeric operations; will give meaningless results
primary analysis day, the length of fixed follow-up in days, numeric
Calculates patient-level individual win proportions
IWP(data, AVAL, TRTP, ref)IWP(data, AVAL, TRTP, ref)
data |
a data frame containing subject-level data. |
AVAL |
variable in the data with ordinal analysis values. |
TRTP |
the treatment variable in the data. |
ref |
the reference treatment group. |
the input data frame with a new column of individual win proportions named using the input AVAL value with _.
Gasparyan SB et al. "Adjusted win ratio with stratification: calculation methods and interpretation." Statistical Methods in Medical Research 30.2 (2021): 580-611. https://doi.org/10.1177/0962280220942558.
calcWO(), calcWO.hce(), calcWO.formula().
KHCE1 <- IWP(data = KHCE, AVAL = "EGFRBL", TRTP = "TRTPN", ref = 2) WP <- tapply(KHCE1$EGFRBL_, KHCE1$TRTPN, mean) VAR <- tapply(KHCE1$EGFRBL_, KHCE1$TRTPN, function(x) (length(x)-1)*var(x)/length(x)) N <- tapply(KHCE1$EGFRBL_, KHCE1$TRTPN, length) SE <- sqrt(sum(VAR/N)) c(WP = WP[[1]], SE = SE) calcWO(EGFRBL ~ TRTP, data = KHCE)[c("WP", "SE_WP")]KHCE1 <- IWP(data = KHCE, AVAL = "EGFRBL", TRTP = "TRTPN", ref = 2) WP <- tapply(KHCE1$EGFRBL_, KHCE1$TRTPN, mean) VAR <- tapply(KHCE1$EGFRBL_, KHCE1$TRTPN, function(x) (length(x)-1)*var(x)/length(x)) N <- tapply(KHCE1$EGFRBL_, KHCE1$TRTPN, length) SE <- sqrt(sum(VAR/N)) c(WP = WP[[1]], SE = SE) calcWO(EGFRBL ~ TRTP, data = KHCE)[c("WP", "SE_WP")]
A dataset with kidney ordinal scale outcomes of 1500 patients in the ADSL dataset.
KHCEKHCE
a data frame with 1500 rows and 11 variables:
patient identifiers, numeric
treatment values, 1 Active or 2 Placebo, numeric
original values for each type of the event, time for TTE outcomes 1-6, numeric values for Continuous outcome 7, numeric
AVAL = AVAL0 + GROUPN, ordinal analysis values for the HCE analysis, numeric, but caution NOT to apply numeric operations; will give meaningless results
name of the event, character
ordinal outcomes corresponding to PARAMN values, numeric
coded name of the event, character
severity of the event, outcomes 1-7, where a higher value means a better outcome, character
strata 1-4, higher value means more severe kidney disease, numeric
Baseline GFR values of patients, numeric
treatment values, A Active or P Placebo, character
primary analysis day (in years), length of the fixed follow-up, numeric
Heerspink HL et al "Development and validation of a new hierarchical composite endpoint for clinical trials of kidney disease progression." Journal of the American Society of Nephrology (2023): https://doi.org/10.1681/ASN.0000000000000243.
# Adjusted win odds res <- regWO(x = KHCE, AVAL = "AVAL", TRTP = "TRTP", COVAR = "STRATAN", ref = "P") res # Convert the dataset to an adhce object. ## First check that `GROUP` is a factor with the correct ordering of outcomes. class(KHCE$GROUP) # "factor" levels(KHCE$GROUP) dat1 <- as_hce(KHCE) class(dat1) calcWO(dat1) ## Re-derive individual patient eGFR slopes using a linear regression model, ## based on the eGFR measurements in the `ADLB` dataset dat2 <- KHCE l <- lapply( split(ADLB, ADLB$ID), function(x) coef(lm(AVAL ~ ADAY, data = x))[2]) new_slopes <- do.call(rbind, l) new_slopes <- as.data.frame(new_slopes) names(new_slopes) <- "LINEAR" new_slopes$ID <- as.numeric(row.names(new_slopes)) dat2 <- merge(KHCE, new_slopes, by = "ID", all.x = TRUE) dat2$AVAL0[dat2$PARAMCD == "eGFR"] <- dat2$LINEAR[dat2$PARAMCD == "eGFR"] dat2$AVAL0[is.na(dat2$AVAL0)] <- 0 dat2 <- as_hce(dat2) calcWO(dat2)# Adjusted win odds res <- regWO(x = KHCE, AVAL = "AVAL", TRTP = "TRTP", COVAR = "STRATAN", ref = "P") res # Convert the dataset to an adhce object. ## First check that `GROUP` is a factor with the correct ordering of outcomes. class(KHCE$GROUP) # "factor" levels(KHCE$GROUP) dat1 <- as_hce(KHCE) class(dat1) calcWO(dat1) ## Re-derive individual patient eGFR slopes using a linear regression model, ## based on the eGFR measurements in the `ADLB` dataset dat2 <- KHCE l <- lapply( split(ADLB, ADLB$ID), function(x) coef(lm(AVAL ~ ADAY, data = x))[2]) new_slopes <- do.call(rbind, l) new_slopes <- as.data.frame(new_slopes) names(new_slopes) <- "LINEAR" new_slopes$ID <- as.numeric(row.names(new_slopes)) dat2 <- merge(KHCE, new_slopes, by = "ID", all.x = TRUE) dat2$AVAL0[dat2$PARAMCD == "eGFR"] <- dat2$LINEAR[dat2$PARAMCD == "eGFR"] dat2$AVAL0[is.na(dat2$AVAL0)] <- 0 dat2 <- as_hce(dat2) calcWO(dat2)
Minimum detectable or WO for alternative hypothesis for given power (no ties)
minWO(N, power = 0.5, SD = NULL, k = 0.5, alpha = 0.05, WOnull = 1, digits = 2)minWO(N, power = 0.5, SD = NULL, k = 0.5, alpha = 0.05, WOnull = 1, digits = 2)
N |
a numeric vector of sample size values (two arms combined). |
power |
the given power. The default is 0.5 corresponding to the minimum detectable win odds. A numeric vector of length 1. |
SD |
assumed standard deviation of the win proportion. By default uses the conservative SD. A numeric vector of length 1. |
k |
proportion of active group in the overall sample size. Default is 0.5 (balanced randomization). A numeric vector of length 1. |
alpha |
the significance level for the 2-sided test. Default is 0.05. A numeric vector of length 1. |
WOnull |
the win odds value of the null hypothesis (default is 1). A numeric vector of length 1. |
digits |
precision to use for reporting calculated win odds. |
a data frame containing the calculated WO with input values.
Gasparyan SB et al. (2021) "Power and sample size calculation for the win odds test: application to an ordinal endpoint in COVID-19 trials." Journal of Biopharmaceutical Statistics 31.6: 765-787. https://doi.org/10.1080/10543406.2021.1968893.
powerWO(), sizeWO() for WO power and sample size calculation.
minWO(N = 100, digits = 5) minWO(N = 1200, power = 0.9, k = 0.75) # Compare the minimum detectable win odds from shifted alternatives to max and ordered alternatives WO <- minWO(N = 1200, k = 0.5, power = 0.67, digits = 7)$WO powerWO(N = 1200, WO = WO, k = 0.5, alternative = "shift") powerWO(N = 1200, WO = WO, k = 0.5, alternative = "ordered") powerWO(N = 1200, WO = WO, k = 0.5, alternative = "max")minWO(N = 100, digits = 5) minWO(N = 1200, power = 0.9, k = 0.75) # Compare the minimum detectable win odds from shifted alternatives to max and ordered alternatives WO <- minWO(N = 1200, k = 0.5, power = 0.67, digits = 7)$WO powerWO(N = 1200, WO = WO, k = 0.5, alternative = "shift") powerWO(N = 1200, WO = WO, k = 0.5, alternative = "ordered") powerWO(N = 1200, WO = WO, k = 0.5, alternative = "max")
hce objectsOrdinal dominance graph for hce objects
## S3 method for class 'hce' plot(x, fill = FALSE, ...)## S3 method for class 'hce' plot(x, fill = FALSE, ...)
x |
an object of class |
fill |
logical; if |
... |
additional arguments to be passed to |
no return value, called for plotting.
Bamber D. "The area above the ordinal dominance graph and the area below the receiver operating characteristic graph." Journal of Mathematical Psychology 12.4 (1975): 387-415. https://doi.org/10.1016/0022-2496(75)90001-2
d <- as_hce(KHCE) d$TRTP <- factor(d$TRTP, levels = c("P", "A")) res <- calcWO(AVAL ~ TRTP, data = d) # Ordinal Dominance Graph plot(d, col = 3, type = 'l') grid() # Area above the Ordinal Dominance Graph plot(d, fill = TRUE, col = "#865A4F", type = 'l', lwd = 2, xlab = "Control", ylab = "Active") legend("bottomright", legend = paste0("WP = ", round(res$WP, 5))) abline(a = 0, b = 1, lwd = 2, lty = 2, col = "#999999")d <- as_hce(KHCE) d$TRTP <- factor(d$TRTP, levels = c("P", "A")) res <- calcWO(AVAL ~ TRTP, data = d) # Ordinal Dominance Graph plot(d, col = 3, type = 'l') grid() # Area above the Ordinal Dominance Graph plot(d, fill = TRUE, col = "#865A4F", type = 'l', lwd = 2, xlab = "Control", ylab = "Active") legend("bottomright", legend = paste0("WP = ", round(res$WP, 5))) abline(a = 0, b = 1, lwd = 2, lty = 2, col = "#999999")
hce_results objectsA print method for hce_results objects
## S3 method for class 'hce_results' plot(x, ...)## S3 method for class 'hce_results' plot(x, ...)
x |
an object of class |
... |
additional arguments to be passed to |
no return value, called for plotting.
WO <- minWO(N = 100:1000) plot(WO) POW <- powerWO(N = 100:1000, WO = 1.2) plot(POW, ylim = c(0, 1))WO <- minWO(N = 100:1000) plot(WO) POW <- powerWO(N = 100:1000, WO = 1.2) plot(POW, ylim = c(0, 1))
Power calculation for the win odds test (no ties)
powerWO( N, WO, SD = NULL, k = 0.5, alpha = 0.05, WOnull = 1, alternative = c("shift", "max", "ordered") )powerWO( N, WO, SD = NULL, k = 0.5, alpha = 0.05, WOnull = 1, alternative = c("shift", "max", "ordered") )
N |
a numeric vector of sample size values. |
WO |
the given win odds for the alternative hypothesis. A numeric vector of length 1. |
SD |
assumed standard deviation of the win proportion. By default uses the conservative SD. A numeric vector of length 1. |
k |
proportion of active group in the overall sample size. Default is 0.5 (balanced randomization). A numeric vector of length 1. |
alpha |
the significance level for the 2-sided test. Default is 0.05. A numeric vector of length 1. |
WOnull |
the win odds value of the null hypothesis (default is 1). A numeric vector of length 1. |
alternative |
a character string specifying the class of the alternative hypothesis, must be one of |
alternative = "max" refers to the maximum variance of the win proportion across all possible
alternatives. The maximum variance equals WP*(1 - WP)/k where the win probability is calculated as WP = WO/(WO + 1).
alternative = "shift" specifies the variance across alternatives from a shifted family of distributions (Wilcoxon test). The variance formula, as suggested by Noether, is calculated based on the null hypothesis as follows 1/(12*k*(1 - k)).
alternative = "ordered" specifies the variance across alternatives from stochastically ordered distributions which include shifted distributions.
a data frame containing the calculated power with input values.
All formulas were presented in
Bamber D (1975) "The area above the ordinal dominance graph and the area below the receiver operating characteristic graph." Journal of Mathematical Psychology 12.4: 387-415. https://doi.org/10.1016/0022-2496(75)90001-2.
Noether's formula for shifted alternatives
Noether GE (1987) "Sample size determination for some common nonparametric tests." Journal of the American Statistical Association 82.398: 645-7. https://doi.org/10.1080/01621459.1987.10478478.
For shift alternatives see also
Gasparyan SB et al. (2021) "Power and sample size calculation for the win odds test: application to an ordinal endpoint in COVID-19 trials." Journal of Biopharmaceutical Statistics 31.6: 765-787. https://doi.org/10.1080/10543406.2021.1968893.
sizeWO(), minWO() for WO sample size or minimum detectable WO calculation.
# Example 1- Use the default standard deviation powerWO(N = 1000, WO = 1.2) powerWO(N = seq(500, 1500, 100), WO = 1.2) # Example 2 - Use data-driven win odds and standard deviation from the COVID19 dataset res <- calcWO(x = COVID19, AVAL = "GROUP", TRTP = "TRTP", ref = "Placebo") print(res) powerWO(N = 500, WO = res$WO, SD = res$SD_WP) powerWO(N = 500, WO = res$WO) # power with the default standard deviation for the win proportion. # Example 3 - Non-balanced 3:1 randomization powerWO(N = 1000, WO = 1.2, k = 0.75) # Example 4 - Comparison of different alternatives powerWO(N = 1000, WO = 1.2, alternative = "m") powerWO(N = 1000, WO = 1.2, alternative = "s") powerWO(N = 1000, WO = 1.2, alternative = "o")# Example 1- Use the default standard deviation powerWO(N = 1000, WO = 1.2) powerWO(N = seq(500, 1500, 100), WO = 1.2) # Example 2 - Use data-driven win odds and standard deviation from the COVID19 dataset res <- calcWO(x = COVID19, AVAL = "GROUP", TRTP = "TRTP", ref = "Placebo") print(res) powerWO(N = 500, WO = res$WO, SD = res$SD_WP) powerWO(N = 500, WO = res$WO) # power with the default standard deviation for the win proportion. # Example 3 - Non-balanced 3:1 randomization powerWO(N = 1000, WO = 1.2, k = 0.75) # Example 4 - Comparison of different alternatives powerWO(N = 1000, WO = 1.2, alternative = "m") powerWO(N = 1000, WO = 1.2, alternative = "s") powerWO(N = 1000, WO = 1.2, alternative = "o")
hce_results objectsA print method for hce_results objects
## S3 method for class 'hce_results' print(x, ...)## S3 method for class 'hce_results' print(x, ...)
x |
an object of class |
... |
additional arguments to be passed to |
no return value, called for printing.
print(powerWO(N = 1000, WO = 1.2))print(powerWO(N = 1000, WO = 1.2))
Proportion of wins/losses/ties given the win odds and the win ratio
propWINS(WO, WR, Overall = 1, alpha = NULL, N = NULL)propWINS(WO, WR, Overall = 1, alpha = NULL, N = NULL)
WO |
win odds. |
WR |
win ratio. |
Overall |
number of comparisons, the sample size of the active treatment multiplied by the sample size of the placebo. The default is 1, hence gives the proportion. |
alpha |
significance level for the win ratio confidence interval. The default is |
N |
the combined sample size of two treatment groups. The default is |
a data frame with a number (or proportion if Overall = 1) of wins/losses/ties. If alpha is specified returns also WR confidence interval.
For the relationship between win odds and win ratio see
Gasparyan SB et al. "Hierarchical Composite Endpoints in COVID-19: The DARE-19 Trial". Case Studies in Innovative Clinical Trials, Chapter 7 (2023): 95-148. Chapman and Hall/CRC. https://doi.org/10.1201/9781003288640-7.
The win ratio CI uses the standard error presented in
Yu RX, Ganju J. (2022) "Sample size formula for a win ratio endpoint." Statistics in Medicine 41.6: 950-63. https://doi.org/10.1002/sim.9297.
# Example 1 propWINS(WR = 2, WO = 1.5) # Example 2 - Back-calculation COVID19HCE <- hce(GROUP = COVID19$GROUP, TRTP = COVID19$TRTP) res <- calcWINS(COVID19HCE) WR <- res$WR1$WR WO <- res$WO$WO Overall <- res$summary$TOTAL propWINS(WR = WR, WO = WO, Overall = Overall) ## Verify res$summary # Example 3 - Confidence interval propWINS(WR = 1.4, WO = 1.3, alpha = 0.05, Overall = 2500) propWINS(WR = 2, WO = 1.5, alpha = 0.01, N = 500)# Example 1 propWINS(WR = 2, WO = 1.5) # Example 2 - Back-calculation COVID19HCE <- hce(GROUP = COVID19$GROUP, TRTP = COVID19$TRTP) res <- calcWINS(COVID19HCE) WR <- res$WR1$WR WO <- res$WO$WO Overall <- res$summary$TOTAL propWINS(WR = WR, WO = WO, Overall = Overall) ## Verify res$summary # Example 3 - Confidence interval propWINS(WR = 1.4, WO = 1.3, alpha = 0.05, Overall = 2500) propWINS(WR = 2, WO = 1.5, alpha = 0.01, N = 500)
A generic function for win odds regression
regWO(x, ...)regWO(x, ...)
x |
an object used to select a method. |
... |
further arguments passed to or from other methods. |
a data frame containing calculated values.
regWO.data.frame(), regWO.formula() methods.
This function performs regression analysis for the win odds using a single numeric covariate.
## S3 method for class 'data.frame' regWO(x, AVAL, TRTP, COVAR, ref, alpha = 0.05, WOnull = 1, ...)## S3 method for class 'data.frame' regWO(x, AVAL, TRTP, COVAR, ref, alpha = 0.05, WOnull = 1, ...)
x |
a data frame containing subject-level data. |
AVAL |
a variable in the data with ordinal analysis values. |
TRTP |
the treatment variable in the data. |
COVAR |
a numeric covariate. |
ref |
the reference treatment group. |
alpha |
the significance level, with a default value of 0.05. |
WOnull |
the null hypothesis value for win odds. The default is 1. |
... |
additional parameters. |
a data frame containing the calculated win odds and its confidence interval, including:
WO_beta adjusted win odds.
LCL lower confidence limit for adjusted WO.
UCL upper confidence limit for adjusted WO.
SE standard error of the adjusted win odds.
WOnull win odds of the null hypothesis (specified in the WOnull argument).
alpha two-sided significance level for calculating the confidence interval (specified in the alpha argument).
Pvalue p-value associated with testing the null hypothesis.
N total number of patients in the analysis.
beta adjusted win probability.
LCL_beta lower confidence limit for adjusted win probability.
UCL_beta upper confidence limit for adjusted win probability.
SE_beta standard error for the adjusted win probability.
SD_beta standard deviation for the adjusted win probability.
WP (non-adjusted) win probability.
SE_WP standard error of the non-adjusted win probability.
SD_WP standard deviation of the non-adjusted win probability.
WO non-adjusted win odds.
COVAR_MEAN_DIFF mean difference between two treatment groups of the numeric covariate.
COVAR_VAR sum of variances of two treatment groups of the numeric covariate.
COVAR_COV covariance between the response and the numeric covariate.
Gasparyan SB et al. (2021) "Adjusted win ratio with stratification: calculation methods and interpretation." Statistical Methods in Medical Research 30.2: 580-611. https://doi.org/10.1177/0962280220942558.
# A baseline covariate that is highly correlated with the outcome set.seed(2023) dat <- COVID19 n <- nrow(dat) dat$Severity <- ifelse(dat$GROUP > 4, rnorm(n, 0), rnorm(n, 100)) tapply(dat$Severity, dat$TRTP, mean) regWO(x = dat, AVAL = "GROUP", TRTP = "TRTP", COVAR = "Severity", ref = "Placebo") # Without adjustment calcWO(x = dat, AVAL = "GROUP", TRTP = "TRTP", ref = "Placebo")# A baseline covariate that is highly correlated with the outcome set.seed(2023) dat <- COVID19 n <- nrow(dat) dat$Severity <- ifelse(dat$GROUP > 4, rnorm(n, 0), rnorm(n, 100)) tapply(dat$Severity, dat$TRTP, mean) regWO(x = dat, AVAL = "GROUP", TRTP = "TRTP", COVAR = "Severity", ref = "Placebo") # Without adjustment calcWO(x = dat, AVAL = "GROUP", TRTP = "TRTP", ref = "Placebo")
This function performs regression analysis for the win odds using a single numeric covariate.
## S3 method for class 'formula' regWO(x, data, ...)## S3 method for class 'formula' regWO(x, data, ...)
x |
an object of class formula. |
data |
a data frame. |
... |
additional parameters. |
a data frame containing the calculated win odds and its confidence interval, including:
WO_beta adjusted win odds.
LCL lower confidence limit for adjusted WO.
UCL upper confidence limit for adjusted WO.
SE standard error of the adjusted win odds.
WOnull win odds of the null hypothesis (specified in the WOnull argument).
alpha two-sided significance level for calculating the confidence interval (specified in the alpha argument).
Pvalue p-value associated with testing the null hypothesis.
N total number of patients in the analysis.
beta adjusted win probability.
LCL_beta lower confidence limit for adjusted win probability.
UCL_beta upper confidence limit for adjusted win probability.
SE_beta standard error for the adjusted win probability.
SD_beta standard deviation for the adjusted win probability.
WP (non-adjusted) win probability.
SE_WP standard error of the non-adjusted win probability.
SD_WP standard deviation of the non-adjusted win probability.
WO non-adjusted win odds.
COVAR_MEAN_DIFF mean difference between two treatment groups of the numeric covariate.
COVAR_VAR sum of variances of two treatment groups of the numeric covariate.
COVAR_COV covariance between the response and the numeric covariate.
formula returning the specified formula in the x argument.
ref showing how the reference group was selected. Can be modifying by specifying the ref argument.
Gasparyan SB et al. (2021) "Adjusted win ratio with stratification: calculation methods and interpretation." Statistical Methods in Medical Research 30.2: 580-611. https://doi.org/10.1177/0962280220942558.
regWO(AVAL ~ TRTP, data = KHCE) regWO(AVAL ~ TRTP + EGFRBL, data = KHCE)regWO(AVAL ~ TRTP, data = KHCE) regWO(AVAL ~ TRTP + EGFRBL, data = KHCE)
Simulate random numbers from a Weibull distribution with gamma frailty
rweibullGF(n, rate, shape = 1, theta = 1)rweibullGF(n, rate, shape = 1, theta = 1)
n |
number of observations. |
rate |
rate parameter of the Weibull distribution. |
shape |
shape parameter of the Weibull distribution, with a default value of 1 (exponential). |
theta |
variance parameter of the gamma frailty distribution, with a default value of 1. |
Let denote a frailty term following a gamma distribution with
and . Then has mean 1
and variance .
Conditional on , the survival function is
where is the shape parameter and is the rate parameter.
Integrating over the gamma frailty distribution gives the marginal survival function
This corresponds to the generalized log-logistic distribution (GLL) as implemented in GLL().
As , this reduces to the standard Weibull distribution
without frailty, with survival function
This corresponds to the Weibull distribution in stats::pweibull() with shape = shape and scale = rate^(-1 / shape).
When , the survival function becomes
which is the survival function of a log-logistic distribution.
a vector of random numbers of length n.
Wienke A. "Frailty Models in Survival Analysis." Chapman and Hall/CRC (2010).
simTTE() for simulation of a two-event time-to-event endpoint
from this distribution under the illness-death model.
pGLL() provides the cumulative distribution function of the
generalized log-logistic distribution.
## Example 1: each patient has a sampled time with potentially different ## shape, rate, and theta values. set.seed(123) n <- 1000 d <- data.frame(ID = 1:(2*n), TRTP = rep(c("A", "P"), each = n), rate = rep(c(0.1, 0.15), each = n), shape = 1.5, theta = 1) d$time1 <- rweibullGF(n = 2*n, rate = d$rate, shape = d$shape, theta = d$theta) tapply(d$time1, d$TRTP, summary) ## Example 2: all patients share the same parameter values. d$time2 <- rweibullGF(n = 2*n, rate = 0.1, theta = 0) tapply(d$time2, d$TRTP, summary)## Example 1: each patient has a sampled time with potentially different ## shape, rate, and theta values. set.seed(123) n <- 1000 d <- data.frame(ID = 1:(2*n), TRTP = rep(c("A", "P"), each = n), rate = rep(c(0.1, 0.15), each = n), shape = 1.5, theta = 1) d$time1 <- rweibullGF(n = 2*n, rate = d$rate, shape = d$shape, theta = d$theta) tapply(d$time1, d$TRTP, summary) ## Example 2: all patients share the same parameter values. d$time2 <- rweibullGF(n = 2*n, rate = 0.1, theta = 0) tapply(d$time2, d$TRTP, summary)
hce objectSimulate an hce object with multiple, possibly correlated (Hougaard copula) Weibull time‑to‑event outcomes and a single continuous endpoint (normal or log‑normal)
simHCE( n, n0 = n, TTE_A, TTE_P, CM_A, CM_P, CSD_A = 1, CSD_P = CSD_A, fixedfy = 1, yeardays = 360, pat = 100, shape = 1, theta = 1, logC = FALSE, seed = NULL, dec = 2, all_data = FALSE )simHCE( n, n0 = n, TTE_A, TTE_P, CM_A, CM_P, CSD_A = 1, CSD_P = CSD_A, fixedfy = 1, yeardays = 360, pat = 100, shape = 1, theta = 1, logC = FALSE, seed = NULL, dec = 2, all_data = FALSE )
n |
sample size in the active treatment group. |
n0 |
sample size in the placebo group. |
TTE_A |
event rates per year in the active group for the time-to-event outcomes. |
TTE_P |
event rates per year in the placebo group for the time-to-event outcomes. Should have the same length as |
CM_A |
mean value for the continuous outcome of the active group. |
CM_P |
mean value for the continuous outcome of the placebo group. |
CSD_A |
standard deviation for the continuous outcome of the active group. |
CSD_P |
standard deviation for the continuous outcome of the placebo group. |
fixedfy |
length of follow-up in years. |
yeardays |
number of days in a year. |
pat |
scale of provided event rates (per |
shape |
shape of the Weibull distribution for time-to-event outcomes. Default is exponential distribution with |
theta |
Gumbel dependence coefficient of the Weibull distributions for time-to-event outcomes. Default is |
logC |
logical, whether to use log-normal distribution for the continuous outcome. |
seed |
for generating random numbers. |
dec |
decimal places for the continuous outcome used for rounding. The default is |
all_data |
logical, whether to return source datasets |
an object of class hce containing the following columns:
ID subject identifier.
TRTP planned treatment group - "A" for active, "P" for Placebo.
GROUP type of the outcome, either "TTE" for time-to-event outcomes or "C" for continuous. Only one continuous outcome is possible, but no restriction on the number of "TTE" outcomes.
GROUPN order of outcomes in GROUP, with a higher value signifying a better outcome.
AVALT the timing of the time-to-event outcomes.
AVAL0 numeric values of the continuous outcome and the timing of "TTE" outcomes.
AVAL analysis values derived as AVAL0 + GROUPN. For the continuous outcome the values of AVAL0 are shifted to start always from 0.
seed the seed of the random sample. If not specified in seed argument will be selected based on system time.
PADY primary analysis day, the length of fixed follow-up in days calculated as yeardays multiplied by fixedfy.
If all_data = TRUE, the function returns a list containing the hce dataset, along with its source datasets: ADET (an event-time dataset for all time-to-event outcomes per patient) and BDS (a basic data structure for the continuous outcome for all patients).
hce(), as_hce() for the helper a coerce function to hce objects.
# Example 1 Rates_A <- c(1.72, 1.74, 0.58, 1.5, 1) Rates_P <- c(2.47, 2.24, 2.9, 4, 6) dat <- simHCE(n = 2500, TTE_A = Rates_A, TTE_P = Rates_P, CM_A = -3, CM_P = -6, CSD_A = 16, CSD_P = 15, fixedfy = 3) head(dat) # Example 2 Rates_A <- 10 Rates_P <- 15 dat <- simHCE(n = 1000, n0 = 500, TTE_A = Rates_A, TTE_P = Rates_P, CM_A = 0.1, CM_P = 0, seed = 5, shape = 0.2, logC = TRUE, dec = 0) summaryWO(dat) # Example 3: Comparison of dependent and independent outcomes Rates_A <- c(10, 20) Rates_P <- c(20, 20) dat1 <- simHCE(n = 2500, TTE_A = Rates_A, TTE_P = Rates_P, CM_A = -3, CM_P = -6, CSD_A = 15, fixedfy = 3, theta = 1, seed = 1) dat2 <- simHCE(n = 2500, TTE_A = Rates_A, TTE_P = Rates_P, CM_A = -3, CM_P = -6, CSD_A = 15, fixedfy = 3, theta = 1.0001, seed = 1) calcWO(dat1) calcWO(dat2)# Example 1 Rates_A <- c(1.72, 1.74, 0.58, 1.5, 1) Rates_P <- c(2.47, 2.24, 2.9, 4, 6) dat <- simHCE(n = 2500, TTE_A = Rates_A, TTE_P = Rates_P, CM_A = -3, CM_P = -6, CSD_A = 16, CSD_P = 15, fixedfy = 3) head(dat) # Example 2 Rates_A <- 10 Rates_P <- 15 dat <- simHCE(n = 1000, n0 = 500, TTE_A = Rates_A, TTE_P = Rates_P, CM_A = 0.1, CM_P = 0, seed = 5, shape = 0.2, logC = TRUE, dec = 0) summaryWO(dat) # Example 3: Comparison of dependent and independent outcomes Rates_A <- c(10, 20) Rates_P <- c(20, 20) dat1 <- simHCE(n = 2500, TTE_A = Rates_A, TTE_P = Rates_P, CM_A = -3, CM_P = -6, CSD_A = 15, fixedfy = 3, theta = 1, seed = 1) dat2 <- simHCE(n = 2500, TTE_A = Rates_A, TTE_P = Rates_P, CM_A = -3, CM_P = -6, CSD_A = 15, fixedfy = 3, theta = 1.0001, seed = 1) calcWO(dat1) calcWO(dat2)
hce datasetSimulate a kidney disease hce dataset, capturing eGFR (Estimated Glomerular Filtration Rate) progression over time, along with
a competing and dependent terminal event: KFRT (Kidney Failure Replacement Therapy)
simKHCE( n, CM_A, CM_P = -4, n0 = n, TTE_A = 1000, TTE_P = TTE_A, fixedfy = 2, Emin = 20, Emax = 100, sigma = NULL, Sigma = 3, m = 10, theta = -0.4605, phi = 0, two_meas = c("no", "base", "postbase", "both"), df_sigma = Inf )simKHCE( n, CM_A, CM_P = -4, n0 = n, TTE_A = 1000, TTE_P = TTE_A, fixedfy = 2, Emin = 20, Emax = 100, sigma = NULL, Sigma = 3, m = 10, theta = -0.4605, phi = 0, two_meas = c("no", "base", "postbase", "both"), df_sigma = Inf )
n |
sample size in the active treatment group. |
CM_A |
annualized eGFR slope in the active group. |
CM_P |
annualized eGFR slope in the control group. |
n0 |
sample size in the control treatment group. |
TTE_A |
event rate per year in the active group for KFRT. |
TTE_P |
event rate per year in the placebo group for KFRT. |
fixedfy |
length of follow-up in years. |
Emin |
lower limit of eGFR at baseline. |
Emax |
upper limit of eGFR at baseline. |
sigma |
within-patient standard deviation. |
Sigma |
between-patient standard deviation. |
m |
number of equidistant visits. |
theta |
coefficient of dependence of eGFR values and the risk of KFRT. |
phi |
coefficient of proportionality (between 0 and 1) of the treatment effect. The case of 0 corresponds to the uniform treatment effect. |
two_meas |
determines whether to use duplicate measurements at baseline and/or at |
df_sigma |
degrees of freedom for the measurement error distribution. The default |
The default setting is TTE_A = TTE_P because, conditional on eGFR level,
the treatment effect does not influence the event rate of KFRT. In this model,
the effect of treatment on KFRT operates entirely through its impact on eGFR decline.
Let CM_A and CM_P be denoted by and , respectively.
Let TTE_A and TTE_P be denoted by and , respectively.
Let theta be denoted by , phi by , sigma by ,
Sigma by , and df_sigma by .
The parameters TTE_A and theta are chosen so that when GFR is 15, the event rate
is 1 per patient per year, and when GFR is 25, the event rate is 0.01 per patient per year. These
parameter values are obtained by solving
for the group-specific baseline rate and . When the observed eGFR is above 30,
the event rate is set to a very low value (10e-7), while when the observed eGFR is below or equal to 7,
the event rate is set to a very high value (10e5). This ensures that patients with observed low eGFR values
always experience KFRT, while those with high eGFR values do not.
By default, the within-patient standard deviation, sigma, is set to NULL. When left as NULL, sigma
is calculated as
where denotes the predicted eGFR for patient at visit . This yields
time-dependent measurement variability, with lower predicted eGFR values corresponding to lower variability.
In the implementation, to prevent the variance from becoming negative or too small, the quantity
is truncated below at 0.1 before taking the square root.
When df_sigma = Inf (the default), measurement errors are normally distributed:
When df_sigma is finite and greater than 2, measurement errors follow a Student t distribution
with heavier tails:
where df_sigma and is a standard t random variable with
degrees of freedom. This scaling preserves the same time-dependent standard deviation defined by sigma,
so that
Given the overall effect Delta and the placebo progression rate CM_P, a fully uniform (purely additive)
treatment effect—meaning the same average effect applies to all patients regardless of baseline progression—is
implemented by setting and
A fully proportional treatment effect—no additive component, the effect scales with the baseline rate—is implemented by setting
and
A more relativistic intermediate effect (half additive and half proportional) is obtained by setting
and
The kidney hierarchical composite endpoint is defined in the following order: (1) Kidney Failure Replacement Therapy (KFRT); (2) Sustained eGFR < 15; (3) Sustained 57 percent or more decline in eGFR; (4) Sustained 50 percent or more decline in eGFR; (5) Sustained 40 percent or more decline in eGFR; and (6) Change in eGFR. In practice, because KFRT is frequently initiated when true eGFR is very low, sustained eGFR < 15 events are rarely observed.
If two_meas is not "no", a second measurement is generated using the same latent baseline eGFR and
subject-specific slope, but with an independent measurement error draw from the same distribution as above.
The two measurements are then averaged at baseline when two_meas = "base", at the final visit when
two_meas = "postbase", or at both baseline and the final visit when two_meas = "both". This implementation
preserves correlation between the duplicate measurements because they share the same underlying true trajectory.
simHCE() for a general function of simulating hce datasets.
# Example - Specifying the most important variables set.seed(2022) ## The overall treatment effect Delta <- 0.75 ## The placebo progression rate CM_P <- - 4.5 ## Intermediate effect (half additive and half proportional) delta <- Delta/2 CM_A <- delta + CM_P phi <- Delta / (2*abs(CM_P)) L <- simKHCE(n = 1000, CM_A = CM_A, CM_P = CM_P, fixedfy = 4, Emin = 25, Emax = 75, phi = phi) dat <- L$HCE calcWO(dat)# Example - Specifying the most important variables set.seed(2022) ## The overall treatment effect Delta <- 0.75 ## The placebo progression rate CM_P <- - 4.5 ## Intermediate effect (half additive and half proportional) delta <- Delta/2 CM_A <- delta + CM_P phi <- Delta / (2*abs(CM_P)) L <- simKHCE(n = 1000, CM_A = CM_A, CM_P = CM_P, fixedfy = 4, Emin = 25, Emax = 75, phi = phi) dat <- L$HCE calcWO(dat)
Simulate ordinal variables for two treatment groups using categorization of beta distributions
simORD(n, n0 = n, M, alpha1 = 8, beta1 = 7, alpha0 = 5, beta0 = 5)simORD(n, n0 = n, M, alpha1 = 8, beta1 = 7, alpha0 = 5, beta0 = 5)
n |
sample size in the active treatment group. |
n0 |
sample size in the placebo group. |
M |
number of ordinal values to be simulated. |
alpha1 |
shape1 parameter for the beta distribution in the active group. |
beta1 |
shape2 parameter for the beta distribution in the active group. |
alpha0 |
shape1 parameter for the beta distribution in the placebo group. |
beta0 |
shape2 parameter for the beta distribution in the placebo group. |
a data frame containing the following columns:
ID subject identifier.
TRTP planned treatment group - "A" for active, "P" for Placebo.
GROUPN ordinal values. The number of unique values is specified by the variable M0.
tau the theoretical win odds.
theta the theoretical win probability.
simHCE() for simulating hce objects.
# Example 1 set.seed(2024) alpha1 <- 8 beta1 <- 8 alpha0 <- 4 beta0 <- 5 d <- simORD(n = 1500, n0 = 1500, M = 5, alpha1 = alpha1, beta1 = beta1, alpha0 = alpha0, beta0 = beta0) x <- seq(0, 1, 0.01) plot(x, dbeta(x, shape1 = alpha1, shape2 = beta1), type = "l", ylab = "Density of beta distribution", col = 2) lines(x, dbeta(x, shape1 = alpha0, shape2 = beta0), col = 3, lty = 2) legend("topleft", lty = c(1, 2), col = c(2, 3), legend = c("Control", "Active")) D <- hce(GROUP = d$GROUPN, TRTP = d$TRTP) table(D$TRTP, D$GROUP) calcWO(D) # Example 2 set.seed(2024) d <- simORD(n = 100, n0 = 50, M = 2) d_hce <- hce(GROUP = d$GROUPN, TRTP = d$TRTP) calcWO(d_hce) ### compare with the theoretical values of the continuous distributions c(tau = unique(d$tau), theta = unique(d$theta)) # Example 2 - Convergence of the win odds to its theoretical value set.seed(2024) N <- NULL size <- c(seq(10, 500, 1)) for(i in size){ d <- simORD(n = i, M = 2) d_hce <- hce(GROUP = d$GROUPN, TRTP = d$TRTP) TAU <- calcWO(d_hce) D <- data.frame(WO = TAU$WO, n = i, tau = unique(d$tau)) N <- rbind(N, D) } plot(N$n, N$WO, log = "y", ylim = c(0.5, 2), ylab = "Win Odds", xlab = "Sample size", type = "l") lines(N$n, N$tau, col = "darkgreen", lty = 2, lwd = 2) abline(h = 1, lty = 4, col = "red") legend("bottomright", legend = c("Theoretical Win Odds", "Null", "Win Odds Estimate"), lty = c(4, 2, 1), col = c("darkgreen", "red", "black")) title("Convergence of the win odds to its theoretical value")# Example 1 set.seed(2024) alpha1 <- 8 beta1 <- 8 alpha0 <- 4 beta0 <- 5 d <- simORD(n = 1500, n0 = 1500, M = 5, alpha1 = alpha1, beta1 = beta1, alpha0 = alpha0, beta0 = beta0) x <- seq(0, 1, 0.01) plot(x, dbeta(x, shape1 = alpha1, shape2 = beta1), type = "l", ylab = "Density of beta distribution", col = 2) lines(x, dbeta(x, shape1 = alpha0, shape2 = beta0), col = 3, lty = 2) legend("topleft", lty = c(1, 2), col = c(2, 3), legend = c("Control", "Active")) D <- hce(GROUP = d$GROUPN, TRTP = d$TRTP) table(D$TRTP, D$GROUP) calcWO(D) # Example 2 set.seed(2024) d <- simORD(n = 100, n0 = 50, M = 2) d_hce <- hce(GROUP = d$GROUPN, TRTP = d$TRTP) calcWO(d_hce) ### compare with the theoretical values of the continuous distributions c(tau = unique(d$tau), theta = unique(d$theta)) # Example 2 - Convergence of the win odds to its theoretical value set.seed(2024) N <- NULL size <- c(seq(10, 500, 1)) for(i in size){ d <- simORD(n = i, M = 2) d_hce <- hce(GROUP = d$GROUPN, TRTP = d$TRTP) TAU <- calcWO(d_hce) D <- data.frame(WO = TAU$WO, n = i, tau = unique(d$tau)) N <- rbind(N, D) } plot(N$n, N$WO, log = "y", ylim = c(0.5, 2), ylab = "Win Odds", xlab = "Sample size", type = "l") lines(N$n, N$tau, col = "darkgreen", lty = 2, lwd = 2) abline(h = 1, lty = 4, col = "red") legend("bottomright", legend = c("Theoretical Win Odds", "Null", "Win Odds Estimate"), lty = c(4, 2, 1), col = c("darkgreen", "red", "black")) title("Convergence of the win odds to its theoretical value")
adhce dataset with two correlated outcomes (illness - death model)Simulate an adhce dataset with two correlated outcomes - death and hospitalization - from a heterogeneous population. The correlation between these outcomes arises from population heterogeneity. Models the risk of death following hospitalization as dependent on the timing
of the hospitalization, reflecting strong dependence between the times to the first and second events (i.e., event clustering).
simTTE( n, n0 = n, TTE_A, TTE_P = TTE_A, shape = 1, shape0 = shape, fixedfy = 2, theta = 1, alpha0 = 1, alpha = 1, rHR = 1, m = Inf, hce_type = c("mi", "md") )simTTE( n, n0 = n, TTE_A, TTE_P = TTE_A, shape = 1, shape0 = shape, fixedfy = 2, theta = 1, alpha0 = 1, alpha = 1, rHR = 1, m = Inf, hce_type = c("mi", "md") )
n |
sample size in the active treatment group. |
n0 |
sample size in the placebo treatment group. |
TTE_A |
event rates in the active group for the time-to-event outcomes; a numeric vector of length two. |
TTE_P |
event rates in the placebo group for the time-to-event outcomes; a numeric vector of length two. |
shape |
shape parameter of the Weibull distribution for time-to-event outcomes in the active group. Default is 1 (exponential distribution). |
shape0 |
shape parameter of the Weibull distribution for time-to-event outcomes in the placebo group. Default is 1 (exponential distribution). |
fixedfy |
length of follow-up. |
theta |
heterogeneity coefficient for the first event, modeled via a gamma distribution with mean 1; |
alpha0 |
exponential heterogeneity coefficient for modeling the heterogeneity of risk of death as the first event. |
alpha |
exponential heterogeneity coefficient for modeling the heterogeneity of risk of death after hospitalization; the heterogeneity of the second event is the inverse of the time of the first event. |
rHR |
recurrence hazard ratio comparing the active group to the control group for the second event, based on gap time measured from the first event. |
m |
categorization number used for to discretize time to death and time to hospitalization. Defaults to |
hce_type |
the type of the hierarchical composite endpoint: use |
The default setting assumes TTE_A = TTE_P. Both TTE_A and TTE_P must be numeric vectors of length two, corresponding to the event rates
(Weibull distribution) for the first event of hospitalization and death. The parameters shape and shape0 identify the shape parameters
of Weibull distributions for the first event, simulated from a distribution with a cumulative hazard of
for hospitalization and
for death, where (gamma) is a patient-specific frailty drawn from a gamma distribution with mean 1 and
variance , shared between death and hospitalization for a given patient. The parameter (theta) represents population heterogeneity and also induces
correlation between death and hospitalization as competing first events. The parameter (alpha0) controls the heterogeneity of time to death through its
effect on heterogeneity. Death after hospitalization is simulated from an exponential distribution with a constant hazard that depends on the timing
of the first event (hospitalization) as
for the placebo arm and
for the active arm where rHR is the recurrence hazard ratio. When , earlier hospitalization (smaller )
increases the risk of death following hospitalization.
By default, events are simulated in continuous time. When m is specified as a positive numeric value, the event times are discretized into m intervals over the follow-up period.
an object of class adhce.
simHCE() for a general adhce dataset simulation, and simKHCE() for kidney disease-specific adhce simulation.
## Example 1 - positive correlation i <- 1764002323 set.seed(i) PADY <- 2 D <- simTTE(n = 1000, TTE_A = c(0.1, 0.04), TTE_P = c(.15, 0.045), theta = 4, alpha0 = 2, alpha = -1, shape = 2, fixedfy = PADY, rHR = 1) ####### Summary of first events by treatment group ######## table(D$EVENT1, D$TRTP) ####### Summary of second events by treatment group ######## table(D$EVENT2, D$TRTP) ######## Calculate win odds ######################### calcWO(D, ref = "P") ## Plot the ordinal dominance graph ###### D$TRTP <- factor(D$TRTP, levels = c("P", "A")) plot(D, type = "l", col = 2, fill = TRUE) abline(a = 0, b = 1, lwd = 2, lty = 3, col = "darkgreen") grid() ################################################################ ## Example 2 - Move-down approach (discrete‑time case only) PADY <- 2 # Continuous-time set.seed(2) D <- simTTE(n = 1000, TTE_A = c(0.1, 0.04), TTE_P = c(.15, 0.045), theta = 4, alpha0 = 2, alpha = -1, shape = 2, fixedfy = PADY, rHR = 1, m = Inf) summaryWO(D, ref = "P")$summary_by_GROUP # Discrete-time (more-ties) D0 <- simTTE(n = 1000, TTE_A = c(0.1, 0.04), TTE_P = c(.15, 0.045), theta = 4, alpha0 = 2, alpha = -1, shape = 2, fixedfy = PADY, rHR = 1, m = 5) summaryWO(D0, ref = "P")$summary_by_GROUP # Discrete-time and move-down approach (less ties on death) D1 <- simTTE(n = 1000, TTE_A = c(0.1, 0.04), TTE_P = c(.15, 0.045), theta = 4, alpha0 = 2, alpha = -1, shape = 2, fixedfy = PADY, rHR = 1, m = 5, hce_type = "md") summaryWO(D1, ref = "P")$summary_by_GROUP## Example 1 - positive correlation i <- 1764002323 set.seed(i) PADY <- 2 D <- simTTE(n = 1000, TTE_A = c(0.1, 0.04), TTE_P = c(.15, 0.045), theta = 4, alpha0 = 2, alpha = -1, shape = 2, fixedfy = PADY, rHR = 1) ####### Summary of first events by treatment group ######## table(D$EVENT1, D$TRTP) ####### Summary of second events by treatment group ######## table(D$EVENT2, D$TRTP) ######## Calculate win odds ######################### calcWO(D, ref = "P") ## Plot the ordinal dominance graph ###### D$TRTP <- factor(D$TRTP, levels = c("P", "A")) plot(D, type = "l", col = 2, fill = TRUE) abline(a = 0, b = 1, lwd = 2, lty = 3, col = "darkgreen") grid() ################################################################ ## Example 2 - Move-down approach (discrete‑time case only) PADY <- 2 # Continuous-time set.seed(2) D <- simTTE(n = 1000, TTE_A = c(0.1, 0.04), TTE_P = c(.15, 0.045), theta = 4, alpha0 = 2, alpha = -1, shape = 2, fixedfy = PADY, rHR = 1, m = Inf) summaryWO(D, ref = "P")$summary_by_GROUP # Discrete-time (more-ties) D0 <- simTTE(n = 1000, TTE_A = c(0.1, 0.04), TTE_P = c(.15, 0.045), theta = 4, alpha0 = 2, alpha = -1, shape = 2, fixedfy = PADY, rHR = 1, m = 5) summaryWO(D0, ref = "P")$summary_by_GROUP # Discrete-time and move-down approach (less ties on death) D1 <- simTTE(n = 1000, TTE_A = c(0.1, 0.04), TTE_P = c(.15, 0.045), theta = 4, alpha0 = 2, alpha = -1, shape = 2, fixedfy = PADY, rHR = 1, m = 5, hce_type = "md") summaryWO(D1, ref = "P")$summary_by_GROUP
Sample size calculation for the win odds test (no ties)
sizeWO( WO, power, SD = NULL, k = 0.5, alpha = 0.05, WOnull = 1, alternative = c("shift", "max", "ordered") )sizeWO( WO, power, SD = NULL, k = 0.5, alpha = 0.05, WOnull = 1, alternative = c("shift", "max", "ordered") )
WO |
a numeric vector of win odds values. |
power |
the given power. A numeric vector of length 1. |
SD |
assumed standard deviation of the win proportion. By default uses the conservative SD. A numeric vector of length 1. |
k |
proportion of active group in the overall sample size. Default is 0.5 (balanced randomization). A numeric vector of length 1. |
alpha |
the significance level for the 2-sided test. Default is 0.05. A numeric vector of length 1. |
WOnull |
the win odds value of the null hypothesis (default is 1). A numeric vector of length 1. |
alternative |
a character string specifying the class of the alternative hypothesis, must be one of |
alternative = "max" refers to the maximum variance of the win proportion across all possible
alternatives. The maximum variance equals WP*(1 - WP)/k where the win probability is calculated as WP = WO/(WO + 1).
alternative = "shift" specifies the variance across alternatives from a shifted family of distributions (Wilcoxon test). The variance formula, as suggested by Noether, is calculated based on the null hypothesis as follows 1/(12*k*(1 - k)).
alternative = "ordered" specifies the variance across alternatives from stochastically ordered distributions which include shifted distributions.
a data frame containing the sample size with input values.
All formulas were presented in
Bamber D (1975) "The area above the ordinal dominance graph and the area below the receiver operating characteristic graph." Journal of Mathematical Psychology 12.4: 387-415. https://doi.org/10.1016/0022-2496(75)90001-2.
Noether's formula for shifted alternatives
Noether GE (1987) "Sample size determination for some common nonparametric tests." Journal of the American Statistical Association 82.398: 645-7. https://doi.org/10.1080/01621459.1987.10478478.
For shift alternatives see also
Gasparyan SB et al. (2021) "Power and sample size calculation for the win odds test: application to an ordinal endpoint in COVID-19 trials." Journal of Biopharmaceutical Statistics 31.6: 765-787. https://doi.org/10.1080/10543406.2021.1968893.
powerWO(), minWO() for WO power or minimum detectable WO calculation.
sizeWO(WO = 1.25, power = 0.9) sizeWO(WO = 1.25, power = 0.9, k = 0.75) sizeWO(WO = seq(1.05, 1.5, 0.05), power = 0.9) # Comparison of different alternatives x <- seq(1.05, 5, 0.05) N1 <- sizeWO(WO = x, power = 0.9, alternative = "m")$SampleSize N2 <- sizeWO(WO = x, power = 0.9, alternative = "o")$SampleSize N3 <- sizeWO(WO = x, power = 0.9, alternative = "s")$SampleSize d <- data.frame(WO = x, N_m = N1, N_o = N2, N_s = N3) ## Check the power for the ordered alternative check <- c() for(i in seq_along(x)){ check[i] <- powerWO(N = d[i, "N_o"], WO = d[i, "WO"], alternative = "o")$power } d$power_check_o <- check print(d)sizeWO(WO = 1.25, power = 0.9) sizeWO(WO = 1.25, power = 0.9, k = 0.75) sizeWO(WO = seq(1.05, 1.5, 0.05), power = 0.9) # Comparison of different alternatives x <- seq(1.05, 5, 0.05) N1 <- sizeWO(WO = x, power = 0.9, alternative = "m")$SampleSize N2 <- sizeWO(WO = x, power = 0.9, alternative = "o")$SampleSize N3 <- sizeWO(WO = x, power = 0.9, alternative = "s")$SampleSize d <- data.frame(WO = x, N_m = N1, N_o = N2, N_s = N3) ## Check the power for the ordered alternative check <- c() for(i in seq_along(x)){ check[i] <- powerWO(N = d[i, "N_o"], WO = d[i, "WO"], alternative = "o")$power } d$power_check_o <- check print(d)
Sample size calculation for the win ratio test (with WR = 1 null hypothesis)
sizeWR(WR, power, WO = NULL, Pties = NULL, k = 0.5, alpha = 0.05)sizeWR(WR, power, WO = NULL, Pties = NULL, k = 0.5, alpha = 0.05)
WR |
a numeric vector of win odds values. |
power |
the given power. A numeric vector of length 1. |
WO |
win odds. Should be specified only if |
Pties |
probability of ties. A numeric vector of length 1. |
k |
proportion of active group in the overall sample size. Default is 0.5 (balanced randomization). A numeric vector of length 1. |
alpha |
the significance level for the 2-sided test. Default is 0.05. A numeric vector of length 1. |
a data frame containing the sample size with input values.
Yu RX, Ganju J. (2022) "Sample size formula for a win ratio endpoint." Statistics in Medicine, 41.6: 950-63. https://doi.org/10.1002/sim.9297.
sizeWO() for WO sample size calculation.
sizeWR(WR = 1.35, Pties = 0.125, power = 0.8) sizeWR(WR = 1.35, WO = 1.3, power = seq(0.5, 0.9, 0.05))sizeWR(WR = 1.35, Pties = 0.125, power = 0.8) sizeWR(WR = 1.35, WO = 1.3, power = seq(0.5, 0.9, 0.05))
A generic function for stratified win odds with adjustment
stratWO(x, ...)stratWO(x, ...)
x |
an object used to select a method. |
... |
further arguments passed to or from other methods. |
a list containing the stratified results and results by strata.
stratWO.data.frame() methods.
Stratified win odds with adjustment
## S3 method for class 'data.frame' stratWO( x, AVAL, TRTP, STRATA, ref, COVAR = NULL, alpha = 0.05, WOnull = 1, ... )## S3 method for class 'data.frame' stratWO( x, AVAL, TRTP, STRATA, ref, COVAR = NULL, alpha = 0.05, WOnull = 1, ... )
x |
a data frame containing subject-level data. |
AVAL |
variable in the data with ordinal analysis values. |
TRTP |
the treatment variable in the data. |
STRATA |
a character variable for stratification. |
ref |
the reference treatment group. |
COVAR |
a numeric covariate. |
alpha |
the reference treatment group. |
WOnull |
the null hypothesis. The default is 1. |
... |
additional parameters. |
a data frame containing the following columns:
WO stratified (or adjusted/stratified) win odds.
LCL lower confidence limit for adjusted (or adjusted/stratified) WO.
UCL upper confidence limit for adjusted (or adjusted/stratified) WO.
SE standard error of the adjusted (or adjusted/stratified) win odds.
WOnull win odds of the null hypothesis (specified in the WOnull argument).
alpha two-sided significance level for calculating the confidence interval (specified in the alpha argument).
Pvalue p-value associated with testing the null hypothesis.
WP adjusted (or adjusted/stratified) win probability.
LCL_WP lower confidence limit for adjusted (or adjusted/stratified) WP.
UCL_WP upper confidence limit for adjusted (or adjusted/stratified) WP.
SE_WP standard error for the adjusted (or adjusted/stratified) win probability.
SD_WP standard deviation of the adjusted (or adjusted/stratified) win probability.
N total number of patients in the analysis.
Type "STRATIFIED" or "STRATIFIED/ADJUSTED" depending on whether COVAR is specified.
Gasparyan SB et al. (2021) "Adjusted win ratio with stratification: calculation methods and interpretation." Statistical Methods in Medical Research 30.2: 580-611. https://doi.org/10.1177/0962280220942558.
# Stratified win odds res <- stratWO(x = KHCE, AVAL = "AVAL", TRTP = "TRTP", STRATA = "STRATAN", ref = "P") res ## Compare with the non-stratified win odds res0 <- calcWO(AVAL ~ TRTP, data = KHCE, ref = "P") res0 ## Compare with the win odds in each stratum separately l <- lapply(split(KHCE, KHCE$STRATAN), calcWO, AVAL = "AVAL", TRTP = "TRTP", ref = "P") l <- do.call(rbind, l) l <- l[, c("WO", "LCL", "UCL", "N")] l$STRATA <- as.numeric(row.names(l)) plot(y = l$WO, x = l$STRATA, ylim = c(0.5, 2.5), log = "y", xlim = c(0, 6), ylab = "Win Odds", xlab = "", xaxt = "n") axis(1, at = 1:6, labels = c(paste0("STR = ", l$STRATA), "Stratified", "Non-stratified")) arrows(l$STRATA, l$LCL, l$STRATA, l$UCL, angle = 90, code = 3, length = 0.05, col = "darkgreen") points(5, res$WO) arrows(5, res$LCL, 5, res$UCL, angle = 90, code = 3, length = 0.05, col = "darkblue") abline(h = c(1, res$WO), col = "red", lty = 4) points(6, res0$WO) arrows(6, res0$LCL, 6, res0$UCL, angle = 90, code = 3, length = 0.05, col = "darkred") # Stratified and adjusted win odds res <- stratWO(x = KHCE, AVAL = "AVAL", COVAR = "EGFRBL", TRTP = "TRTP", STRATA = "STRATAN", ref = "P") res# Stratified win odds res <- stratWO(x = KHCE, AVAL = "AVAL", TRTP = "TRTP", STRATA = "STRATAN", ref = "P") res ## Compare with the non-stratified win odds res0 <- calcWO(AVAL ~ TRTP, data = KHCE, ref = "P") res0 ## Compare with the win odds in each stratum separately l <- lapply(split(KHCE, KHCE$STRATAN), calcWO, AVAL = "AVAL", TRTP = "TRTP", ref = "P") l <- do.call(rbind, l) l <- l[, c("WO", "LCL", "UCL", "N")] l$STRATA <- as.numeric(row.names(l)) plot(y = l$WO, x = l$STRATA, ylim = c(0.5, 2.5), log = "y", xlim = c(0, 6), ylab = "Win Odds", xlab = "", xaxt = "n") axis(1, at = 1:6, labels = c(paste0("STR = ", l$STRATA), "Stratified", "Non-stratified")) arrows(l$STRATA, l$LCL, l$STRATA, l$UCL, angle = 90, code = 3, length = 0.05, col = "darkgreen") points(5, res$WO) arrows(5, res$LCL, 5, res$UCL, angle = 90, code = 3, length = 0.05, col = "darkblue") abline(h = c(1, res$WO), col = "red", lty = 4) points(6, res0$WO) arrows(6, res0$LCL, 6, res0$UCL, angle = 90, code = 3, length = 0.05, col = "darkred") # Stratified and adjusted win odds res <- stratWO(x = KHCE, AVAL = "AVAL", COVAR = "EGFRBL", TRTP = "TRTP", STRATA = "STRATAN", ref = "P") res
A generic function for summarizing win odds
summaryWO(x, ...)summaryWO(x, ...)
x |
an object used to select a method. |
... |
further arguments passed to or from other methods. |
a data frame containing calculated values.
summaryWO.adhce(), summaryWO.hce(), summaryWO.formula(), summaryWO.data.frame() methods.
adhce objectsWin odds summary for adhce objects
## S3 method for class 'adhce' summaryWO(x, ...)## S3 method for class 'adhce' summaryWO(x, ...)
x |
an |
... |
additional parameters. |
a list containing the summary of wins, losses, and ties. It contains the following named objects:
summary a data frame containing number of wins, losses, and ties by treatment group and the overall number of comparisons.
summary_by_GROUP a summary data frame by GROUP.
WO calculated WO (win odds) and WP (win probability) and their standard errors.
cumsummary_by_GROUP a cumulative summary data frame by GROUP.
calcWO(), summaryWO(), summaryWO.data.frame(), summaryWO.formula(), summaryWO.hce() methods.
## Example 1 - using an `hce` object HCE5 <- HCE4 HCE5$PADY <- NULL dat <- as_hce(HCE5) ## `PADY` is not present in the dataset, hence converts it to an `hce` object ## instead of an `adhce` object. ## Example 2 - Using an `adhce` object class(dat) summaryWO(dat, ref = "P") ## The class is `adhce` hence will use the variable `GROUP`. HCE5$PADY <- 1080 dat <- as_hce(HCE4) class(dat) summaryWO(dat, ref = "P") ## Example 3 - Plotting cumulative components of an `adhce` object dat <- as_hce(KHCE) res0 <- summaryWO(dat, ref = "P") res <- res0$cumsummary_by_GROUP barplot(PROP ~ WINS + GROUPN, data = res, col = c("darkgreen", "darkred", "darkblue"), xlab = "Proportions", xlim = c(0, 1), ylab = "Cumulative components by prioritization", legend.text = unique(res$WINS), beside = TRUE, horiz = TRUE) grid()## Example 1 - using an `hce` object HCE5 <- HCE4 HCE5$PADY <- NULL dat <- as_hce(HCE5) ## `PADY` is not present in the dataset, hence converts it to an `hce` object ## instead of an `adhce` object. ## Example 2 - Using an `adhce` object class(dat) summaryWO(dat, ref = "P") ## The class is `adhce` hence will use the variable `GROUP`. HCE5$PADY <- 1080 dat <- as_hce(HCE4) class(dat) summaryWO(dat, ref = "P") ## Example 3 - Plotting cumulative components of an `adhce` object dat <- as_hce(KHCE) res0 <- summaryWO(dat, ref = "P") res <- res0$cumsummary_by_GROUP barplot(PROP ~ WINS + GROUPN, data = res, col = c("darkgreen", "darkred", "darkblue"), xlab = "Proportions", xlim = c(0, 1), ylab = "Cumulative components by prioritization", legend.text = unique(res$WINS), beside = TRUE, horiz = TRUE) grid()
Win odds summary for a data frame
## S3 method for class 'data.frame' summaryWO(x, AVAL, TRTP, ref, GROUP = NULL, ...)## S3 method for class 'data.frame' summaryWO(x, AVAL, TRTP, ref, GROUP = NULL, ...)
x |
a data frame containing subject-level data. |
AVAL |
variable in the data with ordinal analysis values. |
TRTP |
the treatment variable in the data. |
ref |
the reference treatment group. |
GROUP |
an optional variable for grouping. |
... |
additional parameters. |
a list containing the summary of wins, losses, and ties. It contains the following named objects:
summary a data frame containing number of wins, losses, and ties by treatment group and the overall number of comparisons.
summary_by_GROUP (if GROUP variable is specified) a summary data frame by GROUP.
WO calculated WO (win odds) and WP (win probability) and their standard errors.
calcWO(), summaryWO(), summaryWO.formula(), summaryWO.hce() methods.
summaryWO(x = HCE3, AVAL = "AVAL", TRTP = "TRTP", ref = "P", GROUP = "GROUP")summaryWO(x = HCE3, AVAL = "AVAL", TRTP = "TRTP", ref = "P", GROUP = "GROUP")
Win odds summary using formula syntax
## S3 method for class 'formula' summaryWO(x, data, ...)## S3 method for class 'formula' summaryWO(x, data, ...)
x |
an object of class formula. |
data |
a data frame. |
... |
additional parameters. |
a list containing the summary of wins, losses, and ties. It contains the following named objects:
summary a data frame containing number of wins, losses, and ties by treatment group and the overall number of comparisons.
WO calculated WO (win odds) and WP (win probability) and their standard errors.
formula returning the specified formula in the x argument.
ref showing how the reference group was selected. Can be modifying by specifying the ref argument.
calcWO(), summaryWO(), summaryWO.data.frame(), summaryWO.hce() methods.
# Example 1 summaryWO(data = COVID19, GROUP ~ TRTP) summaryWO(data = COVID19, GROUP ~ TRTP, GROUP = "GROUP", ref = "Placebo") # Example 2 - Individual wins, losses, and ties dat <- COVID19 dat$ID <- 1:nrow(dat) summaryWO(data = dat, GROUP ~ TRTP, GROUP = "ID", ref = "Placebo")# Example 1 summaryWO(data = COVID19, GROUP ~ TRTP) summaryWO(data = COVID19, GROUP ~ TRTP, GROUP = "GROUP", ref = "Placebo") # Example 2 - Individual wins, losses, and ties dat <- COVID19 dat$ID <- 1:nrow(dat) summaryWO(data = dat, GROUP ~ TRTP, GROUP = "ID", ref = "Placebo")
hce objectsWin odds summary for hce objects
## S3 method for class 'hce' summaryWO(x, ...)## S3 method for class 'hce' summaryWO(x, ...)
x |
an |
... |
additional parameters. |
a list containing the summary of wins, losses, and ties. It contains the following named objects:
summary a data frame containing number of wins, losses, and ties by treatment group and the overall number of comparisons.
WO calculated WO (win odds) and WP (win probability) and their standard errors.
calcWO(), summaryWO(), summaryWO.data.frame(), summaryWO.formula(), summaryWO.adhce() methods.
COVID19HCE <- hce(GROUP = COVID19$GROUP, TRTP = COVID19$TRTP) summaryWO(COVID19HCE, ref = "Placebo")COVID19HCE <- hce(GROUP = COVID19$GROUP, TRTP = COVID19$TRTP) summaryWO(COVID19HCE, ref = "Placebo")