用於一元及多元線性回歸,本質上是最小二乘法。在Matlab 2014a中,輸入help regress ,會彈出和regress的相關信息,一一整理。
調用格式:
- B = regress(Y,X)
- [B,BINT] = regress(Y,X)
- [B,BINT,R] = regress(Y,X)
- [B,BINT,R,RINT] = regress(Y,X)
- B,BINT,R,RINT,STATS] = regress(Y,X)
- [...] = regress(Y,X,ALPHA)
參數解釋:
- B:回歸系數,是個向量(“the vector B of regression coefficients in the linear model Y = X*B”)。
- BINT:回歸系數的區間估計(“a matrix BINT of 95% confidence intervals for B”)。
- R:殘差( “a vector R of residuals”)。
- RINT:置信區間(“a matrix RINT of intervals that can be used to diagnose outliers”)。
- STATS:用於檢驗回歸模型的統計量。有4個數值:判定系數R^2,F統計量觀測值,檢驗的p的值,誤差方差的估計。
- ALPHA:顯著性水平(缺少時為默認值0.05)。
regress函數例程
目標函數:y=Ax1^2+Bx1^2+Cx1+Dx2+Ex1*x2+F (這是一個二次函數,兩個變量,大寫的字母是常數)
- %導入數據
- y=[7613.51 7850.91 8381.86 9142.81 10813.6 8631.43 8124.94 9429.79 10230.81
- ... 10163.61 9737.56 8561.06 7781.82 7110.97]';
- x1=[7666 7704 8148 8571 8679 7704 6471 5870 5289 3815 3335 2927 2758 2591]';
- x2=[16.22 16.85 17.93 17.28 17.23 17 19 18.22 16.3 13.37 11.62 10.36 9.83 9.25]';
- X=[ones(size(y)), x1.^2,x2.^2, x1, x2, x1.*x2];
- %開始分析
- [b,bint,r,rint,stats] = regress(y,X);