An interactive tool for carrying out multi linear regression.
linregr() // start linregr with some demo data in interactive mode... linregr(Data[,Names,ZDef,Ydef,alfa]) // Start in interactive mode using the data set Data (with optional column names Names, regression variables ZDef, Ydef and alfa.) [beta,stat]=linregr(Data,Names,Zdef,Ydef[,alfa]) // run in silent command line mode - returning the results as variables.
matrix containing experimental variables as column vectors.
optional space separated string containing names for each column in Data. Each name must be a valid name for a Scilab variable.
optional space separated string defining the linear regression matrix Z
optional space separated string defining the dependent variable
optional significance level (default = 0.05) for the parameter confidence interval estimate
parameter estimates (only in command line mode).
data structure with various statistical results (only in command line mode).
dependent variable matrix
ZTZ=Z'*Z;
cov=inv(ZTZ); // covariance matrix
b=cov*Z'*Y; // linear regression parameters
Yhat=Z*b; // estimate of Y
dependent observations
resid=Y-Yhat; // residuals
SSr=resid'*resid; // residual error
Ybar=mean(Y); // average Y
SSt=(Y-Ybar)'*(Y-Ybar); // variance of the data points Y about mean(Y)
SSe=(Yhat-Ybar)'*(Yhat-Ybar); // variance of the estimates Yhat about mean(Y)
SSxy=sqrt(SSr/(n-p)); // standard error of estimates of y on x
SSy=sqrt(SSt/length(Y));
bdev=sqrt(diag(cov))*SSxy; // Standard deviation of estimate
bdelta=cdft('T',n-p,1-alfa/2,alfa/2)*bdev; // confidence interval for b
bint=[b-bdelta, b+bdelta]; // confidence interval for b given as min and max values
R2=1-SSr/SSt; // R^2 of multiple correlation of y on all x
R2adj=1-SSr/SSt*(n-1)/(n-p-1); // R2 adjusted for the number of regression variables
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 StRD Dataset Archives.
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 | ![]() | ![]() |
http://en.wikipedia.org/wiki/Regression_analysis
NIST StRD Dataset Archives - Linear regression: http://www.itl.nist.gov/div898/strd/general/dataarchive.html