Statistical Transformations

These functions are all case functions and have to do with the order of cases in the collection.

prev( a )

The value for a from the previous case. If this is the first case, prev gives 0.

prev( a, default)

prev( a, default, filter)

Optional arguments for prev( ). The default value is what prev( ) returns for the first case. So you can make factorials in an attribute named fact with a formula of caseIndex * prev( fact, 1)

filter is subtle. If it's present, prev will return the value from the first case before the current case for which filter is true.

next( a )

The value for a from the next case. If this is the last case, next gives 0. Optional arguments are the same as for prev( ).

rank( a )

The "place" of this case if the collection were sorted by a. Identical values get the same rank.

uniqueRank( a)

Like rank( ), above, except that this returns a unique value for each case in the collection (i.e., it breaks ties).

runLength( a )

This one's wild! It gives the number of identical values immediately prior to and including the current value.
Example: if flip contained {H, H, H, T, H, T, T}, runLength( flip) would return {1, 2, 3, 1, 1, 1, 2}. You can use max( runLength( flip)) to compute the longest streak of heads or tails in a coin-flipping simulation.

bin( a, bin, min, max)
a
= attribute
bin
= bin width
min
= start of bin 1
max
= end

Gives you a string (category value) for a - its bin as defined by the other arguments.
Example: bin(3.14, 2, 0, 10) gives "b02" because the value (pi) is in bin #2 in [0, 10] with bins of width 2.

The last two arguments are optional.

zScore( x )

sampleZScore( x )

The z-score of the value, that is, the difference between it and the mean divided by the standard deviation. This is the same as
(x - mean( x )) / stdDev( x )
, where stdDev is calculated with n-1 in the denominator.

These two are synonyms.

popZScore( x )

Just like zScore( ) (above) except calculated with n in the denominator (i.e., it assumes we have the population and not a sample of it)

 

Categories of Functions