REGRESS_LIN — Function to perform a linear regression with various statistical tests
[Coef,studCoef,u,Yest95,sig,db_test,r2,fisch]=REGRESS_LIN(X,Y,[CONSTANTNULL])
Input variables (matrix n x p)
Output variables (matrix nx1). Only one variable allowed here !!
boolean defining if the constant term is set to zero (%t) or not (%f). Default is %f
Vector ( p+1 x 1) giving the p+1 coefficient affected to each variable. Coef(1) is the constant term.
Coef/std(Coef) compared to Student T test value. studCoef(:,2) give 5perc. level values, studCoef(:,3) give 1perc. values. studCoef(:,1) should be greater than studCoef(:,2) and studCoef(:,3). Otherwise the hypothesis Coef different from 0 is not rejected.
Residuals (Y-Ycalc). Matrix n x 1.
Uncertainty bounds on calculated values at 95% confidence level (student t statistic). Matrix n x 2.
Standard deviation of the residuals. sig^2 = u'*u / (n-p-1)
Durbin Watson test to verify that residuals are not autocorrelated (matrix 2 x 5). First line of db_test gives 1perc. values, second line gives 5perc. values. db_test(:,1) is the Durban Watson statistic (d) calculated from the sample.
(:,2) => d1, if d inf. to d1 => positive autocorrelation (:,3) => d2, if d is in [d1,d2] => doubt (:,4) => 4-d2, if d is in [d2,4-d2] => no autocorrelation (:,5) => 4-d1, if d is in [4-d2,4-d1] => doubt and if d>4-d1 => negative autocorrelation
Coefficient of determination (in -1..1)
Fischer ratio statistic to check the hypothesis r2different from0. fisch(1) is the fischer ratio calculated from the sample, fisch(2) is the statistic at perc.5, fisch(3) at 1perc..
// Data X=exp(rand(50,4)); Coef1=[1,4,6,-4]'; Y=X*Coef1+rand(50,1)*3; // regression [Coef,studCoef,u,sig,db_test,r2,fisch]=REGRESS_LIN(X,Y); // Student coefficient: // 1.1295666 1.6794274 2.4121159 -> Variable 1 not useful in the correlation // 3.2627158 1.6794274 2.4121159 // 15.412961 1.6794274 2.4121159 // 22.698711 1.6794274 2.4121159 // 15.781374 1.6794274 2.4121159 // Plot plot(Y,Y-u,'.');plot([min(Y),max(Y)],[min(Y),max(Y)],'--');