Tell me more ×
Cross Validated is a question and answer site for statisticians, data analysts, data miners and data visualization experts. It's 100% free, no registration required.

I want to represent a variable as a number between 0 and 1. The variable is a non-negative integer with no inherent bound. I map 0 to 0 but what can I map to 1 or numbers between 0 and 1?

I could use the history of that variable to provide the limits. This would mean I have to restate old statistics if the maximum increases. Do I have to do this or are there other tricks I should know about?

share|improve this question
3  
Because any nondecreasing function from $[0, \infty) \to [0, 1]$ will do the trick, you have a lot of flexibility. But some methods will be better than others, depending on the application. What is your purpose in seeking such a re-expression? – whuber Mar 14 '11 at 21:12
1  
I am measuring content across many different dimensions and I want to be able to make comparisons in terms of how relevant a given piece of content is. Additionally, I want to display values across these dimensions that is explicable and easily understood. – Spencer Mar 14 '11 at 21:14
1  
@Spencer Exactly how are you measuring content and "relevance"? E.g., on arbitrary scales, as counts, proportions, frequencies of views, correlations with other content, etc. etc. Different types of measurements benefit from different kinds of re-expressions. – whuber Mar 14 '11 at 21:29
1  
I am measuring them on arbitrary scales. How old the content is. How many "points" a piece of content is received. Self-reported "interest" in the domain of the content. – Spencer Mar 14 '11 at 21:38
2  
One of the simplest transformations you could use is to convert your data into quantile scores. – charles.y.zheng Mar 15 '11 at 1:28
show 3 more comments

7 Answers

up vote 17 down vote accepted

A very common trick to do so (e.g., in connectionist modeling) is to use the hyperbolic tangent tanh as the 'squashing function". It automatically fits all numbers into the interval between -1 and 1. Which in your case restricts the range from 0 to 1. In r and matlab you get it via tanh().

Another squashing function is the logistic function (thanks to Simon for the name), provided by $ f(x) = 1 / (1 + e ^{-x} ) $, which restricts the range from 0 to 1 (with 0 mapped to .5). So you would have to multiply the result by 2 and subtract 1 to fit your data into the interval between 0 and 1.

Here is some simple R code which plots both functions (tanh in red, logistic in blue) so you can see how both squash:

x <- seq(0,20,0.001)
plot(x,tanh(x),pch=".", col="red", ylab="y")
points(x,(1 / (1 + exp(-x)))*2-1, pch=".",col="blue")
share|improve this answer
Thanks for your answer. That solves the problem of bounding. For my data it goes to 1 very quickly for my data so I guess the next thing I need to do is to scale this information to concentrate on the interesting range which I could do based on the history of it without fear of leaving the bound, just hitting the limit. – Russell Gallop Aug 2 '10 at 15:19

As often, my first question was going to be "why do you want to do this", then I saw you've already answered this in the comments to the question: "I am measuring content across many different dimensions and I want to be able to make comparisons in terms of how relevant a given piece of content is. Additionally, I want to display values across these dimensions that is explicable and easily understood."

There is no reason to normalize the data so that the max is 1 and the min is zero in order to achieve this, and my opinion is that this would be a bad idea in general. The max or min values could very easily be outliers that are unrepresentative of the population distribution. @osknows parting remark about using $z$-scores is a much better idea. $z$-scores (aka standard scores) normalize each variable using its standard deviation rather than its range. The standard deviation is less influenced by outliers. In order to use $z$-scores, it's preferable that each variable has a roughly normal distribution, or at least has a roughly symmetric distribution (i.e. isn't severely skew) but if necessary you can apply some appropriate data transformation first in order to achieve this; which transformation to use could be determined by finding the best fitting Box–Cox transformation.

share|improve this answer
so there is nothing to do with forcing the data to the $[0, 1]$, and in general I do agree with standardization if the author really looks for it :) I answered before the discussion appeared, so probably delete my answer if this one is correct :) – Dmitrij Celov Mar 15 '11 at 10:27

Any sigmoid function will work:

share|improve this answer
erf is not a very handy function, provided you don't want to rather use it for its derivative. – mbq Aug 2 '10 at 15:26

In addition to the good suggestions by Henrik and Simon Byrne, you could use f(x) = x/(x+1). By way of comparison, the logistic function will exaggerate differences as x grows larger. That is, the difference between f(x) and f(x+1) will be larger with the logistic function than with f(x) = x/(x+1). You may or may not want that effect.

share|improve this answer

My earlier post has a method to rank between 0 and 1. Advice on classifier input correlation

However, the ranking I have used, Tmin/Tmax uses the sample min/max but you may find the population min/max more appropriate. Also look up z scores

share|improve this answer

There are two ways to implement this that I use commonly. I am always working with realtime data, so this assumes continuous input. Here's some pseudo-code:

Using a trainable minmax:

define function peak:
// keeps the highest value it has received

define function trough:
// keeps the lowest value it has received

define function calibrate:
// toggles whether peak() and trough() are receiving values or not

define function scale:
// maps input range [trough.value() to peak.value()] to [0.0 to 1.0]

This function requires that you either perform an initial training phase (by using calibrate()) or that you re-train either at certain intervals or according to certain conditions. For instance, imagine a function like this:

define function outBounds (val, thresh):
if val > (thresh*peak.value()) || val < (trough.value() / thresh):
calibrate()
// peak and trough are normally not receiving values, but if outBounds() receives a value that is more than 1.5 times the current peak or less than the current trough divided by 1.5, then calibrate() is called which allows the function to recalibrate automatically.

Using an historical minmax:

var arrayLength = 1000
var histArray[arrayLength]

define historyArray(f):
histArray.pushFront(f) //adds f to the beginning of the array

define max(array):
// finds maximum element in histArray[]
return max

define min(array):
// finds minimum element in histArray[]
return min

define function scale:
// maps input range [min(histArray) to max(histArray)] to [0.0 to 1.0]

main()
historyArray(histArray)
scale(min(histArray), max(histArray), histArray[0])
// histArray[0] is the current element

share|improve this answer
This can all be implemented in Max/MSP/Jitter with the [peak] and [trough] objects for the first example and with [jit.3m] for the second example. – msutherl Aug 3 '10 at 15:40

A very simple option is dividing each number in your data by the largest number in your data. If you have many small numbers and a few very large ones, this might not convey the information well. But it's relatively easy; if you think meaningful information is lost when you graph the data like this, you could try one of the more sophisticated techniques that others have suggested.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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