dat <- data.frame(group1 = c(1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2,
1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2),
group2 = c(1, 1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 2, 2, 2,
1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 1, 2, 2, 2),
x1 = c(3, 1, 4, 2, 5, 3, 2, 3, 6, 4, 3, NA, 5, 3,
3, 2, 6, 3, 1, 4, 3, 5, 6, 7, 4, 3, 5, 4),
x2 = c(4, NA, 3, 6, 3, 7, 2, 7, 3, 3, 3, 1, 3, 6,
3, 5, 2, 6, 8, 3, 4, 5, 2, 1, 3, 1, 2, NA),
x3 = c(7, 8, 5, 6, 4, 2, 8, 3, 6, 1, 2, 5, 8, 6,
2, 5, 3, 1, 6, 4, 5, 5, 3, 6, 3, 2, 2, 4))
# Two-Sided 95% CI for x1
ci.median(dat$x1)
# One-Sided 95% CI for x1
ci.median(dat$x1, alternative = "less")
# Two-Sided 99% CI
ci.median(dat$x1, conf.level = 0.99)
# Two-Sided 95% CI, print results with 3 digits
ci.median(dat$x1, digits = 3)
# Two-Sided 95% CI for x1, convert value 4 to NA
ci.median(dat$x1, as.na = 4)
# Two-Sided 95% CI for x1, x2, and x3,
# listwise deletion for missing data
ci.median(dat[, c("x1", "x2", "x3")], na.omit = TRUE)
# Two-Sided 95% CI for x1, x2, and x3,
# analysis by group1 separately
ci.median(dat[, c("x1", "x2", "x3")], group = dat$group1)
# Two-Sided 95% CI for x1, x2, and x3,
# analysis by group1 separately, sort by variables
ci.median(dat[, c("x1", "x2", "x3")], group = dat$group1, sort.var = TRUE)
# Two-Sided 95% CI for x1, x2, and x3,
# split analysis by group1
ci.median(dat[, c("x1", "x2", "x3")], split = dat$group1)
# Two-Sided 95% CI for x1, x2, and x3,
# analysis by group1 separately, split analysis by group2
ci.median(dat[, c("x1", "x2", "x3")], group = dat$group1, split = dat$group2)
Run the code above in your browser using DataLab