Polyfit - Forcing a non-zero intercept

조회 수: 23 (최근 30일)
F P
F P 2012년 11월 5일
Hi,
Is there any way to specify the y-intercept value of polyfit? I have had a look around, and when this question is asked most people are trying to fit it to a 0 y-intercept. In my case, I need to fit least-square lines to several different groups of points whose y-intercepts are known and are non-zero.
Any help would be great,
FP

채택된 답변

Star Strider
Star Strider 2012년 11월 5일
편집: Star Strider 2012년 11월 5일
I doubt that's possible with polyfit. If you are only using a first order regression model and you have access to one of the nonlinear curve fitting routines ( nlinfit in the Statistics Toolbox or lsqcurvefit in the Optimization Toolbox), the easiest way to do this is simply to use them with an objective function similar to:
Intercept = 5;
RegModel = @(B,X) B(1).*X + Intercept;
then:
beta0 = rand;
[Beta,R,J,CovB,MSE] = nlinfit(X, Y, RegModel, beta0);
You can use whatever sort of regression model you want, of course. In this one I used a simple single-parameter model.
You can specify whatever you want in a model function, and can fit as many parameters as you want (that are mathematically appropriate).

추가 답변 (1개)

Matt J
Matt J 2012년 11월 5일
편집: Matt J 2012년 11월 5일
So you just have a slope to estimate? It should be just
slope=xData\(yData-yIntercept);

카테고리

Help CenterFile Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by