# easiOrigin
## Pairwise Comparisons
### Confidence Intervals
.ciPairwise <- function(x, ...) {
UseMethod(".ciPairwise")
}
.ciPairwise.default <- function(frame, conf.level = .95, ...) {
data <- data.frame(frame)
nr <- dim(data)[2]
rn <- colnames(data)
ncomp <- (nr) * (nr - 1) / 2
results <- data.frame(matrix(ncol = 5, nrow = ncomp))
colnames(results) <- c("Diff", "SE", "df", "LL", "UL")
comp <- 1
for (i in 1:(nr - 1)) {
for (j in (i + 1):nr) {
rownames(results)[comp] <- paste(rn[i], "v", rn[j])
varx <- get(rn[i])
vary <- get(rn[j])
object <- t.test(varx, vary, paired = TRUE, conf.level = conf.level)
results[comp, ] <- .ciDifference(object, ...)
comp <- comp + 1
}
}
results
}
.ciPairwise.formula <- function(formula, ...) {
varx <- eval(formula[[3]])
vary <- eval(formula[[2]])
nr <- nlevels(varx)
rn <- levels(varx)
ncomp <- (nr) * (nr - 1) / 2
results <- data.frame(matrix(ncol = 5, nrow = ncomp))
colnames(results) <- c("Diff", "SE", "df", "LL", "UL")
comp <- 1
for (i in 1:(nr - 1)) {
for (j in (i + 1):nr) {
rownames(results)[comp] <- paste(rn[i], "v", rn[j])
Comparison <- factor(varx, c(rn[i], rn[j]))
object <- t.test(vary ~ Comparison, ...)
results[comp, ] <- .ciDifference(object, ...)
comp <- comp + 1
}
}
results
}
ciPairwise <- function(..., conf.level = .95, main = NULL, digits = 3) {
results <- .ciPairwise(..., conf.level = conf.level)
if (is.null(main)) {
main <- "Confidence Intervals for the Pairwise Comparisons"
}
.formatList(list(results), main = main, digits = digits)
}
### Null Hypothesis Significance Tests
.nhstPairwise <- function(x, ...) {
UseMethod(".nhstPairwise")
}
.nhstPairwise.default <- function(frame, conf.level = .95, mu = 0, ...) {
data <- data.frame(frame)
nr <- dim(data)[2]
rn <- colnames(data)
ncomp <- (nr) * (nr - 1) / 2
results <- data.frame(matrix(ncol = 5, nrow = ncomp))
colnames(results) <- c("Diff", "SE", "t", "df", "p")
comp <- 1
for (i in 1:(nr - 1)) {
for (j in (i + 1):nr) {
rownames(results)[comp] <- paste(rn[i], "v", rn[j])
varx <- get(rn[i])
vary <- get(rn[j])
object <- t.test(varx, vary, paired = TRUE, conf.level = conf.level, mu = mu)
results[comp, ] <- .nhstDifference(object, ...)
comp <- comp + 1
}
}
results
}
.nhstPairwise.formula <- function(formula, ...) {
varx <- eval(formula[[3]])
vary <- eval(formula[[2]])
nr <- nlevels(varx)
rn <- levels(varx)
ncomp <- (nr) * (nr - 1) / 2
results <- data.frame(matrix(ncol = 5, nrow = ncomp))
colnames(results) <- c("Diff", "SE", "t", "df", "p")
comp <- 1
for (i in 1:(nr - 1)) {
for (j in (i + 1):nr) {
rownames(results)[comp] <- paste(rn[i], "v", rn[j])
Comparison <- factor(varx, c(rn[i], rn[j]))
object <- t.test(vary ~ Comparison, ...)
results[comp, ] <- .nhstDifference(object, ...)
comp <- comp + 1
}
}
results
}
nhstPairwise <- function(..., main = NULL, digits = 3) {
results <- .nhstPairwise(...)
if (is.null(main)) {
main <- "Hypothesis Tests for the Pairwise Comparisons"
}
.formatList(list(results), main = main, digits = digits)
}
### Confidence Interval Plots
graphPairwise <- function(x, ...) {
UseMethod("graphPairwise")
}
graphPairwise.default <- function(frame, main = NULL, ylab = "Mean Difference", xlab = "", mu = NULL, rope = NULL, conf.level = .95, values = TRUE, ylim = NULL, digits = 3, pch = 17, col = "black", ...) {
results <- .ciPairwise(frame, conf.level = conf.level)[, c("Diff", "LL", "UL")]
if (is.null(main)) {
main <- "Confidence Intervals for the Pairwise Comparisons"
}
.cipMain(results, main = main, ylab = ylab, xlab = xlab, mu = mu, rope = rope, values = values, ylim = ylim, digits = digits, connect = FALSE, pch = pch, col = col)
}
graphPairwise.formula <- function(formula, main = NULL, ylab = "Mean Difference", xlab = "", mu = NULL, rope = NULL, conf.level = .95, values = TRUE, ylim = NULL, digits = 3, pch = 17, col = "black", ...) {
results <- .ciPairwise(formula, conf.level = conf.level)[, c("Diff", "LL", "UL")]
if (is.null(main)) {
main <- "Confidence Interval for the Pairwise Comparisons"
}
.cipMain(results, main = main, ylab = ylab, xlab = xlab, mu = mu, rope = rope, values = values, ylim = ylim, digits = digits, connect = FALSE, pch = pch, col = col)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.