1
$\begingroup$

I have a list of numbers:

list = {0.202431, -0.011127, -0.313263, -0.181741, -0.0800737, -0.0513697, 
      0.0808629, 0.197559, 0.27316, -0.341358, -0.0513697, 0.347136, 0.147117};

I need to count pairs of numbers. I tried this, but it doesn't work:

Values[[#n-#(n-1)],& list]

I mean to count first two numbers, then third-second, fourth-second, etc. I want to make sign test for independent residuals and I need to know how many numbers has possitive mark. The numbers in the list are actually residuals. so I need to know how many pairs {e2-e1,e3-e2,e4-e5,e6-e7,...} has possitive mark

$\endgroup$
  • 1
    $\begingroup$ What do you mean by "count pairs of numbers"? Do you mean count how many different pairs there are? Based on your code attempt, maybe you're trying to find out how many times a particular difference appears among the pairs? As it is, this question is very confusing. Can you provide more details? A smaller example with the expected output would go a long way toward making the question understandable. $\endgroup$ – march May 3 '16 at 22:56
  • $\begingroup$ I'm sorry, but "count first two numbers, then second+third, third+fourth" still doesn't make sense, because it suggests that you are just trying to find how many pairs there are, which I'm pretty sure you don't want. I strongly encourage you to give the expected output for your list, because that will go a long way toward helping us figure out what you want. $\endgroup$ – march May 3 '16 at 23:00
  • 1
    $\begingroup$ Does this give what you need: Partition[list, 2, 1]? Or, this: Differences[list]? $\endgroup$ – kglr May 3 '16 at 23:10
  • $\begingroup$ Pretty much, but I need more, to deduct each pair like #2 - #1, to get one value instead of 2. So total count of numbers will be 12 instead of 13, $\endgroup$ – krecek7 May 3 '16 at 23:18
4
$\begingroup$
list = {0.202431, -0.011127, -0.313263, -0.181741, -0.0800737, 0.0513697, 
  0.0808629, 0.197559, 0.27316, -0.341358, -0.0513697, 0.347136, 0.147117};

differences = Differences[list]

{-0.213558, -0.302136, 0.131522, 0.101667, 0.028704, 0.132233, 0.116696, 0.075601, -0.614518, 0.289988, 0.398506, -0.200019}

Count[differences, _?Positive]

8

Or, in a single step, Count[Differences[list], _?Positive].

Also:

Total[UnitStep[Differences[list]]]

8

Update: I think you may find the built-in function SignTest useful:

SignTest[list, 0, "TestDataTable"]

Mathematica graphics

SignTest[list, 0, "TestConclusion"]

Mathematica graphics

$\endgroup$
2
$\begingroup$
d = Sign[Differences[list]]

(Classical) Hypothesis testing (null hypothesis p=0.5):

Probability[x == Count[d, 1], 
 x \[Distributed] BinomialDistribution[Length@d, 0.5]]

or

Likelihood[BinomialDistribution[Length@d, 0.5], {Count[d,1]}]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.