Hey Everyone, Im fresh new in R, and Im supposed to write a code to give me a correlation between two rankings. So I have two ranking lists, which contain file names, e.g.: Ranking list 1: file1.java file3.java file2.java Ranking list 2: fiile2.java file4.java file1.java I need to see how much are these two ranking lists are alike, get a correlation between them. I dont even know where to start. Can anyone bring me some light or tips? Thank you in advance. Cheers, -- David Nemer [[alternative HTML version deleted]]
Dear David, Are the rankings the numbers? Like.... List 1: 1 3 2 If so you should be able to do it fairly easily with cor() If you have a lot of file names and need to extract the numbers look at ?strsplit or ?substring. This will be easier or harder depending how variable the names are. For instance with your example names> x <- c("file1.java","file2.java") > as.numeric(substring(x,5,5))[1] 1 2 but this assumes that there is only 1 number and that it always occurs as five characters from the left. Best regards, Joshua On Fri, Apr 9, 2010 at 8:22 AM, David Nemer <davidnemer at gmail.com> wrote:> Hey Everyone, > > Im fresh new in R, and Im supposed to write a code to give me a correlation > between two rankings. So I have two ranking lists, which contain file names, > e.g.: > > Ranking list 1: > file1.java > file3.java > file2.java > > Ranking list 2: > fiile2.java > file4.java > file1.java > > I need to see how much are these two ranking lists are alike, get a > correlation between them. I dont even know where to start. Can anyone bring > me some light or tips? Thank you in advance. > > Cheers, > -- > David Nemer > > ? ? ? ?[[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. >-- Joshua Wiley Senior in Psychology University of California, Riverside http://www.joshuawiley.com/
On Fri, Apr 9, 2010 at 8:58 AM, David Nemer <davidnemer at gmail.com> wrote:> Hello Joshua, > Thanks for your help. The ranking list doesn't have numbers (it doesn't > matter the name of the file), just the file name, and the ranking is assumed > base on the position of the file name in the list (so the first filename to > appear is ranked number 1). So I guess I would just need to add the > filenames into a vector (array) for both rankings and then compare them.. isYou would add both lists to vectors.> it right? And to compare them I would use cor() right?cor() requires numeric data. To use it in this case, you would need to come up with rankings based on the position for each file name, and use those pairs of numbers with cor().> Cheers, > -- > David Nemer-- Joshua Wiley Senior in Psychology University of California, Riverside http://www.joshuawiley.com/
On Fri, Apr 9, 2010 at 10:23 AM, David Nemer <davidnemer at gmail.com> wrote:> Would that also work if in one ranking I have a filename that it is not in > the other ranking?match() will return an NA, if it cannot find a match, in which case you could use the argument: use="pairwise.complete.obs") in cor() to have it only use pairs with complete data.> Eg: > Ranking X: > A > B > C > Ranking Y: > A > D > CIn this example, you would get a correlation of 1, because B from x does not match anything in y, and D from y does not match x, so you're left with A and C which are in the same positions.> > -- > David Nemer-- Joshua Wiley Senior in Psychology University of California, Riverside http://www.joshuawiley.com/
On 04/10/2010 01:22 AM, David Nemer wrote:> Hey Everyone, > > Im fresh new in R, and Im supposed to write a code to give me a correlation > between two rankings. So I have two ranking lists, which contain file names, > e.g.: > > Ranking list 1: > file1.java > file3.java > file2.java > > Ranking list 2: > fiile2.java > file4.java > file1.java > > I need to see how much are these two ranking lists are alike, get a > correlation between them. I dont even know where to start. Can anyone bring > me some light or tips? Thank you in advance. >Hi David, Are you sure you don't want the concordance between the rankings? If so, look at the irr package for some concordance functions. The example shows pretty much no concordance. Jim
Try this:> A <- c("file1.java", "file3.java", "file2.java") > B <- c("file2.java", "file4.java", "file1.java") > cor(A, B, method = "spearman")[1] 0.5 On Fri, Apr 9, 2010 at 11:22 AM, David Nemer <davidnemer at gmail.com> wrote:> Hey Everyone, > > Im fresh new in R, and Im supposed to write a code to give me a correlation > between two rankings. So I have two ranking lists, which contain file names, > e.g.: > > Ranking list 1: > file1.java > file3.java > file2.java > > Ranking list 2: > fiile2.java > file4.java > file1.java > > I need to see how much are these two ranking lists are alike, get a > correlation between them. I dont even know where to start. Can anyone bring > me some light or tips? Thank you in advance. > > Cheers, > -- > David Nemer > > ? ? ? ?[[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. >