what is an accurate function for linear regression?
2 views (last 30 days)
Show older comments
Abdulaziz Abutunis on 7 Oct 2016
can anyone tell me an accurate function for linear regression (fitting a line to data). I am also interested in the slop, interception and R-square of the fitted line. I am only familiar with polifit
dpb on 7 Oct 2016
Edited: dpb on 8 Oct 2016
Which Toolboxen do you have? There's fit in the Curve Fitting TB and LinearModel.fit in the Statistics Toolbox. polyfit is certainly just as accurate; for such simple fitting and wants, the coefficients are returned directly and Rsq is easily computed from the definition as 1-SSE/SST
>> x=1:10; x=x(:); y=randn(size(x)); % sample data
>> b=polyfit(x,y,1) % fit....
>> yhat=polyval(b,x); % evaluate
>> hold all
>> dot(y-mn,y-mn) % definition for SST, total sum squares
>> SST=var(y)*(length(y)-1) % Use builtin VAR function
More Answers (0)
Find more on Linear and Nonlinear Regression in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!