View source: R/con_true_initial.R
1 | con_true_initial(variable, testdata, top_pm = 50, method = "kendall", goodtype = "goodpvname")
|
variable |
|
testdata |
|
top_pm |
|
method |
|
goodtype |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | ##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function (variable, testdata, top_pm = 50, method = "kendall",
goodtype = "goodpvname")
{
testlevel <- testdata
testlevel[[variable]] <- NULL
n <- dim(testdata)[1]
group <- testdata[[variable]]
indx <- 1:n
indx0 <- sample(indx, n)
indx1 <- indx[!indx %in% indx0]
group[indx1] <- group[sample(indx1)]
otu.test <- apply(testlevel, 2, function(x) {
ct <- cor.test(x = x, y = group, method = method)
return(data.frame(pv = ct$p.value, es = ct$statistic,
cr = ct$estimate))
})
otu.test <- do.call(rbind, otu.test)
select <- switch(goodtype, goodpvname = order(otu.test$pv)[1:top_pm],
goodesname = order(abs(otu.test$es))[1:top_pm], goodcrname = order(abs(otu.test$cr))[1:top_pm],
stop("goodtype must be one of the follows: 'goodpvname', 'goodesname' and 'goodcrname'. "))
selname <- row.names(otu.test)[select]
return(list(select = select, selname = selname, testlevel = testlevel,
n = n, otu.test = otu.test))
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.