[R] routine for dependent correlation test with stratified random sample

From: D. Alain <dialvac-r_at_yahoo.de>
Date: Fri, 13 May 2011 08:57:59 +0100 (BST)


Dear R-List,
 

I would like to have a large number of stratified random subsamples drawn from my dataframe and automatically test for correlation differences in every subsample.
 

Let this be my dataframe
 

df<-data.frame(group=c(rep(1,5),rep(2,5),rep(3,5)),a=c(3,4,5,6,3,4,5,4,5,4,1,2,1,2,1),b=c(1,2,3,4,5,3,4,3,4,5,6,5,6,2,3),c=c(2,2,3,3,5,1,1,6,6,5,6,1,1,2,1))
 

Then I would like to have n subsamples with one row out of each group, e.g.
 

> df
   group a b c

1      1 3 1 2
2      1 4 2 2
3      1 5 3 3
4      1 6 4 3
5      1 3 5 5
6      2 4 3 1
7      2 5 4 1
8      2 4 3 6
9      2 5 4 6
10     2 4 5 5
11     3 1 6 6
12     3 2 5 1
13     3 1 6 1

14     3 2 2 2
15     3 1 3 1
 

>df.sub1
group  a  b  c
1         3  1  2
2         5  4  1
3         1  3  1

 

>df.sub2
group  a  b  c
1         4  2  2
2         4  3  6
3         2  2  2

 

etc.
 

And then test, if the correlation ab is significantly higher than the correlation ac.
 

I managed to perform the test "manually" using r.test from the "psych" package, however I did not succeed in doing it automatically, i.e. I had to do cor(df.sub) for all subsamples an put the values manually into the r.test-code (which is very time consuming if you have to do it 100 times). Is there a nice way to combine the stratified subsampling with a code that can do the r.test with dataframe input directly (I mean without me entering all correlations ab, ac, bc manually)?
 

Thank you for any hint!
Alain 

        [[alternative HTML version deleted]]



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Fri 13 May 2011 - 08:01:17 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 13 May 2011 - 10:10:07 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive