Residuals from Regress

I'm trying to get the residual error from a linear fit between two variables and the residuals I get from the regress function make no sense and don't match what I get from the data fitting gui (which looks correct). What is the difference in the procedures here and how can I programmatically get the residuals I see through the data fitting menu option?

댓글 수: 1

the cyclist
the cyclist 2011년 4월 14일
Can post the code that uses the regress function and seems suspicious to you?

댓글을 달려면 로그인하십시오.

 채택된 답변

Richard Willey
Richard Willey 2011년 4월 14일

0 개 추천

% Generate some random data
X = linspace(1,100,100)';
Y = X + randn(100,1);
% Use Curve Fitting Toolbox to generate a fit
% In your workflow, you'd create the fit in cftool and then export the
% model to MATLAB as a fit object
foo = fit(X,Y,'poly1')
% Calculate residuals
resid1 = Y - foo(X)
% Use regress to compute residuals
b = regress(Y, [ones(length(X),1) X])
Yhat = [ones(length(X),1) X]*b;
resid2 = Y - Yhat
% Check that the residuals are the same
resid1./resid2

댓글 수: 2

Jamie Johnston
Jamie Johnston 2011년 4월 14일
Thanks Richard - I was simply missing the second column for the X variable...looks to be working now.
Richard Willey
Richard Willey 2011년 4월 14일
Easy mistake to make. regress gives you really fine grained control over your design matrix. However, in turn you need to do things like add a ones vector for your constant and the like...

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by