Function Math Statistics Class

Forecast

Predicts a future Y value for a specified X value using linear regression.

Signature (Visual Basic / VBA)

Public Function Forecast( _
      ByVal vX As Variant _
    , ByRef vYValues As Variant _
    , ByRef vXValues As Variant _
    ) As Variant

Code Example

    Forecast(0, Array(1, 3, 4), Array(2, 6, 9)) = 0.216216216216216
    Forecast(2, Array(1, 3, 4), Array(2, 6, 9)) = 1.08108108108108
    Forecast(5, Array(1, 3, 4), Array(2, 6, 9)) = 2.37837837837838

Parameters

Parameter Description
vYValues Dependent set of data. Numeric-type array or Variant array containing only numeric elements. This function is NOT affected by the current setting of the StatVarType Property. It assumes that vYValues is an array that contains only numeric elements.
vXValues Independent set of data. Numeric-type array or Variant array containing only numeric elements. This function assumes that vXValues is an array that contains only numeric elements.

Return Value

Function returns a future Y value for the specified X value. Function returns Null if the arrays vYValues and vXValues contain a different number of elements, if both arrays are empty, or if there is some type of error, such as if the argument is a Variant array which contains an Object reference or String.