MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Re: Riddle with Ordering

  • To: mathgroup at smc.vnet.net
  • Subject: [mg78020] Re: [mg77934] Re: Riddle with Ordering
  • From: DrMajorBob <drmajorbob at bigfoot.com>
  • Date: Thu, 21 Jun 2007 05:51:15 -0400 (EDT)
  • References: <f58dbg$8gi$1@smc.vnet.net> <16868914.1182336134968.JavaMail.root@m35>
  • Reply-to: drmajorbob at bigfoot.com

Allowing ties, you get something like this, then:

Clear[rawRanking, ranks]
rawRanking[x_List] := Ordering@Ordering@x
ranks[int_List] := Module[{raw = rawRanking@int},
   Mean[Pick[raw, int, #]] & /@ int
   ]
{integers = RandomInteger[{0, 10}, 14], Sort@integers,
   rawRanking@integers, ranks@integers} // TableForm

2	1	5	10	3	6	4	1	6	7	2	2	9	9
1	1	2	2	2	3	4	5	6	6	7	9	9	10
3	1	8	14	6	9	7	2	10	11	4	5	12	13
4	3/2	8	14	6	19/2	7	3/2	19/2	11	4	4	25/2	25/2

Bobby

On Wed, 20 Jun 2007 04:28:07 -0500, <nazdrovje at gmail.com> wrote:

> I got this reply by  Andrzej Kozlowski, which was very close but not
> what I intended.
>
> ****Begin quote
>
> Iit's not much of a riddle for anyone who has been reading carefully
> this forum for a while as it has turned up more than once.  It gives
> you the permutation which will turn Sort[AnyList] into AnyList.   In
> other words:
>
> Sort[AnyList][[Ordering[Ordering[AnyList]]]] == Anylist
>
>
> This means, in particular, that if AnyPermuation is any permutation:
>
> Ordering[Ordering[AnyPermuation]]==AnyPermutation
>
> Moreover, AnyList does not have to be a list of reals, or even a list
> of numbers, and its elements need not be distinct.
> *****End quote
>
>
> The intended answer is that the above construct replaces each number
> with its rank in the list. This is useful for all kinds of statistics
> involving ranks, such as Spearman rank correlation (although
> Mathematica has this already built-in). The reason I required the
> numbers to be unique is that otherwise equal numbers would get unequal=

> (successive) ranks. Usually, a set of equal numbers is mapped to a set=

> of equal ranks (the average of the ranks that would be obtained for
> the set by the above method).
>
> Naz
>
>
>
> On Jun 19, 1:06 pm, nazdro... at gmail.com wrote:
>> Just a gem I discovered with Ordering[ ].
>>
>> Anyone have an idea what
>>
>> SomeArrayWithUniqueReals // Ordering // Ordering
>>
>> does?
>>
>> I like this, especially the double use of Ordering. Answer tomorrow.
>
>
>



-- =

DrMajorBob at bigfoot.com


  • Prev by Date: Re: Inequalities
  • Next by Date: Mac OS X 10.4.10 update and 64 bit
  • Previous by thread: Re: Riddle with Ordering
  • Next by thread: Re:QuestionUsenet