net.sourceforge.openforecast.models
Class RegressionModel

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

public class RegressionModel
extends AbstractForecastingModel

Implements a single variable linear regression model using the variable named in the constructor as the independent variable. The cofficients of the regression - the intercept and the slope - 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 linear regression model essentially attempts to put a straight line through the data points. For the more mathematically inclined, this line is defined by its gradient or slope, and the point at which it intercepts the x-axis (i.e. where the independent variable has, perhaps only theoretically, a value of zero). Mathematically, assuming the independent variable is x and the dependent variable is y, then this line can be represented as:

y = intercept + slope * x

Author:
Steven R. Gould

Field Summary
 
Fields inherited from class net.sourceforge.openforecast.models.AbstractForecastingModel
accuracyIndicators, initialized
 
Constructor Summary
RegressionModel(String independentVariable)
          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

RegressionModel

public RegressionModel(String independentVariable)
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.
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)
                throws ModelNotInitializedException
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.

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.

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

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