# [R] How to resample matrices to test for the robustness of their correlation

camilleislande camille at mail.holar.is
Mon Feb 20 16:36:16 CET 2012

```Thank you Chuck,

Here is the head of my data set (tjornres):
Fish.1 Fish.2  MORPHO      DIET
1         1      2        0.03768       0.1559250
2         1      3        0.05609       0.7897060
3         1      4        0.03934       0.4638010
4         1      5        0.03363       0.1200480
5         1      6        0.05629       0.4390760
6         1      8        0.08366       0.1866750
7         1      9        0.04892       0.0988235
8         1     10       0.04427       0.2637140

MORPHO and DIET refer to the morphological and diet distances between fish 1
and fish 2. My original data set has over 2400 pairs of fish. My goal  is to
resample this dataste by selecting only 435.
I would like to do this 999 times and get a distribution of the correlation
coefficients MORPHO~DIET.

I went on and wrote this code:

essayres = tjornres                  # copy of the data
R = 999                                         # the number of replicates
cor.values = numeric(R)         # store the data
for (i in 1:R) {                              # loop
+ group1 = sample(essayres, size=435, replace=F)
+ group2 = sample(essayres, size=435, replace=F)
+ cor.values[i] = cor.test(group1,group2)\$cor
+ }

I have a syntax error in this code.

Also if I run one resampling, sample(essayres, size=435, replace=F), I get
this error message: Error in `[.data.frame`(x, .Internal(sample(length(x),
size, replace,  : cannot take a sample larger than the population when
'replace = FALSE'.

Does anyone know why this code is not working? Are there any other ways to
resample (without replacement) ?

--
View this message in context: http://r.789695.n4.nabble.com/How-to-resample-matrices-to-test-for-the-robustness-of-their-correlation-tp4397915p4404337.html
Sent from the R help mailing list archive at Nabble.com.

```