#----------------------------------------------------------------------------
# rdt() example
#----------------------------------------------------------------------------
library(rankdifferencetest)
# Use example data from Kornbrot (1990)
data <- kornbrot_table1
# Create tall-format data for demonstration purposes
data_tall <- reshape(
data = kornbrot_table1,
direction = "long",
varying = c("placebo", "drug"),
v.names = c("time"),
idvar = "subject",
times = c("placebo", "drug"),
timevar = "treatment",
new.row.names = seq_len(prod(length(c("placebo", "drug")), nrow(kornbrot_table1)))
)
# Subject and treatment should be factors. The ordering of the treatment factor
# will determine the difference (placebo - drug).
data_tall$subject <- factor(data_tall$subject)
data_tall$treatment <- factor(data_tall$treatment, levels = c("drug", "placebo"))
# Recreate analysis and results from table 3 (page 248) in Kornbrot (1990)
## Divide p-value by 2 for one-tailed probability.
rdt(
data = data,
formula = placebo ~ drug,
alternative = "two.sided",
distribution = "asymptotic",
zero_method = "wilcoxon",
correct = TRUE,
conf_level = 0.95
)
rdt2(
x = data$placebo,
y = data$drug,
alternative = "two.sided",
distribution = "asymptotic",
zero_method = "wilcoxon",
correct = TRUE,
conf_level = 0.95
)
# The same outcome is seen after transforming time to rate.
## Rate transformation inverts the rank ordering.
data$placebo_rate <- 60 / data$placebo
data$drug_rate <- 60 / data$drug
data_tall$rate <- 60 / data_tall$time
rdt(
data = data_tall,
formula = rate ~ treatment | subject,
alternative = "two.sided",
distribution = "asymptotic",
zero_method = "wilcoxon",
correct = TRUE,
conf_level = 0.95
)
# In contrast to the rank difference test, the Wilcoxon signed-rank test
# produces differing results. See table 1 and table 2 (page 245) in
# Kornbrot (1990).
## Divide p-value by 2 for one-tailed probability.
srt(
data = data,
formula = placebo ~ drug,
alternative = "two.sided",
distribution = "asymptotic",
zero_method = "wilcoxon",
correct = TRUE,
conf_level = 0.95
)
srt(
data = data_tall,
formula = rate ~ treatment | subject,
alternative = "two.sided",
distribution = "asymptotic",
zero_method = "wilcoxon",
correct = TRUE,
conf_level = 0.95
)
Run the code above in your browser using DataLab