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

Description Usage Arguments Examples

View source: R/Rallfun-v24.R

Description

This function uses an adjusted percentile bootstrap method that gives good results when the error term is heteroscedastic.

WARNING: If the number of boostrap samples is altered, it is unknown how to adjust the confidence interval when n1+n2 < 250.

Usage

1
twopcor(x1, y1, x2, y2, SEED = TRUE)

Arguments

x1
y1
x2
y2
SEED

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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
##---- 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, SEED = T) 
{
    nboot <- 599
    if (SEED) 
        set.seed(2)
    X <- elimna(cbind(x1, y1))
    x1 <- X[, 1]
    y1 <- X[, 2]
    X <- elimna(cbind(x2, y2))
    x2 <- X[, 1]
    y2 <- X[, 2]
    print("Taking bootstrap samples; please wait")
    data1 <- matrix(sample(length(y1), size = length(y1) * nboot, 
        replace = T), nrow = nboot)
    bvec1 <- apply(data1, 1, pcorbsub, x1, y1)
    data2 <- matrix(sample(length(y2), size = length(y2) * nboot, 
        replace = T), nrow = nboot)
    bvec2 <- apply(data2, 1, pcorbsub, x2, y2)
    bvec <- bvec1 - bvec2
    ilow <- 15
    ihi <- 584
    if (length(y1) + length(y2) < 250) {
        ilow <- 14
        ihi <- 585
    }
    if (length(y1) + length(y2) < 180) {
        ilow <- 11
        ihi <- 588
    }
    if (length(y1) + length(y2) < 80) {
        ilow <- 8
        ihi <- 592
    }
    if (length(y1) + length(y2) < 40) {
        ilow <- 7
        ihi <- 593
    }
    bsort <- sort(bvec)
    r1 <- cor(x1, y1)
    r2 <- cor(x2, y2)
    ci <- c(bsort[ilow], bsort[ihi])
    list(r1 = r1, r2 = r2, ci = ci)
  }

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