001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.commons.math3.stat.regression;
018
019 import org.apache.commons.math3.exception.MathIllegalArgumentException;
020 import org.apache.commons.math3.exception.NoDataException;
021
022 /**
023 * An interface for regression models allowing for dynamic updating of the data.
024 * That is, the entire data set need not be loaded into memory. As observations
025 * become available, they can be added to the regression model and an updated
026 * estimate regression statistics can be calculated.
027 *
028 * @version $Id: UpdatingMultipleLinearRegression.java 1392342 2012-10-01 14:08:52Z psteitz $
029 * @since 3.0
030 */
031 public interface UpdatingMultipleLinearRegression {
032
033 /**
034 * Returns true if a constant has been included false otherwise.
035 *
036 * @return true if constant exists, false otherwise
037 */
038 boolean hasIntercept();
039
040 /**
041 * Returns the number of observations added to the regression model.
042 *
043 * @return Number of observations
044 */
045 long getN();
046
047 /**
048 * Adds one observation to the regression model.
049 *
050 * @param x the independent variables which form the design matrix
051 * @param y the dependent or response variable
052 * @throws ModelSpecificationException if the length of {@code x} does not equal
053 * the number of independent variables in the model
054 */
055 void addObservation(double[] x, double y) throws ModelSpecificationException;
056
057 /**
058 * Adds a series of observations to the regression model. The lengths of
059 * x and y must be the same and x must be rectangular.
060 *
061 * @param x a series of observations on the independent variables
062 * @param y a series of observations on the dependent variable
063 * The length of x and y must be the same
064 * @throws ModelSpecificationException if {@code x} is not rectangular, does not match
065 * the length of {@code y} or does not contain sufficient data to estimate the model
066 */
067 void addObservations(double[][] x, double[] y) throws ModelSpecificationException;
068
069 /**
070 * Clears internal buffers and resets the regression model. This means all
071 * data and derived values are initialized
072 */
073 void clear();
074
075
076 /**
077 * Performs a regression on data present in buffers and outputs a RegressionResults object
078 * @return RegressionResults acts as a container of regression output
079 * @throws ModelSpecificationException if the model is not correctly specified
080 * @throws NoDataException if there is not sufficient data in the model to
081 * estimate the regression parameters
082 */
083 RegressionResults regress() throws ModelSpecificationException, NoDataException;
084
085 /**
086 * Performs a regression on data present in buffers including only regressors
087 * indexed in variablesToInclude and outputs a RegressionResults object
088 * @param variablesToInclude an array of indices of regressors to include
089 * @return RegressionResults acts as a container of regression output
090 * @throws ModelSpecificationException if the model is not correctly specified
091 * @throws MathIllegalArgumentException if the variablesToInclude array is null or zero length
092 */
093 RegressionResults regress(int[] variablesToInclude) throws ModelSpecificationException, MathIllegalArgumentException;
094 }