/** * Gets the tricube bisquare weigths. * * @param residuals the residuals array * @return the tricube bisquare weigths */ public static double[] getTricubeBisquareWeights(final double... residuals) { final double[] weights = getTricubeWeights(residuals.length); final double[] weights2 = new double[residuals.length]; final double s6 = median(abs(residuals)) * 6; for (int i = 2; i < residuals.length; i++) { final double k = Math.pow(1 - Math.pow(residuals[i] / s6, 2), 2); weights2[i] = k > 0 ? (1 / k) * weights[i] : Double.MAX_VALUE; } weights2[0] = weights2[1] = weights2[2]; return weights2; }
/** * Gets the Local Regression (Loess) parameter estimates. * * @param y the dependent variable * @return the Loess parameter estimates */ public static double[] getLoessParameterEstimates(final double... y) { final double[] x = createIndependentArray(y.length); return createWeightedLinearRegression(x, y, getTricubeWeights(y.length)) .regress().getParameterEstimates(); }
/** * Gets the robust loess parameter estimates. * * @param y the dependent variable * @return the robust loess parameter estimates */ public static double[] getRobustLoessParameterEstimates(final double... y) { final double[] x = createIndependentArray(y.length); final SimpleRegression tricubeRegression = createWeightedLinearRegression(x, y, getTricubeWeights(y.length)); final double[] residuals = new double[y.length]; for (int i = 0; i < y.length; i++) { residuals[i] = y[i] - tricubeRegression.predict(x[i]); } final SimpleRegression tricubeBySqrRegression = createWeightedLinearRegression(x, y, getTricubeBisquareWeights(residuals)); final double[] estimates = tricubeBySqrRegression.regress().getParameterEstimates(); if (Double.isNaN(estimates[0]) || Double.isNaN(estimates[1])) { return tricubeRegression.regress().getParameterEstimates(); } return estimates; }