Biostar Beta. Not for public use.
Checking How Good A Correlation Is
0
Entering edit mode
6.1 years ago
deschisandy • 60

I'm working with a set of data and I've obtained a certain correlations (using pearson's correlation coefficient). Is there a R function or package that would determine how good a correlation is by permutation tests? Or is there any other way to do this?

The example data:

data A

``````  structure(list(A = c(4.7671948292, 5.057230067, 5.3789958351,
6.1564088085, 4.8594252454, 5.8761895664, 4.4854758124, 4.7528916483,
4.4210848845, 3.9850111524), B = c(4.5852526479, 4.9673151031,
5.1601803995, 6.3082498288, 4.5796519129, 5.665788171, 4.2886052774,
4.4678455852, 4.4444468354, 3.8911975809)), .Names = c("A",
"B"), row.names = c("901_at", "902_at", "903_at",
"904_at", "905_at", "906_at", "907_at", "908_at",
"909_at", "910_s_at"), class = "data.frame")
``````

data B

``````      structure(list(A = c(5.5552465406, 5.8527484565, 8.3272537274,
6.4436035152, 5.597121724, 7.7741738479, 4.9931115346, 5.3852788212,
6.0292060458, 4.8351702985),B = c(5.6748698406, 6.8504588796,
9.4375062219, 7.6984745916, 5.7246927142, 9.0156741296, 4.8601744963,
5.4403609238, 6.842929093, 5.474543968)), .Names = c("A", "B"
), row.names = c("901_at", "902_at", "903_at", "904_at",
"905_at", "906_at", "907_at", "908_at", "909_at",
"910_s_at"), class = "data.frame")
``````

The correlation was calculated as :

``````   cor1<-cor(data A, data B)
``````

How to do the permutation tests to validate the same?

r correlation • 1.5k views
2
Entering edit mode

What exactly do you have in mind? You want to remove some data 1000 times and verify if the correlation still holds? You want to permute data between A and B randomly 1000 times? You want to permute all the data, some of the data? Why do you want to accomplish this? In order to see if the correlation is robust to small changes in the data? Otherwise, a correlation coefficient already tells you how good the correlation is.

0
Entering edit mode

Yes, I would like to permute all of the data to see if the correlation still holds and how good a correlation is when compared to a correlation between random permutations of the data

0
Entering edit mode
3
Entering edit mode
13 months ago
National Institutes of Health, Bethesda…

``````corperm = function(x,y,n) {
# n is the number of permutations
# x and y are the vectors to correlate
obs = abs(cor(x,y))
tmp = sapply(1:n,function(z) {abs(cor(sample(x,replace=TRUE),y))})
return(1-sum(obs>tmp)/n)
}
``````

Usage is like `corperm(A\$A,B\$B,1000)`. Note that this will likely give results very similar to `cor.test` and will be slower.

2
Entering edit mode
12 months ago
Leandro Lima • 920
San Francisco, CA

Hello!

I think you can use the function `cor.test`.

Example:

``````cor.test(A\$A, B\$A)
``````