correlation

how do i calculate correlation between corresponding columns of two matrices and not getting other correlations as output

為{幸葍}努か 提交于 2019-12-09 17:29:48
问题 I have these data > a a b c 1 1 -1 4 2 2 -2 6 3 3 -3 9 4 4 -4 12 5 5 -5 6 > b d e f 1 6 -5 7 2 7 -4 4 3 8 -3 3 4 9 -2 3 5 10 -1 9 > cor(a,b) d e f a 1.0000000 1.0000000 0.1767767 b -1.0000000 -1.000000 -0.1767767 c 0.5050763 0.5050763 -0.6964286 The result I want is just: cor(a,d) = 1 cor(b,e) = -1 cor(c,e) = 0.6964286 回答1: I would probably personally just use diag : > diag(cor(a,b)) [1] 1.0000000 -1.0000000 -0.6964286 But you could also use mapply : > mapply(cor,a,b) a b c 1.0000000 -1

Correlation between multiple variables of a data frame

杀马特。学长 韩版系。学妹 提交于 2019-12-09 13:29:58
问题 I have a data.frame of 10 Variables in R . Lets call them var1 var2 ... var10 I want to find correlation of one of var1 with respect to var2 , var3 ... var10 How can we do that? cor function can find correlation between 2 variables at a time. By using that I had to write cor function for each Analysis 回答1: My package corrr , which helps to explore correlations, has a simple solution for this. I'll use the mtcars data set as an example, and say we want to focus on the correlation of mpg with

Create a correlation graph in Matlab

家住魔仙堡 提交于 2019-12-09 10:25:43
问题 I'm trying to emulate this graph: If I have a correlation matrix how can I create an output like this? 回答1: If you have an n x n correlation matrix M , and a vector L of length n containing the label for each bin, you can use something like the following: imagesc(M); % plot the matrix set(gca, 'XTick', 1:n); % center x-axis ticks on bins set(gca, 'YTick', 1:n); % center y-axis ticks on bins set(gca, 'XTickLabel', L); % set x-axis labels set(gca, 'YTickLabel', L); % set y-axis labels title(

Extracting and formatting results of cor.test on multiple pairs of columns

浪子不回头ぞ 提交于 2019-12-09 07:38:28
I am trying to generate a table output of a correlation matrix. Specifically, I am using a for loop in order to identify a correlation between all data in columns 4:40 to column 1. While the results of the table are decent, it does not identify what is being compared to what. In checking attributes of cor.test ,I find that data.name is being given as x[1] and y[1] which is not good enough to trace back which columns is being compared to what. Here is my code: input <- read.delim(file="InputData.txt", header=TRUE) x<-input[,41, drop=FALSE] y=input[,4:40] corr.values <- vector("list", 37) for (i

Calculate correlation by aggregating columns of data frame

断了今生、忘了曾经 提交于 2019-12-09 03:25:04
问题 I have the following data frame: y <- data.frame(group = letters[1:5], a = rnorm(5) , b = rnorm(5), c = rnorm(5), d = rnorm(5) ) How to get a data frame which gives me the correlation between columns a,b and c,d for each row? something like: sapply(y, function(x) {cor(x[2:3],x[4:5])}) Thank you, S 回答1: You could use apply > apply(y[,-1],1,function(x) cor(x[1:2],x[3:4])) [1] -1 -1 1 -1 1 Or ddply (although this might be overkill, and if two rows have the same group it will do the correlation

MPI python-Open-MPI

☆樱花仙子☆ 提交于 2019-12-08 17:36:14
问题 I have 20,000*515 numpy matrix,representing biological datas. I need to find the correlation coefficient of the biological data,meaning as a result I would have a 20,000*20,000 matrix with correlation value. Then I populate a numpy array with 1's and 0's if each correlation coefficient is greater than a threshold value. I used numpy.corrcoef to find the correlation coefficient and it works well in my machine. Then I wanted to put in the cluster(having 10 computers and node varying from 2 to 8

Correlation with p values matrix

瘦欲@ 提交于 2019-12-08 12:35:27
问题 I have following data: x1 = sample(1:10, 100, replace=T) x2 = sample(1:3, 100, replace=T) x3 = sample(50:100, 100, replace=T) y1 = sample(50:100, 100, replace=T) y2 = sample(50:100, 100, replace=T) mydf = data.frame(x1,x2,x3,y1,y2) head(mydf) x1 x2 x3 y1 y2 1 2 2 96 100 73 2 5 2 77 93 52 3 10 1 86 54 80 4 3 2 98 59 94 5 2 2 85 94 85 6 9 2 56 79 99 I have following data: I want to do correlations and produce following output: x1 x2 x3 y1 r.value; p.value r.value; p.value r.value; p.value y2 r

How to calculate statistical significance of correlation in pandas or some other python module

天大地大妈咪最大 提交于 2019-12-08 12:04:15
问题 I am using the Pandas library in Python. So, I am calculating correlations between attributes in my data-set. df.corr() This is a nice function that returns a data-frame of correlations between all attributes. There is this term called statistical significance of correlation, which test the probability that this difference was obtain by chance (description here). So does anybody know if there is a function to return this in pandas or in some other Python library. 来源: https://stackoverflow.com

Fast rolling correlation in Matlab

别来无恙 提交于 2019-12-08 10:44:46
问题 I am trying to derive a function for calculating a moving/rolling correlation for two vectors and speed is a high priority, since I need to apply this function in an array function. What I have (which is too slow) is this: Data1 = rand(3000,1); Data2 = rand(3000,1); function y = MovCorr(Data1,Data2) [N,~] = size(Data1); correlationTS = nan(N, 1); for t = 20+1:N correlationTS(t, :) = corr(Data1(t-20:t, 1),Data2(t-20:t,1),'rows','complete'); end y = correlationTS; end I am thinking that the for

R: Filter correlation matrix on values > and < [closed]

若如初见. 提交于 2019-12-08 10:25:14
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 years ago . I am programming in R and have a huge correlation matrix. I would like to filter this matrix such that I only have rows and columns containing values >0.7 or <-0.7. I already tried subset and filter but don't really get what I want. The additional problem is that there are so many row/column names that I do not