Re: [R] Ranking

2015-11-15 Thread Bert Gunter
It is perhaps worth mentioning that the OP's desire to do the
conversion to numeric to calculate won-lost percentages is completely
unnecessary and indicates that he/she could benefit by spending some
additional time learning R. See, e.g. ?tapply, ?table, ?prop.table,
and friends.

Cheers,
Bert


Bert Gunter

"Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom."
   -- Clifford Stoll


On Sun, Nov 15, 2015 at 8:28 PM, David L Carlson  wrote:
> I used your code but deleted sep="\t" since there were no tabs in your email 
> and added the fill= argument I mentioned before.
>
>
>
> David
>
>
>
>  Original message 
> From: Ashta 
> Date: 11/14/2015 6:40 PM (GMT-06:00)
> To: David L Carlson 
> Cc: R help 
> Subject: Re: [R] Ranking
>
> Thank you David,
>
> My intention was if I change the status column  to numeric
> 0= Lost and 1 Won, then I can use this numeric variables  to calculate
> the  Percent game Won by each country.
> how did you read the data first?
> That was my problem.   The actual data is in a file have to be read or laded.
>
> Thank you !
>
>
>
>
>
>
> On Sat, Nov 14, 2015 at 6:10 PM, David L Carlson  wrote:
>> It is always good to read the manual page for a function, but especially 
>> when it is not working as you expected. In this case if you look at the 
>> arguments for read.table(), you will find one called fill=TRUE that is 
>> useful in this case.
>>
>> Based on your ifelse(), you seem to be assuming that a blank is not missing 
>> data but a lost game. You may also discover that in your example wins are 
>> coded as w and W.  Since character variables get converted to factors by 
>> default, you could use something like:
>>
>>> levels(test$STATUS) <- c("L", "W", "W")
>>> addmargins(xtabs(~Country+STATUS, test), 2)
>>STATUS
>> Country L W Sum
>> FRA 2 3   5
>> GER 1 3   4
>> SPA 2 1   3
>> UNK 1 2   3
>> USA 1 2   3
>>
>> I'll let you figure out how to get the last column.
>>
>> David L. Carlson
>> Department of Anthropology
>> Texas A&M University
>>
>> -Original Message-
>> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Ashta
>> Sent: Saturday, November 14, 2015 4:28 PM
>> To: R help 
>> Subject: [R] Ranking
>>
>> Hi all,
>>
>> I have the following raw data some records  don't have the second variable.
>>
>> test <- read.table(textConnection(" Country  STATUS
>> USA
>> USAW
>> USAW
>> GER
>> GERW
>> GERw
>> GERW
>> UNKW
>> UNK
>> UNKW
>> FRA
>> FRA
>> FRAW
>> FRAW
>> FRAW
>> SPA
>> SPAW
>> SPA  "),header = TRUE,  sep= "\t")
>> test
>>
>> It is not reading it correctly.
>>
>> Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  :
>>   line 17 did not have 2 elements
>>
>>
>>
>> After reading   I want change the status column  to numeric so that I
>> can use the table function
>>
>> test$STATUS <- ifelse(is.na(test$STATUS), 0,  1)
>>
>> at the end I want the following table (Country, Won, Lost , Number of
>> games played and % of score ) and pick the top 3 countries.
>>
>> COUNTRY   Won   Lost   NG%W
>>  USA 21 3  (2/3)*100
>>  GER 31 4  (3/4)*100
>>  UNK 21 3  (2/3)*100
>>  FRA 3 25  (3/5)*100
>>  SPA 1 2 3  (1/3)*100
>>
>> Thank you in  advance
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> 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.
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Ranking

2015-11-15 Thread David L Carlson
I used your code but deleted sep="\t" since there were no tabs in your email 
and added the fill= argument I mentioned before.



David



 Original message 
From: Ashta 
Date: 11/14/2015 6:40 PM (GMT-06:00)
To: David L Carlson 
Cc: R help 
Subject: Re: [R] Ranking

Thank you David,

My intention was if I change the status column  to numeric
0= Lost and 1 Won, then I can use this numeric variables  to calculate
the  Percent game Won by each country.
how did you read the data first?
That was my problem.   The actual data is in a file have to be read or laded.

Thank you !






On Sat, Nov 14, 2015 at 6:10 PM, David L Carlson  wrote:
> It is always good to read the manual page for a function, but especially when 
> it is not working as you expected. In this case if you look at the arguments 
> for read.table(), you will find one called fill=TRUE that is useful in this 
> case.
>
> Based on your ifelse(), you seem to be assuming that a blank is not missing 
> data but a lost game. You may also discover that in your example wins are 
> coded as w and W.  Since character variables get converted to factors by 
> default, you could use something like:
>
>> levels(test$STATUS) <- c("L", "W", "W")
>> addmargins(xtabs(~Country+STATUS, test), 2)
>STATUS
> Country L W Sum
> FRA 2 3   5
> GER 1 3   4
> SPA 2 1   3
> UNK 1 2   3
> USA 1 2   3
>
> I'll let you figure out how to get the last column.
>
> David L. Carlson
> Department of Anthropology
> Texas A&M University
>
> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Ashta
> Sent: Saturday, November 14, 2015 4:28 PM
> To: R help 
> Subject: [R] Ranking
>
> Hi all,
>
> I have the following raw data some records  don't have the second variable.
>
> test <- read.table(textConnection(" Country  STATUS
> USA
> USAW
> USAW
> GER
> GERW
> GERw
> GERW
> UNKW
> UNK
> UNKW
> FRA
> FRA
> FRAW
> FRAW
> FRAW
> SPA
> SPAW
> SPA  "),header = TRUE,  sep= "\t")
> test
>
> It is not reading it correctly.
>
> Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  :
>   line 17 did not have 2 elements
>
>
>
> After reading   I want change the status column  to numeric so that I
> can use the table function
>
> test$STATUS <- ifelse(is.na(test$STATUS), 0,  1)
>
> at the end I want the following table (Country, Won, Lost , Number of
> games played and % of score ) and pick the top 3 countries.
>
> COUNTRY   Won   Lost   NG%W
>  USA 21 3  (2/3)*100
>  GER 31 4  (3/4)*100
>  UNK 21 3  (2/3)*100
>  FRA 3 25  (3/5)*100
>  SPA 1 2 3  (1/3)*100
>
> Thank you in  advance
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Ranking

2015-11-14 Thread Ashta
Thank you David,

My intention was if I change the status column  to numeric
0= Lost and 1 Won, then I can use this numeric variables  to calculate
the  Percent game Won by each country.
how did you read the data first?
That was my problem.   The actual data is in a file have to be read or laded.

Thank you !






On Sat, Nov 14, 2015 at 6:10 PM, David L Carlson  wrote:
> It is always good to read the manual page for a function, but especially when 
> it is not working as you expected. In this case if you look at the arguments 
> for read.table(), you will find one called fill=TRUE that is useful in this 
> case.
>
> Based on your ifelse(), you seem to be assuming that a blank is not missing 
> data but a lost game. You may also discover that in your example wins are 
> coded as w and W.  Since character variables get converted to factors by 
> default, you could use something like:
>
>> levels(test$STATUS) <- c("L", "W", "W")
>> addmargins(xtabs(~Country+STATUS, test), 2)
>STATUS
> Country L W Sum
> FRA 2 3   5
> GER 1 3   4
> SPA 2 1   3
> UNK 1 2   3
> USA 1 2   3
>
> I'll let you figure out how to get the last column.
>
> David L. Carlson
> Department of Anthropology
> Texas A&M University
>
> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Ashta
> Sent: Saturday, November 14, 2015 4:28 PM
> To: R help 
> Subject: [R] Ranking
>
> Hi all,
>
> I have the following raw data some records  don't have the second variable.
>
> test <- read.table(textConnection(" Country  STATUS
> USA
> USAW
> USAW
> GER
> GERW
> GERw
> GERW
> UNKW
> UNK
> UNKW
> FRA
> FRA
> FRAW
> FRAW
> FRAW
> SPA
> SPAW
> SPA  "),header = TRUE,  sep= "\t")
> test
>
> It is not reading it correctly.
>
> Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  :
>   line 17 did not have 2 elements
>
>
>
> After reading   I want change the status column  to numeric so that I
> can use the table function
>
> test$STATUS <- ifelse(is.na(test$STATUS), 0,  1)
>
> at the end I want the following table (Country, Won, Lost , Number of
> games played and % of score ) and pick the top 3 countries.
>
> COUNTRY   Won   Lost   NG%W
>  USA 21 3  (2/3)*100
>  GER 31 4  (3/4)*100
>  UNK 21 3  (2/3)*100
>  FRA 3 25  (3/5)*100
>  SPA 1 2 3  (1/3)*100
>
> Thank you in  advance
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Ranking

2015-11-14 Thread David L Carlson
It is always good to read the manual page for a function, but especially when 
it is not working as you expected. In this case if you look at the arguments 
for read.table(), you will find one called fill=TRUE that is useful in this 
case.

Based on your ifelse(), you seem to be assuming that a blank is not missing 
data but a lost game. You may also discover that in your example wins are coded 
as w and W.  Since character variables get converted to factors by default, you 
could use something like:

> levels(test$STATUS) <- c("L", "W", "W")
> addmargins(xtabs(~Country+STATUS, test), 2)
   STATUS
Country L W Sum
FRA 2 3   5
GER 1 3   4
SPA 2 1   3
UNK 1 2   3
USA 1 2   3

I'll let you figure out how to get the last column.

David L. Carlson
Department of Anthropology
Texas A&M University

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Ashta
Sent: Saturday, November 14, 2015 4:28 PM
To: R help 
Subject: [R] Ranking

Hi all,

I have the following raw data some records  don't have the second variable.

test <- read.table(textConnection(" Country  STATUS
USA
USAW
USAW
GER
GERW
GERw
GERW
UNKW
UNK
UNKW
FRA
FRA
FRAW
FRAW
FRAW
SPA
SPAW
SPA  "),header = TRUE,  sep= "\t")
test

It is not reading it correctly.

Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  :
  line 17 did not have 2 elements



After reading   I want change the status column  to numeric so that I
can use the table function

test$STATUS <- ifelse(is.na(test$STATUS), 0,  1)

at the end I want the following table (Country, Won, Lost , Number of
games played and % of score ) and pick the top 3 countries.

COUNTRY   Won   Lost   NG%W
 USA 21 3  (2/3)*100
 GER 31 4  (3/4)*100
 UNK 21 3  (2/3)*100
 FRA 3 25  (3/5)*100
 SPA 1 2 3  (1/3)*100

Thank you in  advance

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


[R] Ranking

2015-11-14 Thread Ashta
Hi all,

I have the following raw data some records  don't have the second variable.

test <- read.table(textConnection(" Country  STATUS
USA
USAW
USAW
GER
GERW
GERw
GERW
UNKW
UNK
UNKW
FRA
FRA
FRAW
FRAW
FRAW
SPA
SPAW
SPA  "),header = TRUE,  sep= "\t")
test

It is not reading it correctly.

Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  :
  line 17 did not have 2 elements



After reading   I want change the status column  to numeric so that I
can use the table function

test$STATUS <- ifelse(is.na(test$STATUS), 0,  1)

at the end I want the following table (Country, Won, Lost , Number of
games played and % of score ) and pick the top 3 countries.

COUNTRY   Won   Lost   NG%W
 USA 21 3  (2/3)*100
 GER 31 4  (3/4)*100
 UNK 21 3  (2/3)*100
 FRA 3 25  (3/5)*100
 SPA 1 2 3  (1/3)*100

Thank you in  advance

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] ranking a vector in R

2012-06-21 Thread Prof Brian Ripley

On 21/06/2012 07:24, Petr Savicky wrote:

On Thu, Jun 21, 2012 at 12:24:47AM +0200, Jessy wrote:

Hello,


May someone help me with how in R I can rank a vector from highest to
lowest. i.e  rank 1 (smallest rank) is given to the highest value instead
of the usual way that it get's the highest rank.


Hello:

Try

   x <- c(3, 2, 4, 1)
   rank(-x)

   [1] 2 3 1 4


Or more generally

rank(-xtfrm(x))

which works also for non-numeric x.


--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

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


Re: [R] ranking a vector in R

2012-06-21 Thread arun
Hi,

> dat<-c(5,4,3,12,15)
> rank(-dat)
[1] 3 4 5 2 1
> rank(dat)
[1] 3 2 1 4 5

A.K.



- Original Message -
From: Jessy 
To: r-help@r-project.org
Cc: 
Sent: Wednesday, June 20, 2012 6:24 PM
Subject: [R] ranking a vector in R

Hello,


May someone help me with how in R I can rank a vector from highest to
lowest. i.e  rank 1 (smallest rank) is given to the highest value instead
of the usual way that it get's the highest rank.

Regards,
Jessy

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


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


Re: [R] ranking a vector in R

2012-06-21 Thread Christian Brechbühler
On Wed, Jun 20, 2012 at 6:24 PM, Jessy  wrote:

> May someone help me with how in R I can rank a vector from highest to
> lowest. i.e  rank 1 (smallest rank) is given to the highest value instead
> of the usual way that it get's the highest rank.
>

How about rank(-v), e.g.,

>
> rank(-c(3,1,4,6,5))
> [1] 4 5 3 1 2


/Christian

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


Re: [R] ranking a vector in R

2012-06-20 Thread Petr Savicky
On Thu, Jun 21, 2012 at 12:24:47AM +0200, Jessy wrote:
> Hello,
> 
> 
> May someone help me with how in R I can rank a vector from highest to
> lowest. i.e  rank 1 (smallest rank) is given to the highest value instead
> of the usual way that it get's the highest rank.

Hello:

Try

  x <- c(3, 2, 4, 1)
  rank(-x)

  [1] 2 3 1 4

Hope this helps.

Petr Savicky.

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


Re: [R] ranking a vector in R

2012-06-20 Thread Jorge I Velez
Hi Jessy,

?sort
?rank

will be a good starting point.

HTH,
Jorge.-


On Wed, Jun 20, 2012 at 6:24 PM, Jessy  wrote:

> Hello,
>
>
> May someone help me with how in R I can rank a vector from highest to
> lowest. i.e  rank 1 (smallest rank) is given to the highest value instead
> of the usual way that it get's the highest rank.
>
> Regards,
> Jessy
>
>[[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.
>

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


[R] ranking a vector in R

2012-06-20 Thread Jessy
Hello,


May someone help me with how in R I can rank a vector from highest to
lowest. i.e  rank 1 (smallest rank) is given to the highest value instead
of the usual way that it get's the highest rank.

Regards,
Jessy

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


Re: [R] Ranking submodels by AIC (more general question)

2011-06-23 Thread Alexandra Thorn
Thanks for the suggestion.  Those functions only provide part of the
functionality I want.  

After a great deal more of drawing the internet, I've concluded that the
correct answer to my question is dredge() from the package MuMIn.  It
seems to use the same AIC algorithm as AIC, which is perfect for making
comparisons!

Thanks again to everybody who's tried to help me out on this!
Alexandra

On Thu, 2011-06-23 at 21:29 +0200, Jan van der Laan wrote: 
> Alexandra,
> 
> Have a look at add1 and drop1.
> 
> Regards,
> Jan
> 
> 
> On 06/23/2011 07:32 PM, Alexandra Thorn wrote:
> > Here's a more general question following up on the specific question I
> > asked earlier:
> >
> > Can anybody recommend an R command other than mle.aic() (from the wle
> > package) that will give back a ranked list of submodels?  It seems like
> > a pretty basic piece of functionality, but the closest I've been able to
> > find is stepAIC(), which as far as I can tell only gives back the best
> > submodel, not a ranking of all submodels.
> >
> > Thanks in advance,
> > Alexandra
> >
> > __
> > 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.
>

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


Re: [R] Ranking submodels by AIC (more general question)

2011-06-23 Thread Jan van der Laan

Alexandra,

Have a look at add1 and drop1.

Regards,
Jan


On 06/23/2011 07:32 PM, Alexandra Thorn wrote:

Here's a more general question following up on the specific question I
asked earlier:

Can anybody recommend an R command other than mle.aic() (from the wle
package) that will give back a ranked list of submodels?  It seems like
a pretty basic piece of functionality, but the closest I've been able to
find is stepAIC(), which as far as I can tell only gives back the best
submodel, not a ranking of all submodels.

Thanks in advance,
Alexandra

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


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


[R] Ranking submodels by AIC (more general question)

2011-06-23 Thread Alexandra Thorn
Here's a more general question following up on the specific question I
asked earlier:

Can anybody recommend an R command other than mle.aic() (from the wle
package) that will give back a ranked list of submodels?  It seems like
a pretty basic piece of functionality, but the closest I've been able to
find is stepAIC(), which as far as I can tell only gives back the best
submodel, not a ranking of all submodels.

Thanks in advance,
Alexandra

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


Re: [R] Ranking correlation with R

2010-04-15 Thread Peter Ehlers

On 2010-04-14 16:04, David Nemer wrote:

Hello Guys, thank you all very much for the help!

Sorry for my total lack of knowledge in R... so I did the correlation.. and
got these results:


cor(A, C, method = "spearman")
[1] 0.4922165
cor(B, C, method = "spearman")
[1] 0.1922412
cor(A, B, method = "spearman")
[1] -0.00889328


I don't know how to interpret them... so the correlation is good when it is
really close to 1 or to 0? What about negative correlation??


Your questions suggest that it's time to do some studying.
Crack open a stats book (or at least check Wikipedia). There is
no such thing as a 'good' or 'bad' correlation. Everything
depends on context. You shouldn't use a statistic if you don't
understand it.

 -Peter Ehlers



Cheers,
--
David Nemer


On Sat, Apr 10, 2010 at 2:58 PM, Gabor Grothendieck
wrote:



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





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




--
Peter Ehlers
University of Calgary

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


Re: [R] Ranking correlation with R

2010-04-14 Thread David Nemer
Hello Guys, thank you all very much for the help!

Sorry for my total lack of knowledge in R... so I did the correlation.. and
got these results:

> cor(A, C, method = "spearman")
>[1] 0.4922165
> cor(B, C, method = "spearman")
>[1] 0.1922412
> cor(A, B, method = "spearman")
> [1] -0.00889328

I don't know how to interpret them... so the correlation is good when it is
really close to 1 or to 0? What about negative correlation??

Cheers,
--
David Nemer


On Sat, Apr 10, 2010 at 2:58 PM, Gabor Grothendieck  wrote:

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

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


Re: [R] Ranking correlation with R

2010-04-10 Thread Gabor Grothendieck
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  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@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.
>

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


Re: [R] Ranking correlation with R

2010-04-10 Thread Jim Lemon

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

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


Re: [R] Ranking correlation with R

2010-04-09 Thread Joshua Wiley
On Fri, Apr 9, 2010 at 10:23 AM, David Nemer  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
> C

In 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/

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


Re: [R] Ranking correlation with R

2010-04-09 Thread Joshua Wiley
>> 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().
>
> One possible source for such numbers would be row.names(dfrm) since by
> default (assuming they are in a data.frame) row.names are an ascending
> series of integers, but one could also number them by appending a
> colrankn=1:nrow(dfrm).

What about this?

x <- c("A","C","B")
y <- c("A","B","C")
ranks <- match(y,x)

> ranks
[1] 1 3 2

> cor(seq_along(x), ranks)
[1] 0.5

It seems like as long as both sets of filenames contain exactly the
same names, that should work.

>
> David Winsemius, MD
> West Hartford, CT



-- 
Joshua Wiley
Senior in Psychology
University of California, Riverside
http://www.joshuawiley.com/

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


Re: [R] Ranking correlation with R

2010-04-09 Thread David Winsemius


On Apr 9, 2010, at 12:14 PM, Joshua Wiley wrote:

On Fri, Apr 9, 2010 at 8:58 AM, David Nemer   
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.. is


You 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().


One possible source for such numbers would be row.names(dfrm) since by  
default (assuming they are in a data.frame) row.names are an ascending  
series of integers, but one could also number them by appending a  
colrankn=1:nrow(dfrm).





Cheers,
--
David Nemer



--
Joshua Wiley
Senior in Psychology



David Winsemius, MD
West Hartford, CT

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


Re: [R] Ranking correlation with R

2010-04-09 Thread Joshua Wiley
On Fri, Apr 9, 2010 at 8:58 AM, David Nemer  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.. is

You 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/

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


Re: [R] Ranking correlation with R

2010-04-09 Thread Joshua Wiley
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  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@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/

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


[R] Ranking correlation with R

2010-04-09 Thread David Nemer
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@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.


[R] ranking the results of a questionnaire

2008-11-28 Thread Wolfgang Lindner
dear experts,

I reproduced an experiment (questionnaire) some times.
The result of the experiment is a vector of 5 factors, say (A,B,C,D,E).
In the original article the result is given in 5 pairs of mean and stDev for
A .. E, e.g. mean_A=37.4 and sd_A=8.1.
The interval for A,B,C,D,E values is 0..50. The original data frame is not
available.

For a comparison of my results L=(A',B',C',D',E')  with the original
G=(A,B,C,D,E)  we can interpret that smaller sd-values are 'better'.
But for the means the interpretation is a little bit complicated:
a smaller mean value of A or B or E is 'better', but a bigger mean value for
C or D is 'better'.

To construct a quantified value of being 'better' and to rank my data L vs.
the data G, I wrote a kind of an signed distance-function.
Here is my simple code and an small example run:

R version 2.7.1 (2008-06-23)
Copyright (C) 2008 The R Foundation for Statistical Computing
ISBN 3-900051-07-0

> L<-c(32.8,5.3,  26.3,9.0,  35.1,6.2,  33.4,6.3,  22.9,12.9)
> G<-c(37.4,8.1,  30.6,9.7,  32.0,7.9,  29.7, 9.0,  17.1,10.8)

> sigdist<- function (L,G)
 sqrt(
sign( G[1]-L[1] )*(G[1]-L[1])^2
  +   sign( G[2]-L[2] )*(G[2]-L[2])^2
  + sign( G[3]-L[3] )*(G[3]-L[3])^2
  +   sign( G[4]-L[4] )*(G[4]-L[4])^2
  - sign( G[5]-L[5] )*(G[5]-L[5])^2
  +   sign( G[6]-L[6])*(G[6]-L[6])^2
  - sign( G[7]-L[7] )*(G[7]-L[7])^2
  +   sign( G[8]-L[8] )*(G[8]-L[8])^2
  + sign( G[9]-L[9] )*(G[9]-L[9])^2
  +   sign( G[10]-L[10] )*(G[10]-L[10])^2
 )

> sigdist(L,G)
[1] 6.588627

I like to interpret the positive value 6.588 that  'the L vector is better
then G vector w.r.t. sigdist'.

My questions are:

1. are there build-in functions in R calculating some (distance?)value with
the possibility of a similar interpretation?
2. are there other ideas for a ranking of the experimental results L and G?

Any comments, critique or hints are very welcome.

Sincerely

Wolfgang

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