import static java.lang.System.*;

import java.util.*;

 

import static javastat.regression.PsiFunction.*;

import static javastat.regression.SelectionCriterion.*;

import javastat.regression.*;

import static javastat.util.Argument.*;

import javastat.util.*;

 

/**

 *

 * <p>Data Source: Brinkman, N. D., 1981. Ethanol fuel-A single-cylinder

 * engine study of efficiency and exhaust emissions. SAE Transactions 90,

 * No. 810345, 1410-1424. </p>

 */

 

public class RobustSelectionCriterionExample extends SelectionCriterionTemplate

{

 

    public double c;

 

    public double[] residuals;

 

    public RobustSelectionCriterionExample(double c)

    {

        this.c = c;

    }

 

    public RobustSelectionCriterionExample(double c,

                                       Hashtable argument,

                                       Object ...dataObject)

    {

        this.c = c;

        weightedSelectionCriterion = (Double) weightedSelectionCriterion(

                argument, dataObject);

    }

 

 

    public RobustSelectionCriterionExample(Hashtable argument,

                                      Object ...dataObject)

    {

        this(2.0, argument, dataObject);

    }

 

    public Double weightedRSS(Hashtable argument,

                            Object ...dataObject)

    {

        residuals = ((WeightedSelectionCriterion)

           new WeightedSelectionCriterion(argument, dataObject).

           statisticalAnalysis).residuals;

        weightedRSS = 0.0;

        for (int i = 0; i < residuals.length; i++)

        {

            if (Math.abs(residuals[i]) <= c)

            {

                weightedRSS += Math.pow(residuals[i], 2.0);

            }

            else

            {

                weightedRSS += 2.0 * c * Math.abs(residuals[i]) -

                        Math.pow(c, 2.0);

            }

        }

 

        return weightedRSS;

    }

 

    public Double penalty(Hashtable argument,

                       Object ...dataObject)

    {

        return new WeightedSelectionCriterion().

penalty(argument, dataObject);

    }

 

    public static void main(String[] args)

    {

        DataManager dm = new DataManager();

        BasicStatistics bs = new BasicStatistics();

        Hashtable argument = new Hashtable();

        String[][] mysqlData = new DBLoader("jdbc:mysql://localhost/data",

                                        "root", "",

                                        "SELECT * FROM data").data;

        double[][] data = dm.transpose(dm.stringToDouble(mysqlData));

        double[] response = data[0];

        double[][] covariate = dm.getData(1, data.length - 1, 0,

                                     data[0].length - 1, data);

        double[][] weightMatrix =

dm.inverse(bs.covarianceAR1(response.length, 0.2, 1));

        double robustAIC = (Double) new RobustSelectionCriterionExample(

argument, weightMatrix, response, covariate).

weightedSelectionCriterion;

        out.println(robustAIC);

 

        String[][] postgreData = new DBLoader(

                "jdbc:postgresql://localhost/weitest", "wenwei", "1234",

                "SELECT * FROM data").data;

        data = dm.transpose(dm.stringToDouble(postgreData));

        response = data[0];

        double[] covariate2 = data[1];

        argument.put(SMOOTHING_PARAMETER, 1000);

        argument.put(DIVISIONS, 10);

        argument.put(DEGREE, 3);

        argument.put(ORDER, 2);

        double robustGCV =

(Double) new RobustSelectionCriterionExample(1.5).

            weightedSelectionCriterion(argument, response, covariate2);

    }

 

}

 

Results:

The robust AIC is 1.329

The robust GCV is 1.126