Scilab Home page | Wiki | Bug tracker | Forge | Mailing list archives | ATOMS | File exchange
Please login or create an account
Change language to: English - Français - Português - 日本語
Справка Scilab >> Statistics > Data with Missing Values > nanreglin


Linear regression




x, y, a, b

numerical vectors or matrices.


Solve the regression problem y=a*x+b in the least square sense. 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).

Each line of y is treated as an independent problem, if x or y contain a NaN (x(i,j) = %nan or y(i,j) = %nan), then x(:,j) and y(i,j) are ignored, as if the point [x(:,j); y(i,j)] did not exist.


Graphical example #1:

// In the following example, both problems represent two straight lines:
// one goes from (0,0) to (10,10) and the other one goes from (0,20) to (10,30).
// reglin and nanreglin find the same values because all the points are aligned and the NaNs have been ignored.
x = 0:10;
y = 20:30;
[a1, b1] = reglin(x, [x ; y]);
plot(x', (a1*x+repmat(b1,1,11))', "red")

y2 = y;
y2(2:10) = %nan; // Leaving y2(1) and y2(11) unchanged.
[a2, b2] = nanreglin(x, [x ; y2])
plot(x', (a2*x+repmat(b2,1,11))', "blue")

Graphical example #2:

// Now both problems represent one straight line (reglin(x, x)) from (0,0) to (2,2),
// but while the second argument of the first problem (reglin(x, y)) represents
// a flat line (with equation y = 1), the second argument of the second problem
// (reglin(x, y2)) ignores the central point of y (set to %nan) so the flat line
// now has equation y = 0, because the two remaining points are (0,0) and (2,0).
x = 0:2;
y = [0 3 0];
[a1, b1] = reglin(x, [x ; y]);
plot(x', (a1*x+repmat(b1,1,3))', "red")

y2 = y;
y2(2) = %nan; // y2 = [0 %nan 0];
[a2, b2] = nanreglin(x, [x ; y2]);
plot(x', (a2*x+repmat(b2,1,3))', "blue")

See also

  • reglin — Linear regression
  • pinv — pseudoinverse
  • leastsq — Solves non-linear least squares problems
  • qr — QR decomposition


5.5.0 Introduction
Scilab Enterprises
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Tue Feb 14 15:13:25 CET 2017