Re: Polyfit




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 message
<fkdv58$psb$1@xxxxxxxxxxxxxxxxxx>...

John's method is quick but dirty in the sense that it
will
weight 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
x, so
that the homoscedasticity assumption (constant error
variance) does not apply if it applies to the original
data (polyfit uses least squares estimation which
makes
use 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
function
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



.



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: Simple Question on R-Squared
    ... Y has a certain variance. ... You want much of the variance to be due to the linear ... Var(a + beta × X) ... In the regression, you estimate beta with b, and Varand Varby Sxx ...
    (sci.stat.edu)
  • Re: interaction terms in regression model
    ... approach to regression than that in some other disciplines. ... centering constants you use (I'm assuming a two-variable model here... ... two linear and one interaction between those) the "significance" of the ... The "failure to center" ...
    (sci.stat.edu)
  • Re: Regression analysis -- how-to?
    ... > were it not for the fact that, the last time I asked an algorithm ... Do you want to learn about regression? ... > (linear, quadratic, logarithmic, exponential, power and inverse) and at ... > least two types of linear correlation coefficient (rank and product ...
    (comp.lang.pascal.delphi.misc)

Loading