LinearModelFactory

class LinearModelFactory(*args)

Class used to create a linear model from numerical samples.

Available usages:

LinearModelFactory()

See also

LinearModel

Notes

This class is used in order to create a linear model from numerical samples. The linear regression model between the scalar variable Y and the n -dimensional one \vect{X} = (X_i)_{i \leq n} writes as follows:

\tilde{Y} = a_0 + \sum_{i=1}^n a_i X_i + \epsilon

where \epsilon is the residual, supposed to follow the standard Normal distribution.

Each coefficient a_i is evaluated from both samples Ysample and Xsample and is accompagnied by a confidence interval and a p-value (which tests if they are significantly different from 0.0).

This class enables to test the quality of the model. It provides only numerical tests. If X is scalar, a graphical validation test exists, that draws the residual couples (\epsilon_i, \epsilon_{i+1}), where the residual \epsilon_i is evaluated on the samples (Xsample, Ysample): \epsilon_i  = Ysample_i - \tilde{Y}_i with \tilde{Y}_i = a_0 + a_1 + Xsample_i. The OpenTURNS method is VisualTest_DrawLinearModelResidual.

Methods

build(*args) Build the linear model from numerical samples.
__init__(*args)
build(*args)

Build the linear model from numerical samples.

Available usages:

build(Xsample, Ysample)

build(Xsample, Ysample, level)

Parameters:

Xsample : 2-d sequence of float

Input sample, of dimension n \geq 1.

Ysample : 2-d sequence of float

Output sample, of dimension 1.

level : positive float < 1

The level value of the confidence intervals of each coefficient of the linear model, equal to 0.95 by default.

Returns:

linearModel : LinearModel

The linear model built from the samples (Xsample, Ysample): a_0 + \sum_{i=1}^n a_i X_i + \epsilon, where \epsilon is the random residual with zero mean.

See also

LinearModel

Examples

>>> import openturns as ot
>>> ot.RandomGenerator.SetSeed(0)
>>> distribution = ot.Normal()
>>> Xsample = distribution.getSample(30)
>>> func = ot.NumericalMathFunction('x', '2 * x + 1')
>>> Ysample = func(Xsample) + ot.Normal().getSample(30)
>>> LMF = ot.LinearModelFactory()
>>> linearModel = LMF.build(Xsample, Ysample)
>>> print(linearModel)
LinearModel name=Unnamed regression=[1.1802,2.0034] confidence intervals=[0.887852, 1.47256]
[1.70439, 2.3024] p-Values=[1.87486e-07,5.10531e-12]