Page 1 of 1

Maths question (log() maybe).

Posted: Sat Feb 24, 2007 3:34 pm
by onion2k
(This is actually related to the table of scores I had a question about in databases.)

I have a table of score data. I'm fetching the top 25 scores and outputting them using a system that makes the highest score biggest:

Code: Select all

	function scoreToSize($s,$min,$max) { //Score, minimum score, maximum score
	
		static $scoreSize = array("tiny","small","medium","large","verylarge","huge"); //These are CSS classes
		
		$range = $max-$min; //Find the full range
		$s = $s-$min; //Zero base the current score value.
		$per = (($s/$range)*100); //Work out the percentile value of the score in the range
		$rper = 100/count($scoreSize)+1; //Work out the 'band width' of each size
		$level = round($per / $rper); //Calculate which band the score is in
		
		return $scoreSize[$level]; // Return the band class
			
	}
This works fine, it calculates the 'band' in which the score appears as a percentage of the difference between the biggest and the smallest.

However, it really only works if there is a reasonably even distribution of scores across the range. If they're 1,2,2,3,3,5,6,6,6,6,7,10,12 there's no problem, but if there's a score that's very different, such as 50, it means the table displays with 1 'huge' score and all the rest are 'tiny'.

Is there a solution to this? I thought about making it a logarithmic scale, but I'm not sure how to go about doing that.

Posted: Sat Feb 24, 2007 4:14 pm
by feyd
Number of bands: ceil(sqrt(high - low))
I'd then use standard deviation for the destribution.

Posted: Sun Feb 25, 2007 4:02 am
by onion2k
feyd wrote:Number of bands: ceil(sqrt(high - low))
The number of bands has to be fixed as they're defined as CSS classes.
feyd wrote:I'd then use standard deviation for the destribution.
I've got the standard deviation, but I've no idea what to do with it. :cry:

Posted: Sun Feb 25, 2007 5:36 am
by dude81
I'm not sure what thesis you are using behind this logic( name of the formula could be of help).

But defnitely standard deviation is a standard way for such average scores and ranks.

I think a tutorial on standard deviation could be of help.

Posted: Sun Feb 25, 2007 10:27 am
by feyd
Standard deviation tells you where the bulk of your population is. Data within one standard deviation (as an edge) is 68.27% of your sample's arithmetic mean, within two widens that to 95.45% and the third brings it to 99.73%.

Posted: Sun Feb 25, 2007 1:22 pm
by onion2k
I'm pretty sure that the standard deviation isn't any use in this case. In a set with one outlying result all the rest are going to be within 1 standard deviation of the mean. That's no help at all, it's the same as what I have now (all the smaller scores being tiny with one big score). I'm trying to get a more linear distribution of sizes. I think I'm just going to have to make the first 3 the biggest, next 3 the next biggest down, and so on.