shared3p_statistics_regression.sc

shared3p_statistics_regression.sc

Module for performing regression analysis.

Functions:

constants

Constants used for specifying the method used in linear regression modeling with multiple explanatory variables.

Constants

int64

LINEAR_REGRESSION_INVERT = 0

int64

LINEAR_REGRESSION_LU_DECOMPOSITION = 1

int64

LINEAR_REGRESSION_GAUSS = 2

int64

LINEAR_REGRESSION_CONJUGATE_GRADIENT = 3

linearRegression

Fitting of linear models with multiple explanatory variables.

Detailed Description

D - shared3p protection domain

Supported types - int32 / int64 / float32 / float64

You can pass an empty matrix as the variables argument to specify a null model with just intercept.

Parameters

variables

- a matrix where each column is a sample of an explanatory variable

dependent

- sample vector of dependent variable

method

- a constant indicating which algorithm to use (LINEAR_REGRESSION_INVERT, LINEAR_REGRESSION_LU_DECOMPOSITION or LINEAR_REGRESSION_GAUSS)

returns vector {β_1, β_1, …, β_n} such that y ≈ β_1 * x_1 + β_2 * x_2 + … + β_(n-1) * x_(n-1) + β_n where y is the dependent variable and x_i are the explanatory variables.

None

Function Overloads

D float32 linearRegression(D int32[[2]] variables, D int32[[1]] dependent, int64 method)

D float64 linearRegression(D int64[[2]] variables, D int64[[1]] dependent, int64 method)

D float32 linearRegression(D float32[[2]] variables, D float32[[1]] dependent, int64 method)

D float64 linearRegression(D float64[[2]] variables, D float64[[1]] dependent, int64 method)

linearRegressionCG

Fitting of linear models with multiple explanatory variables using the conjugate gradient method.

Detailed Description

D - shared3p protection domain

Supported types - int32 / int64 / float32 / float64

You can pass an empty matrix as the variables argument to specify a null model with just intercept.

Parameters

variables

- a matrix where each column is a sample of an explanatory variable

dependent

- sample vector of dependent variable

iterations

- number of iterations to use. Empirical testing showed that 10 iterations provides better accuracy than LU decomposition and Gaussian elimination and with a high number of variables it is also faster.

returns vector {β_1, β_1, …, β_n} such that y ≈ β_1 * x_1 + β_2 * x_2 + … + β_(n-1) * x_(n-1) + β_n where y is the dependent variable and x_i are the explanatory variables.

None

Function Overloads

D float32 linearRegressionCG(D int32[[2]] variables, D int32[[1]] dependent, uint iterations)

D float64 linearRegressionCG(D int64[[2]] variables, D int64[[1]] dependent, uint iterations)

D float32 linearRegressionCG(D float32[[2]] variables, D float32[[1]] dependent, uint iterations)

D float64 linearRegressionCG(D float64[[2]] variables, D float64[[1]] dependent, uint iterations)

loess

LOESS regression with linear local regression.

Detailed Description

This implementation of LOESS only supports linear local regression with one explanatory variable. Robust regression is not supported so it might not work well in the case of outliers. Unlike most software you must specify the x-axis values where regressions are evaluated using xmin, xmax and xpoints arguments.

D - shared3p protection domain

Parameters

x

- x-axis values

y

- y-axis values

span

- fraction of points used for each local regression

xmin

- smallest x-axis value where a local model is fitted

xmax

- largest x-axis value where a local model is fitted

xpoints

- number of regressions desired

degree

- degree of local regression polynomial (1 or 2)

returns LOESSResult structure

None

Function Overloads

deprecated("the float32 version of LOESS is deprecated due to low precision. Use float64 version." )

float32 loess(D int32[[1]] x, D int32[[1]] y, float64 span, float32 xmin, float32 xmax, uint xpoints, uint degree)

loess(D int64[[1]] x, D int64[[1]] y, float64 span, float64 xmin, float64 xmax, uint xpoints, uint degree)

float32 loess(D float32[[1]] x, D float32[[1]] y, float64 span, float32 xmin, float32 xmax, uint xpoints, uint degree)

loess(D float64[[1]] x, D float64[[1]] y, float64 span, float64 xmin, float64 xmax, uint xpoints, uint degree)

simpleLinearRegression

Fitting of simple linear models.

Detailed Description

D - shared3p protection domain

Supported types - int32 / int64 / float32 / float64

Parameters

x

- explanatory variable sample

y

- dependent variable sample

filter

- filter indicating which elements of the samples are available

returns vector {α, β} where α, β are such that y ≈ α + β · x

Leaks the number of missing values

Function Overloads

D float32 simpleLinearRegression(D int32[[1]] x, D int32[[1]] y, D bool[[1]] filter)

D float64 simpleLinearRegression(D int64[[1]] x, D int64[[1]] y, D bool[[1]] filter)

D float32 simpleLinearRegression(D float32[[1]] x, D float32[[1]] y, D bool[[1]] filter)

D float64 simpleLinearRegression(D float64[[1]] x, D float64[[1]] y, D bool[[1]] filter)

weightedLinearRegression

Fitting of linear models with observation weights.

Detailed Description

D - shared3p protection domain

Supported types - float32 / float64

Parameters

variables

- independent variable samples as column vectors

dependent

- dependent variable sample

weights

- observation weight vector

returns coefficient vector. The last element is the intercept.

None

Function Overloads

D float32 weightedLinearRegression(D float32[[2]] variables, D float32[[1]] dependent, D float32[[1]] weights)

D float64 weightedLinearRegression(D float64[[2]] variables, D float64[[1]] dependent, D float64[[1]] weights)

LOESSResult

LOESS result type.

LOESSResult<domain D :shared3p , type T>

bool

good

whether the procedure finished successfully

string

error

error message if the procedure failed

T

points

x-axis points where regressions were evaluated

D T

predictions

estimated y-axis values evaluated at 'points'