Linear regression line in MATLAB scatter plot

左心房为你撑大大i 提交于 2019-12-23 09:12:05

问题


I am trying to get the residuals for the scatter plot of two variables. I could get the least squares linear regression line using lsline function of matlab. However, I want to get the residuals as well. How can I get this in matlab. For that I need to know the parameters a and b of the linear regression line

ax+b

回答1:


Use the function polyfit to obtain the regression parameters. You can then evaluate the fitted values and calculate your residuals accordingly.

Basically polyfit performs least-squares regression for a specified degree N which, in your case will be 1 for straight line regression. The regression parameters are returned by the function and you can use the other function polyval to get the fitted values from the regression parameters




回答2:


If you have the curve fitting toolbox, type cftool and press enter and the GUI will appear.

You can use this tool to find a linear polynomial fit for a given data set, as well as many other fits.



来源:https://stackoverflow.com/questions/11209974/linear-regression-line-in-matlab-scatter-plot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!