twocor: Compute a .95 confidence interval for the difference between...

Description Usage Arguments Examples

View source: R/Rallfun-v24.R

Description

The function corfun is any function that returns a correlation coefficient in corfun$cor. The functions pbcor and wincor follow this convention.

For Pearson's correlation, use the function twopcor instead.

The default number of bootstrap samples is nboot=599

Usage

1
twocor(x1, y1, x2, y2, corfun = pbcor, nboot = 599, alpha = 0.05, ...)

Arguments

x1
y1
x2
y2
corfun
nboot
alpha
...

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
30
31
32
##---- 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 (x1, y1, x2, y2, corfun = pbcor, nboot = 599, alpha = 0.05, 
    SEED = T, ...) 
{
    if (SEED) 
        set.seed(2)
    print("Taking bootstrap samples. Please wait.")
    data1 <- matrix(sample(length(y1), size = length(y1) * nboot, 
        replace = T), nrow = nboot)
    bvec1 <- apply(data1, 1, corbsub, x1, y1, corfun, ...)
    data2 <- matrix(sample(length(y2), size = length(y2) * nboot, 
        replace = T), nrow = nboot)
    bvec2 <- apply(data2, 1, corbsub, x2, y2, corfun, ...)
    bvec <- bvec1 - bvec2
    bsort <- sort(bvec)
    term <- alpha/2
    ihi <- floor((1 - term) * nboot + 0.5)
    ilow <- floor(term * nboot + 0.5)
    corci <- 1
    corci[1] <- bsort[ilow]
    corci[2] <- bsort[ihi]
    r1 <- corfun(x1, y1)$cor
    r2 <- corfun(x2, y2)$cor
    reject <- "NO"
    if (corci[1] > 0 || corci[2] < 0) 
        reject = "YES"
    list(r1 = r1, r2 = r2, ci.dif = corci, reject = reject)
  }

WRS documentation built on May 2, 2019, 5:49 p.m.