Polynomial Module

Linear regression using polynomials as regression function: f(x) = a + bx + cx^2 + ....

Functions and values

Function or value Description

cooksDistance order xData yData

Full Usage: cooksDistance order xData yData

Parameters:
    order : int - order of the polynomial (1 = linear, 2 = quadratic, ... )
    xData : Vector<float> - vector of x values
    yData : Vector<float> - vector of y values

Returns: vector returns collection of cooks distances for each data point

Fits a polynomial model of user defined order to the data and returns the cooks distance for every data pair present in the input collections as an estimator for the influence of each data point in coefficient estimation.

order : int

order of the polynomial (1 = linear, 2 = quadratic, ... )

xData : Vector<float>

vector of x values

yData : Vector<float>

vector of y values

Returns: vector

returns collection of cooks distances for each data point

Example

 
   // e.g. days since a certain event
   let xData = vector [|1.;2.;3.;4.;5.;6.|]
   // e.g. temperature measured at noon of the days specified in xData 
   let yData = vector [|4.;7.;9.;8.;7.;9.;|]
   
   // Returns distances for a quadratic polynomial
   let distances = 
       LinearRegression.OLS.Polynomial.cooksDistance 2 xData yData

fit order xData yData

Full Usage: fit order xData yData

Parameters:
    order : int - order of the polynomial (1 = linear, 2 = quadratic, ... )
    xData : Vector<float> - vector of x values
    yData : Vector<float> - vector of y values

Returns: Coefficients vector of polynomial coefficients sorted as [intercept;constant;quadratic;...]

Calculates the polynomial coefficients for polynomial regression.

order : int

order of the polynomial (1 = linear, 2 = quadratic, ... )

xData : Vector<float>

vector of x values

yData : Vector<float>

vector of y values

Returns: Coefficients

vector of polynomial coefficients sorted as [intercept;constant;quadratic;...]

Example

 
   // e.g. days since a certain event
   let xData = vector [|1.;2.;3.;4.;5.;6.|]
   // e.g. temperature measured at noon of the days specified in xData 
   let yData = vector [|4.;7.;9.;8.;7.;9.;|]
   
   // Estimate the three coefficients of a quadratic polynomial.
   let coefficients = 
       LinearRegression.OLS.Polynomial.fit 2 xData yData

fitWithWeighting order weighting xData yData

Full Usage: fitWithWeighting order weighting xData yData

Parameters:
    order : int - order of the polynomial (1 = linear, 2 = quadratic, ... )
    weighting : Vector<float> - Vector of weightings that define the releveance of each point for fitting.
    xData : Vector<float> - vector of x values
    yData : Vector<float> - vector of y values

Returns: Coefficients vector of polynomial coefficients sorted as [intercept;constant;quadratic;...]

Calculates the polynomial coefficients for polynomial regression with a given point weighting.

order : int

order of the polynomial (1 = linear, 2 = quadratic, ... )

weighting : Vector<float>

Vector of weightings that define the releveance of each point for fitting.

xData : Vector<float>

vector of x values

yData : Vector<float>

vector of y values

Returns: Coefficients

vector of polynomial coefficients sorted as [intercept;constant;quadratic;...]

Example

 
   // e.g. days since a certain event
   let xData = vector [|1.;2.;3.;4.;5.;6.|]
   // e.g. temperature measured at noon of the days specified in xData 
   let yData = vector [|4.;7.;9.;8.;7.;9.;|]
   
   // Estimate the three coefficients of a quadratic polynomial.
   let coefficients = 
       LinearRegression.OLS.Polynomial.fit 2 xData yData

getDerivative coef level x

Full Usage: getDerivative coef level x

Parameters:
    coef : Coefficients - vector of polynomial coefficients (e.g. determined by Polynomial.coefficients), sorted as [intercept;constant;quadratic;...]
    level : int - depth of derivative: 1 = slope, 2 = curvature, ...
    x : float - x value of which the corresponding y value should be predicted

Returns: float predicted derivative with given polynomial coefficients at X=x

calculates derivative values at X=x with given polynomial coefficients. Level 1 = fst derivative; Level2 = snd derivative ...

coef : Coefficients

vector of polynomial coefficients (e.g. determined by Polynomial.coefficients), sorted as [intercept;constant;quadratic;...]

level : int

depth of derivative: 1 = slope, 2 = curvature, ...

x : float

x value of which the corresponding y value should be predicted

Returns: float

predicted derivative with given polynomial coefficients at X=x

Example

 
   // e.g. days since a certain event
   let xData = vector [|1.;2.;3.;4.;5.;6.|]
   // e.g. temperature measured at noon of the days specified in xData 
   let yData = vector [|4.;7.;9.;8.;7.;9.;|]
   
   // Estimate the polynomial coefficients
   let coefficients = 
       LinearRegression.OLS.Polynomial.fit xData yData 
   
   // Predict the curvature of the regression function at midnight between day 1 and 2. 
   LinearRegression.OLS.Polynomial.getDerivative coefficients 2 1.5

predict coef x

Full Usage: predict coef x

Parameters:
    coef : Coefficients - vector of polynomial coefficients (e.g. determined by Polynomial.coefficients), sorted as [intercept;constant;quadratic;...]
    x : float - x value of which the corresponding y value should be predicted

Returns: float predicted y value with given polynomial coefficients at X=x

Takes polynomial coefficients and x value to predict the corresponding y value.

If all coefficients are nonzero, the order is equal to the length of the coefficient vector!

coef : Coefficients

vector of polynomial coefficients (e.g. determined by Polynomial.coefficients), sorted as [intercept;constant;quadratic;...]

x : float

x value of which the corresponding y value should be predicted

Returns: float

predicted y value with given polynomial coefficients at X=x

Example

 
   // e.g. days since a certain event
   let xData = vector [|1.;2.;3.;4.;5.;6.|]
   // e.g. temperature measured at noon of the days specified in xData 
   let yData = vector [|4.;7.;9.;8.;7.;9.;|]
   
   // Define the polynomial coefficients.
   let coefficients = 
       LinearRegression.OLS.Polynomial.fit xData yData 
   
   // Predict the temperature value at midnight between day 1 and 2. 
   LinearRegression.OLS.Polynomial.predict coefficients 1.5