Gene Expression Correlation
I want to correlate the expression of gene-setA with SetB using Pearson's correlation in R. Can someone help with the script?
• 9,509 views
•
link
2 answers
Type in ?cor.test within R, and take a look at the provided example at the bottom of the documentation.
• 0 views
•
link
Yeah so...there are a few things you want to keep in mind
- I hate saying it but use Google first for a quick search
- What's your script so far? how does it look? it's easier to help you if you already have something
- If unequal size you either use only the matching samples or use simulation of missing data to estimate the correlation coefficient by repeating the simulation enough times...but it seems that pairwise deletion is easier and leads to pretty much the same results
Now, as starting point I can give you pseudocode which can look like:
mat1 <- matrix 100x10
mat2 <- matrix 100x10
results <- c()
for I in 1 to 100 { # go through rows in first matrix
for j I in 1 to 100 { # go through rows in second matrix
correlation <- calculateCorrelation(mat1[i,], mat2[j,]) # get correlation
temp <- c(results, temp) # create a vector with all the correlation of one row with all the rows in the second matrix
}
results <- rbind(results, temp) # create the 100x100 matrix
}
This will give you what you want and if matrix 1 and matrix 2 are different size it should be trivial to tweak
• 0 views
•
link
Log in to answer this question.
Yes, but that correlated values of each row. e.g.: SetA-row1 vs SetB-row1..and so on...It did not create a matrix with each gene of set A correlation with all genes of SetB
not sure what you are trying to achieve, do you want to correlate the same gene in two conditions? one gene against all the others in the other conditions? everything against everything? how do your data look? could you post a sample of the data so we can better help you out?
e.g.:
SetA
SetB
I want to create a aXb correlation matrix
Also, What if the 2 gene sets are of unequal sizes
You can't take the correlation of a pair of samples where there is only one observation, because the two samples you are comparing have no standard deviation, and the definition of the Pearson's correlation coefficient requires the calculation of a standard deviation or distance from the mean, which has no meaning for one observation: http://en.wikipedia.org/wiki/Pearson_product-moment_correlation_coefficient
You need at least three observations of your two variables a and b, and both vectors usually need to be of same size to do a Pearson correlation test with
cor.test(). You can tell the correlation test how to handleNAvalues withna.action = "na.exclude"(i.e., where you don't have a matching observation in one of the two paired samples, you exclude data from both vectors).I suggest reading about correlation and reading the relevant R documentation. What you're asking for doesn't seem to make much sense as described.
I got an error when running this function:
TriS wrote a pseudo code, which could be functional or just the guideline.
You should read a short tutorial to get yourself acquainted to the loops in R
A Tutorial on Loops in R - Usage and Alternatives
# this is the syntax for R
for(i in 1:100 ){print (i)}