Re: Line fitting



Alan wrote:


Hi,

Let say I have two matrices A and B. The value A is between 0 and
100.

Now, I need to find the relationship between A and B. I set three
breakpoints a1, a2, and a3 such that:

When A is 0<A<a1, B = m1A + c1
When A is a1<A<a2, B = m2A + c2
When A is a2<A<a3, B = m3A + c3
When A is a3<A<100, B = m4A + c4

The four equations are obtained using curve fitting technique (e.g.
polyfit function). In Matlab, is there any way to set these
breakpoints so that the R^2 of these equations are maximized?

Thanks,

Alan


This is known as a linear least squares
spline. Polyfit is not a solution, since
the pieces must be continuous.

Estimation of the break points of the
spline is a "free knot" problem, where
those parameters are also estimated from
the data. This can be solved using a
nonlinear least squares, nonlinear on
the breaks and linear on the spline
parameters.

It can also be solved using a stepwise
regression approach, as implemented in
MARS. I've not yet seen a MARS version
fully written in Matlab though.

Regardless, the solution is not one that
maximizes the total R^2. This is not how
linear regression modeling works. It
minimizes the sums of squares of the
residuals. By a stroke of coincidence ;-),
one measure of a good regression fit is
an R^2 near 1.

John
.



Relevant Pages

  • Re: two questions from a researcher
    ... linear regression will solve it. ... Do you mean that beta is a function of unknown ... squares cubic spline for the function beta. ...
    (comp.soft-sys.matlab)
  • Re: two questions from a researcher
    ... linear regression will solve it. ... Do you mean that beta is a function of unknown ... squares cubic spline for the function beta. ...
    (comp.soft-sys.matlab)
  • Re: partial least squares
    ... show a linear regression type fit, although I am not so sure what ... algorithms Labview uses to generate the fit stats in some of its Linear ... algebra VIs (ie. Partial Least Squares, SIMPLS, or regular least ...
    (comp.lang.labview)
  • Re: Linear regression with functional heteroscedasticity
    ... The basic homoscedastic linear regression problem is as follows: ... estimate gby least squares. ...
    (sci.stat.math)
  • Re: linear fit for the same x-value
    ... 100x2 dataset that I need to linear fit (linear ... Then you are not looking for a linear regression ... Total least squares is usually used here. ...
    (comp.soft-sys.matlab)