# Changing the scale of a variable to 0-100

I have constructed a social capital index using PCA technique. This index comprises values both positive and negative. I want to transform / convert this index to 0-100 scale to make it easy to interpret. Please suggest me an easiest way to do so.

-
 Related question: Standard formula for quick calculation of scores. – chl♦ Apr 5 '12 at 16:52 The logistic function used in logit models might come in handy as well. Depends on specific purpose. – Ondrej Apr 5 '12 at 17:45

Any variable (univariate distribution) v with observed min and max values (or these could be preset potential bounds for values) can be rescaled to range min' to max' by formula (max'-min')/(max-min)(v-max)+max' or (max'-min')/(max-min)(v-min)+min'.

-

Just to add to ttnphnss's answer, to implement this process in Python (for example), this function will do the trick:

from __future__ import division

def rescale(values, new_min = 0, new_max = 100):
output = []
old_min, old_max = min(values), max(values)

for v in values:
new_v = (new_max - new_min) / (old_max - old_min) * (v - old_min) + new_min
output.append(new_v)

return output

print rescale([1, 2, 3, 4, 5])
# [0.0, 25.0, 50.0, 75.0, 100.0]

-
 Thanks, does this formula also apply on negative values?? for example, if my original variable ranges from -10 to 10 . – Sohail Akram Apr 5 '12 at 20:34 Yes - it works for all values - for example, print rescale([-10, -9, -5, 2, 6]) # [0.0, 6.25, 31.25, 75.0, 100.0] – Andrew Tulloch Apr 6 '12 at 5:13 Thanks to all who helped me to solve my problem. – Sohail Akram Apr 7 '12 at 18:09

first, lets get some example data:

x <- runif(20, -10, 10)


Here are two functions that will work in R

rescale <- function(x) (x-min(x))/(max(x) - min(x)) * 100
rescale(x)


Or, you could use other transformations. For example, the logit transform was mentioned by @ondrej

plogis(x)*100


or, other transforms:

pnorm(x)*100
pnorm(x, 0, 100) * 100
punif(x, min(x), max(x))*100

-