[R] Estimate correlation with bootstrap

Andreas Klein klein82517 at yahoo.de
Fri Sep 21 07:59:14 CEST 2007


Hello.

I would like to estimate the correlation coefficient
from two samples with Bootstrapping using the
R-function sample().

The problem is, that I have to sample pairwise. For
example if I have got two time series and I draw from
the first series the value from 1912 I need the value
from 1912 from the second sample, too.

Example:

Imagine that a and b are two time series with returns
for example: 

a <- c(1,2,3,4,5,6,7,8,9,10)
b <- c(1,1,56,3,6,6,6,7,2,10)

a.sample     <- numeric(10)
b.sample     <- numeric(10)
boot.cor.a.b <- numeric(1000)

for (i in 1:1000)

{

 for (j in 1:10)

 {

  a.sample[j] <- sample(a,1,replace=TRUE)
  b.sample[j] <- sample(b,1,replace=TRUE)

 }

 boot.cor.a.b[i] <- cor(a,b)

}

The problem here is, that the sampling is independent
from each other.

So how do I have to change the R-code to get the
pairwise sampling mentioned above?

I hope you can help me.

Sincerely
Klein.


      ________



More information about the R-help mailing list