Re: Polyfit
- From: "Phil Wallhead" <pjw5@xxxxxxxxxxxxxxx>
- Date: Sat, 5 Jan 2008 11:32:58 +0000 (UTC)
Apologies John, I wasn't aware of this use of \ and
thought you meant: beta = polyfit(x,x.\y,n).
So, for a polynomial regression:
beta = X\y
is the numerically hygeinic solution in my notation.
Phil
"John D'Errico" <woodchips@xxxxxxxxxxxxxxxx> wrote in
message <fke0vj$miq$1@xxxxxxxxxxxxxxxxxx>...
"Phil Wallhead" <pjw5@xxxxxxxxxxxxxxx> wrote in messagewill
<fkdv58$psb$1@xxxxxxxxxxxxxxxxxx>...
John's method is quick but dirty in the sense that it
x, soweight the fit preferentially towards low x values.
WRONG!!!!!!!
The method that I suggested is to use
x\y
This computes the linear regression both
accurately and more efficiently than does
the normal equations method that you
later recommend.
You are perhaps thinking of a transformation
to linearity using a log transformation in
your response, but x\y does nothing of the
sort.
This
is because you have scaled the errors in the data by
makesthat the homoscedasticity assumption (constant error
variance) does not apply if it applies to the original
data (polyfit uses least squares estimation which
functionuse the Guass-Markov assumptions).
WRONG WRONG WRONG!
x\y does nothing of the sort!
To avoid this why not
try the good-old general formula for multiple linear
regression (see e.g. Wikipedia):
beta = inv(X'*X)*X'*y
BAD!!!!!!!
This is a very POOR way to implement this
computation. Please get your mathematics
right if you are going to correct them.
Why is this bad? It uses a matrix inverse,
a less efficient way to solve the system.
It also squares the condition number of your
system, a bad thing to do for accuracy.
where X is the matrix of n data by p explanatory
values (=x for the simple slope fit), y is your data
vector, and beta is the vector of p least-squares
parameter estimates (=slope for slope fit).
Please get your numerical analysis right.
Just because you find something on
Wikipedia, does NOT mean that it is any
good.
John
.
- Prev by Date: Re: To find maximum value in a random curve
- Next by Date: Re: solving a linear system
- Previous by thread: r2007b on AMD Athlon 64 crash
- Next by thread: Surface plot of radial potentials
- Index(es):
Relevant Pages
|
Loading