net.sourceforge.openforecast.models
Class PolynomialRegressionModel

java.lang.Object
  extended by net.sourceforge.openforecast.models.AbstractForecastingModel
      extended by net.sourceforge.openforecast.models.PolynomialRegressionModel
All Implemented Interfaces:
ForecastingModel

public class PolynomialRegressionModel
extends AbstractForecastingModel

Implements a single variable polynomial regression model using the variable named in the constructor as the independent variable. The cofficients of the regression as well as the accuracy indicators are determined from the data set passed to init.

Once initialized, this model can be applied to another data set using the forecast method to forecast values of the dependent variable based on values of the dependent variable (the one named in the constructor).

A single variable polynomial regression model essentially attempts to put a polynomial line - a curve if you prefer - through the data points. Mathematically, assuming the independent variable is x and the dependent variable is y, then this line can be represented as:

y = a0 + a1*x + a2*x2 + a3*x3 + ... + am*xm
You can specify the order of the polynomial fit (the value of m in the above equation) in the constructor.

Author:
Steven R. Gould

Field Summary
 
Fields inherited from class net.sourceforge.openforecast.models.AbstractForecastingModel
accuracyIndicators, initialized
 
Constructor Summary
PolynomialRegressionModel(String independentVariable)
          Constructs a new polynomial regression model, using the given name as the independent variable.
PolynomialRegressionModel(String independentVariable, int order)
          Constructs a new linear regression model, using the given name as the independent variable.
 
Method Summary
 double forecast(DataPoint dataPoint)
          Using the current model parameters (initialized in init), apply the forecast model to the given data point.
 String getForecastType()
          Returns a short name for this type of forecasting model.
 int getNumberOfPredictors()
          Returns the number of predictors used by the underlying model.
 void init(DataSet dataSet)
          Initializes the coefficients to use for this regression model.
 String toString()
          Returns a detailed description of this forcasting model, including the intercept and slope.
 
Methods inherited from class net.sourceforge.openforecast.models.AbstractForecastingModel
calculateAccuracyIndicators, forecast, getAIC, getBias, getMAD, getMAPE, getMSE, getSAE
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PolynomialRegressionModel

public PolynomialRegressionModel(String independentVariable)
Constructs a new polynomial regression model, using the given name as the independent variable. For a valid model to be constructed, you should call init and pass in a data set containing a series of data points involving the given independent variable.

Using this constructor the order of the polynomial fit is not specified. The effect is that the model will try to determine an appropriate order for the given data. It will do this by calculating up to 10 coefficients and once the coefficients become numerically insignificant they will be excluded from the model.

Parameters:
independentVariable - the name of the independent variable to use in this model.

PolynomialRegressionModel

public PolynomialRegressionModel(String independentVariable,
                                 int order)
Constructs a new linear regression model, using the given name as the independent variable. For a valid model to be constructed, you should call init and pass in a data set containing a series of data points involving the given independent variable.

Parameters:
independentVariable - the name of the independent variable to use in this model.
order - the required order of the polynomial to fit.
Method Detail

init

public void init(DataSet dataSet)
Initializes the coefficients to use for this regression model. The intercept and slope are derived so as to give the best fit line for the given data set.

Additionally, the accuracy indicators are calculated based on this data set.

Parameters:
dataSet - the set of observations to use to derive the regression coefficients for this model.

forecast

public double forecast(DataPoint dataPoint)
Using the current model parameters (initialized in init), apply the forecast model to the given data point. The data point must have valid values for the independent variables. Upon return, the value of the dependent variable will be updated with the forecast value computed for that data point.

Parameters:
dataPoint - the data point for which a forecast value (for the dependent variable) is required.
Returns:
the same data point passed in but with the dependent value updated to contain the new forecast value.
Throws:
ModelNotInitializedException - if forecast is called before the model has been initialized with a call to init.

getNumberOfPredictors

public int getNumberOfPredictors()
Returns the number of predictors used by the underlying model.

Returns:
the number of predictors used by the underlying model.
Since:
0.5

getForecastType

public String getForecastType()
Returns a short name for this type of forecasting model. A more detailed explanation is provided by the toString method.

Returns:
a short string describing this type of forecasting model.

toString

public String toString()
Returns a detailed description of this forcasting model, including the intercept and slope. A shortened version of this is provided by the getForecastType method.

Specified by:
toString in interface ForecastingModel
Overrides:
toString in class Object
Returns:
a description of this forecasting model.


OpenForecast, Copyright (c) Steven Gould, 2002-2011