Example Five-number summary
1 example
1.1 example in r
1.2 example in python
1.3 example in sas
1.4 example in stata
example
this example calculates five-number summary following set of observations: 0, 0, 1, 2, 63, 61, 27, 13. these number of moons of each planet in solar system.
it helps put observations in ascending order: 0, 0, 1, 2, 13, 27, 61, 63. there 8 observations, median mean of 2 middle numbers, (2 + 13)/2 = 7.5. splitting observations either side of median gives 2 groups of 4 observations. median of first group lower or first quartile, , equal (0 + 1)/2 = 0.5. median of second group upper or third quartile, , equal (27 + 61)/2 = 44. smallest , largest observations 0 , 63.
so five-number summary 0, 0.5, 7.5, 44, 63.
example in r
it possible calculate five-number summary in r programming language using fivenum function. summary function, when applied vector, displays five-number summary mean (which not part of five-number summary).
> moons <- c(0, 0, 1, 2, 63, 61, 27, 13)
> fivenum(moons)
[1] 0.0 0.5 7.5 44.0 63.0
> summary(moons)
min. 1st qu. median mean 3rd qu. max.
0.0 0.5 7.5 20.88 44.0 63
example in python
this python example uses python3 , numerical library numpy.
import numpy np
moons = np.array([0, 0, 1, 2, 63, 61, 27, 13])
tukey = [np.min(moons),
np.percentile(moons, 25, interpolation= midpoint ),
np.median(moons),
np.percentile(moons, 75, interpolation= midpoint ),
np.max(moons)]
v in tukey:
print(v)
0
0.5
7.5
44.0
63
example in sas
you can use proc univariate in sas (software) 5 number summary:
ata fivenum; input x @@; datalines; 1 2 3 4 20 202 392 4 38 20
run;
ods select quantiles; proc univariate data = fivenum;
output out = fivenums min = min q1 = q1 q2 = median q3 = q3 max = max;
run;
proc print data = fivenums; run;
example in stata
input byte y
0
0
1
2
63
61
27
13
end
list
tabstat y, statistics(min q max)
Comments
Post a Comment