我試圖做一個迴歸分析,找出了資本資產定價模型的斜率和截距(CAPM)公式:如何在MatLab中運行迴歸來找出斜率和截距?
ER = B*RM + A
ER
和RM
與大小兩個已知行向量(100x1
)
我想模擬B
(斜率)和A
(截距)。兩者都應該是一個標量。
我已經在Excel中完成了,但我得到完全不同的輸出,如在MATLAB中。
在MATLAB中,我嘗試了不同的功能,但沒有結果:
B = ER\RM % I get output only B but not A(intercept).
[slope,intercept] = postreg(ER',RM') % I get vector, not a scalar.
[r,m,b] = regress(RM,ER) %I get vector, not a scalar.
謝謝, 馬特
查看matlab手冊中的[簡單線性迴歸](https://nl.mathworks.com/help/matlab/data_analysis/linear-regression.html#buva8q5)部分。 – m7913d
[如何獲得MATLAB中最小二乘迴歸直線的斜率和截距?](http://stackoverflow.com/questions/10131823/how-to-get-the-slope-and-intercept-of -a-least-squares-regression-line-in-matlab) – m7913d