English Français Deutsch

Fivenum

' Given an array of numbers, compute the five-number summary (min, quarter1, median, quarter3, max)

program fivenum(X)
rename X^ x
order x 1
dup
project x min, x median, x max, x count
set q1 = x_count / 4
set q1min = floor(q1)
set q1weight = q1 - q1min
set q3 = x_count * 3 / 4
set q3min = floor(q3)
set q3weight = q3 - q3min
swap
dup
select rownumber = q1min + 1 or rownumber = q1min + 2
extend w = q1weight * (rownumber - 1) - (rownumber - 2) * (1-q1weight)
extend xw = x * w
project xw sum
rename xw_sum x_quarter1
swap
select rownumber = q3min + 1 or rownumber = q3min + 2
extend w = q3weight * (rownumber - 1) - (rownumber - 2) * (1-q3weight)
extend xw = x * w
project xw sum
rename xw_sum x_quarter3
join cross
join cross
project x_min, x_quarter1, x_median, x_quarter3, x_max
print
end program

relation a
insert 3
insert 4
insert 18
insert 12
insert 17
insert 5
insert 6
insert 11
insert 8
run fivenum("a")

Given an array of numbers, compute the five-number summary (min, quarter1, median, quarter3, max)
x_min x_quarter1 x_median x_quarter3 x_max
3 0 8 0 18