# 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
Run the code above in your browser using DataLab