#' @title Select differential variables between groups by significance level
#'
#' @description Select differential variables between groups by significance level.
#'
#' @param x an object of class 'compareGroups'
#' @param p.threshold a significance level threshold for selecting. Default value is 0.2, meaning that all variable showing an overall p-value under 0.2 will be setected.
#' @param which.p name of p-value from x to compare with threshold of 'relevant' value. Default value is p.overall. Other options are: p.ratio (p.trend is not implemented)
#' @return a character vector with the names of the selected variables.
#' @export
selectFromCompareGroups <- function(x, p.threshold = 0.2, which.p = "p.overall"){
selectedvar <- c()
if(which.p == "p.overall"){
for (i in 1:length(x)) {
if (!is.na(x[[i]]$p.overall)){
if (x[[i]]$p.overall < p.threshold) selectedvar <- c(selectedvar, attributes(x)$varnames.orig[[i]])
}
}
}
if(which.p == "p.ratio"){
for (i in 1:length(x)) {
if (sum(1*!is.finite(as.numeric(attr(x[[i]], "p.ratio"))))<=1){
if (min(as.numeric(attr(x[[i]], "p.ratio")), na.rm = TRUE) < p.threshold) selectedvar <- c(selectedvar, attributes(x)$varnames.orig[[i]])
}
}
}
return(selectedvar)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.