mean.equiv.tost.test <- function(x, y, margin=1, alpha=0.05) {
## Equivalence Test for Two Means by TOST (Two One-Sided Test) Procedure
## Assumption: Normality.
## Reference: Understanding Equivalence and Noninferiority Testing (Walker and Nowacki)
## INPUT:
## x: a vector of continuous scale.
## y: another vector of continuous scale (to compare with x)
## margin: Equivalence Margin (defaul to 1)
## alpha: Significance Level.
cl <- 1 - 2 * alpha
a <- t.test(x, y, conf.level=cl)
ci <- a$conf.int
print(a)
cat("Equivalence Test for Two Means by TOST Procedure:\n")
cat("Equivalence Margin =", margin, "\n")
if (ci[1] >= -margin && ci[2] <= margin) {
cat("Equivalence Established! (Significance Level =", 100*alpha, "%)\n\n")
} else cat("Equivalence NOT Established. (Significance Level =", 100*alpha, "%)\n\n")
plot(0, 0, xlim=c(-2*margin, 2*margin), ylim=c(-1,1), axes=F, xlab="Difference in Efficacies", ylab="", type="n")
axis(side=1, at=c(-2*margin, -margin, 0, margin, 2*margin), labels=c("", paste("-", margin), "0", margin, ""))
abline(v=c(-margin, 0, margin), lty=c(2,1,2))
lines(ci, c(0,0), lwd=3)
lines(rep(ci[1], 2), c(-0.1, 0.1), lwd=2)
lines(rep(ci[2], 2), c(-0.1, 0.1), lwd=2)
lines(rep(-diff(a$estimate), 2), c(-0.1, 0.1), lwd=4)
}
if (F) {
mean.equiv.tost.test(rnorm(20), rnorm(20, mean=0.3))
}
No comments:
Post a Comment