con_true_initial: con_true_initial

Usage Arguments Examples

View source: R/con_true_initial.R

Usage

1
con_true_initial(variable, testdata, top_pm = 50, method = "kendall", goodtype = "goodpvname")

Arguments

variable
testdata
top_pm
method
goodtype

Examples

 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))
  }

LyonsZhang/ProgPerm documentation built on July 16, 2020, 12:45 a.m.