필터 지우기
필터 지우기

what is an accurate function for linear regression?

조회 수: 1 (최근 30일)
Abdulaziz Abutunis
Abdulaziz Abutunis 2016년 10월 7일
편집: dpb 2016년 10월 8일
Hi All,
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
Thanks Aziz

채택된 답변

dpb
dpb 2016년 10월 7일
편집: dpb 2016년 10월 8일
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
ADDENDUM
>> x=1:10; x=x(:); y=randn(size(x)); % sample data
>> b=polyfit(x,y,1) % fit....
b =
0.2412 -0.7021
>> plot(x,y,'-*)
>> yhat=polyval(b,x); % evaluate
>> hold all
>> plot(x,yhat)
>> mn=mean(y);
>> dot(y-mn,y-mn) % definition for SST, total sum squares
ans =
28.1924
>> SST=var(y)*(length(y)-1) % Use builtin VAR function
SST =
28.1924
>> SSE=dot(y-yhat,y-yhat)
SSE =
23.3944
>> Rsq=1-SSE/SST
Rsq =
0.1702

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by