Name

linregr — An interactive tool for carrying out multi linear regression.

Calling Sequence

   linregr()           // start linregr with some demo data in interactive mode...
   linregr(Data[,Names]) // Start in interactive mode using the data set Data (with optional column names Names)
   [beta,stat]=linregr(Data,Names,Zdef,Ydef[,alfa]) // run in silent command line mode - returning the results as variables.
   

Parameters

Data :

matrix containing experimental variables as column vectors.

Names:

optional space separated string containing names for each column in Data. Each name must be a valid name for a Scilab variable.

Zdef:

optional space separated string defining the linear regression matrix Z

Ydef:

optional space separated string defining the dependent variable

alfa:

optional significance level (default = 0.05) for the parameter confidence interval estimate.

beta:

parameter estimates (only in command line mode).

stat:

data structure with various statistical results (only in command line mode).

stat.Z:

dependent variable matrix

stat.ZTZ:

ZTZ=Z'*Z;

stat.cov:

cov=inv(ZTZ); // covariance matrix

stat.b:

b=cov*Z'*Y; // linear regression parameters

stat.bint:

bint=cdft('T',n-p,1-alfa/2,alfa/2)*sqrt(diag(cov)); // confidence interval for b

stat.Yhat:

Yhat=Z*b; // estimated Y

stat.resid:

resid=Y-Yhat; // residuals

stat.SSr:

SSr=resid'*resid; // residual error

stat.Ybar:

Ybar=mean(Y); // average Y

stat.SSt:

SSt=(Y-Ybar)'*(Y-Ybar); // variance of the data points about mean(Yhat)

stat.SSe:

SSe=(Yhat-Ybar)'*(Yhat-Ybar); // variance of the estimates about mean(Yhat)

stat.SSxy:

SSxy=sqrt(SSr/ZTZ(1,1)); // standard error of estimates of y on x

stat.SSy:

SSy=sqrt(SSt/length(Y));

stat.R2:

R2=1-SSr/SSt; // coefficient^2 of multiple correlation of y on all x

Description

linregr is a user friendly tool for analysing data using multi linear regression.

In interactive mode a graphical user interface is presented and statistical results from regression analysis is presented in the Scilab Console window.

When run in silent command line mode the results are returned as the parameters beta and stat. In this mode no statistical information is displayed in the Scilab Console window.

See the Scilab Demonstrations section for some linear regression test problems from the NIST StRG Dataset Archives.

Examples

X=[0:.1:2*%pi]'; Y=[X+rand(X)+X.^2+10*sin(X)];
[b,stat]=linregr([Y X],'y x','x x.^2 sin(x)','y')  // solve problem in command line mode

// Example from http://en.wikipedia.org/wiki/Simple_linear_regression
Height=[1.47, 1.50, 1.52, 1.55, 1.57, 1.60, 1.63, 1.65, 1.68, 1.70, 1.73, 1.75, 1.78, 1.80, 1.83]';
Weight=[52.21, 53.12, 54.48, 55.84, 57.20, 58.57, 59.93, 61.29, 63.11, 64.47, 66.28, 68.10, 69.92, 72.19, 74.46]';
linregr([Weight Height],'Weight Height'); // Interactive mode

   

See also

nlinregr, nlinlsq

Bibliography

http://en.wikipedia.org/wiki/Regression_analysis

NIST StRD Dataset Archives - Linear regression: http://www.itl.nist.gov/div898/strd/general/dataarchive.html

Authors

T. Pettersen, top@tpett.com