Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
2024.1.0 - Português


reglin

Linear regression

Syntax

[a,b,sig]=reglin(x,y)

Arguments

x, y, a, b, sig

numerical vectors or matrices.

Description

Solve the regression problem y=a*x+b in the least square sense. sig is the standard deviation of the residual. x and y are two matrices of size x(p,n) and y(q,n), where n is the number of samples.

The estimator a is a matrix of size (q,p) and b is a vector of size (q,1).

If x or y contains NaNs, use nanreglin.

Examples

// Simulation of data for a(3, 5) and b(3, 1)
x  = rand(5, 100);
aa = testmatrix("magi", 5); aa = aa(1:3, :);
bb = [9; 10; 11];
y  = aa*x +bb*ones(1, 100)+ 0.1*rand(3, 100);

// Identification
[a, b, sig] = reglin(x, y);
max(abs(aa-a))
max(abs(bb-b))

// Another example: fitting a polynomial
f = 1:100; x = [f.*f; f];
y = [2 3]*x + 10*ones(f) + 0.1*rand(f);
[a, b] = reglin(x, y)

Graphical example:

// Generating an odd function (symmetric with respect to the origin)
x = -30:30;
y = x.^3;

// Extracting the least square mean of that function and displaying
[a, b] = reglin(x, y);
plot(x, y, "red")
plot(x, a*x+b)

See also

  • nanreglin — Linear regression
  • pinv — pseudo-inversa
  • leastsq — Solves non-linear least squares problems
  • qr — QR decomposição
Report an issue
<< princomp Multivariate Correl Regress PCA show_pca >>

Copyright (c) 2022-2024 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Mon Jun 17 17:53:24 CEST 2024