MULTIPLES inputVector test resultVariable

Replaces the contents of the result variable with the number of "multiples" whose sizes satisfy the test.

A multiple is the case where more than one element of a vector has the same value.

The size of a multiple is the number of repetitions that make it up.

For example, the vector A = (1 3 5 3 6 5 8 5) has two multiples: one of size 2 and one of size 3. So, if we had the command MULTIPLES A =2 B, then B would become 1 because there is one duplicate. If the test were >2, B would become 1 again, because there is only one multiple whose size is greater than two. If the test were >=2, then B would become 2. A test of =1 will result in B being 3. The definition of a multiple for this command has been relaxed to allow 1 to be considered a ("degenerate") multiple.

Missing data (represented by "." or "NaN"), are ignored in the computation. See the example at right.

If the input vector is empty, the result variable will contain zero, no matter what test is applied.

COPY 1,10 A
SAMPLE 10 A B
MULTIPLES B =2 C
PRINT B C

The above program produced the following output on one trial:

B: (4.0 8.0 5.0 8.0 7.0 9.0 4.0 3.0 5.0 7.0)
C: 4.0

Here's a practical application of the MULTIPLES command:

(What is the probability that in a group of 25 people chosen at random, two or more will have the same birthday?)

COPY 1000 rptCount
REPEAT rptCount
   GENERATE 25 1,365 A  'generate 25 "birthdays"
   MULTIPLES A >= 2 J   'how many duplicates,
      triplicates, quadruplicates, etc.?
   SCORE J Z            'keep score
END
COUNT Z >= 1 K  'how often were one or more birthdays replicated?
DIVIDE K rptCount probability
PRINT Z probability

Here's an example to show the handling of NaNs:

COPY (1 NaN 2 NaN 2 NaN) A
MULTIPLES A =1 B
MULTIPLES a >=2 C
PRINT B C

This produces the following output:

B: 1.0
C: 1.0

The NaNs are ignored.

Here is an example showing how to find the number of unique values in a vector:

A=(1 3 5 3 6 5 8 5)
MULTIPLES a > 0 uniqueValueCount
PRINT uniqueValueCount

This will print:

uniqueValueCount: 5.0