monotonicityTest <- function(x, y, data, test = c("jonckheere", "bartholomew"), level = 0.05, ...){ # , "drc", "quad"
if(!missing(data)){
x <- data[[x]]
y <- data[[y]]
}
xFac <- factor(x)
lm_alternative <- lm(y ~ x)$coef[["x"]]
alternative <- ifelse(lm_alternative > 0, "greater", "less")
test <- match.arg(test)
if(test == "jonckheere"){
p.value <- .jonckheereTest(x = y, g = x, alternative = alternative)$p.value
names(p.value) <- NULL
acceptMonotonicity = p.value < level
}
if(test == "bartholomew"){
if(!require("isotone")){
stop('package "isotone" must be installed to use bartolomew monotonicity test')
}
p.value <- .bartholomewTest(y = y, x = x, alternative = alternative, ...)$p.value
names(p.value) <- NULL
acceptMonotonicity = p.value < level
}
# if(test == "drc"){
# capture.output({
# p.value <- .drcMonotonicityTest(y = y, x = x, alternative = alternative, ...)$p.value
# })
# names(p.value) <- NULL
# acceptMonotonicity = p.value > level
# }
#
# if(test == "quad"){
# p.value <- .quadMonotonicityTest(y = y, x = x, ...)$p.value
# names(p.value) <- NULL
# acceptMonotonicity = p.value > level
# }
list(p.value = p.value, acceptMonotonicity = acceptMonotonicity)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.