views:

327

answers:

1

Hi, I have a set of data and I want to compare which line describes it the best (polynomes of different orders, exponential or logarithmic).

I use Python and Numpy and for polynomial fitting there is a function polyfit(). But I found no such functions for exponential and logarithmic fitting.

Are there any? Or how to solve it otherwise?

Thank you very much. Tomas

+3  A: 

For fitting y = A + B log x, just fit y against log x.

For fitting y = AeBx, take the logarithm of both side gives log y = log A + Bx. So just fit log y against x.

KennyTM
Thank you, that's perfect, but how do I find the base of the logarithm that suits the best?
Tomas Novotny
@Tomas: Usually the natural log, but any log works. Just remember that if you use base K, then the equation becomes y = A*K^(Bx).
KennyTM
So the quality of the fitting (for example R2) is not dependent on the base of the logarithm? Thank you once again, the answers are perfect, very useful, I will give you a point as soon as I reach enough reputation.
Tomas Novotny
@Tomas: Right. Changing the base of log just multiplies a constant to log x or log y, which doesn't affect r^2.
KennyTM
This will give greater weight to values at small y.Hence it is better to weight contributions to the chi-squared values by y_i
Rupert Nash