Example 1: Empirical Quantiles

In this example, five empirical quantiles from a sample of size 30 are obtained. Notice that the 0.5 quantile corresponds to the sample median. The data are from Hinkley (1977) and Velleman and Hoaglin (1981). They are the measurements (in inches) of precipitation in Minneapolis/St. Paul during the month of March for 30 consecutive years.

import java.text.*;
import com.imsl.stat.*;

public class  EmpiricalQuantilesEx1 {
    public static void main(String args[]) {
        String fmt = "0.00";
        DecimalFormat df = new DecimalFormat(fmt);
       
        double[]  x = {0.77, 1.74, 0.81, 1.20, 1.95, 1.20, 0.47, 1.43, 3.37,
                2.20, 3.00, 3.09, 1.51, 2.10, 0.52, 1.62, 1.31, 0.32, 0.59,
                0.81, 2.81, 1.87, 1.18, 1.35, 4.75, 2.48, 0.96, 1.89, 0.90,
                2.05
        };
        double[] qProp = {0.01, 0.5, 0.90, 0.95, 0.99};
        
        EmpiricalQuantiles eq = new EmpiricalQuantiles(x, qProp);
        double [] Q = eq.getQ();
        double [] XLo = eq.getXLo();
        double [] XHi = eq.getXHi();
        System.out.println("               Smaller        Empirical        Larger");
        System.out.println(" Quantile       Datum          Quantile         Datum");
        for (int i = 0; i < qProp.length; i++)
            System.out.println(df.format(qProp[i])+"           "+df.format(XLo[i])+
                    "             "+df.format(Q[i])+"           "+df.format(XHi[i]));
    }
}

Output

               Smaller        Empirical        Larger
 Quantile       Datum          Quantile         Datum
0.01           0.32             0.32           0.32
0.50           1.43             1.47           1.51
0.90           3.00             3.08           3.09
0.95           3.37             3.99           4.75
0.99           4.75             4.75           4.75
Link to Java source.