Skip to content

Hoe to resample matrices to test for the robustness of their correlation

3 messages · camilleislande, chuck.01

#
Hello 
I have several populations where I have morphology and diet for each
individual. I am interested in the correlation between diet and
morphological distances. However the number of individuals in each
population ranges from 22 to 80 individuals. I have looked at the
correlation diet-morphology for each population and (not surprisingly) the
correlation coefficientis is highly correlated with the number of
individuals per population. 

I would like to resample (without replacement) the populations with 60-80
individuals and get random samplings of  30 individuals (1000 times). I
would like to get a correlation coefficient distribution against which to
test the original value of the correlation. 

I guess it is possible do this, however I have never written a script in R
and I am not familiar with resampling techniques at all. Any help with
coding will be greatly appreciated 

Thank you

--
View this message in context: http://r.789695.n4.nabble.com/Hoe-to-resample-matrices-to-test-for-the-robustness-of-their-correlation-tp4397915p4397915.html
Sent from the R help mailing list archive at Nabble.com.
#
see:
?sample
library(vegan)
?rrarefy

not knowing your data structure, its hard to say. 


camilleislande wrote
--
View this message in context: http://r.789695.n4.nabble.com/How-to-resample-matrices-to-test-for-the-robustness-of-their-correlation-tp4397915p4399189.html
Sent from the R help mailing list archive at Nabble.com.
2 days later
#
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:

head(tjornres)

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) ?
Thank you for your help,







--
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.