[OT] Weighted distribution of Numbers

hh hh at hyperhh.de
Mon Aug 5 08:47:33 EDT 2019

When computing limits for distribution categories given
frequencies the following may be useful:

A number q is a p%-quantile of a data set
If  the percentage of data nums <= q is >= p%
and the percentage of data nums >= q is >= (100-p)%

For each percentage p there is an interval
[lowerV,upperV] so that each number from that interval
is p%-quantile of the data set.

To make it unique some use in case lowerV < upperV the
average of lowerV and upperV.

-- d=data in lines, sorted ascending numeric
-- p=percentage (num in range 0-100)
function quantile p,d
  put the num of lines of d into N
  put N*p/100 into m0
  put line ceil(N*p/100) of d into lowerV
  put line N+1 - ceil(N*(100-p)/100) of d into upperV
  -- return avg(lowerV,upperV) --> unique variant
  if lowerV=upperV then return lowerV
  else return lowerV,upperV
end quantile

For example quantile(50,d) returns the median of a data set,
quantile(25,d), quantile(50,d), quantile(75,d) the quartiles.

More information about the Use-livecode mailing list