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