---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
## The heights of 19 sixteen year-old female students:
 
data=c(150,155,156,157,157,157,159,160,162,162,163,163,164,165,165,166,167,168,170)
stem(data)
 
#  The decimal point is 1 digit(s) to the right of the |
#  15 | 0
#  15 | 567779
#  16 | 022334
#  16 | 55678
#  17 | 0
 
length(data); Median(data); median(data)
#   19          162          162
 
## The quantity is odd so the two ways of calculating the median coincide

## We suppose the values are rounded to the nearest integer. So:
 
interv = seq(150,171,1)-1/2                   # 149.5, 150.5, ... ,170.5
freq = c(1,0,0,0,0,1,1,3,0,1,1,0,2,2,1,2,1,1,1,0,1)
noClass=1; histoclas(interv,freq)
 
# The mean (brown dot) is about  161.3681 
# For percentages use  PERC   For other statistics use the   morestat()
 
             
morestat()
#   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
#  149.5   157.1   162.2   161.4   165.1   170.5 
#    The brown dots are 5^ and 95^ percentiles 
#           The red dot is the mean
## To have a larger amount of digits (of median, that is the 50^ percentile):
percentile(50)
# 162.2498
## I can take 162.25 as an estimate of the median
## In this case (where the data represents lengths) it makes sense to take more digits.
 
## The approximations by default and those for excess partially compensate. That is why
## I can take the median with one or two more digits.

Back