Linear fit in a log-log plot

I have two waves, 10 log (S) and log(f). When I plot them in a linear-linear scale, and linear fit them, I got a slope of -10. When I plot S vs f in a log-log plot, and fit to f(x)=(10^b)*(10^a), I got wrong results, slope is +0.6. I understand that the two methods will have some differences, but not to this degree. What is the problem here?
typo- I mean f(x)=(x^b)*(10^a).

To clarify, I got a negative slope in the first plot, and a positive slope in the second, so clearly this is inconsistent.
Can you post the data, or provide more info?

My first guess is that you are not using a weighting wave (std dev or it's reciprocal), and this may be the source of your issue - if so then the two ends of the data set will have different effective weights in the two situations you describe.

Hope this helps,
Kurt
I don't understand yet- your data has two waves, specdB and logf. I tried making new waves 10^specdB and 10^logf, but that doesn't match your pictures. Your pictures don't really help, either- the picture loglog.png shows S values that don't match with either log(specDB) or 10^specDB. And pictures don't allow us to poke around at what you have already done.

I do have a suggestion though- when you plot data on log-log axes, you see a very distorted picture of the data. To see what Igor is really fitting, use linear axes.

And if you need further help, please post an Igor experiment file (.pxp) containing ALL the data. A copy of the file you are actually using is best, that still has your attempts to fit the data.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
I am sorry for that. I have attached an experiment file. It should be quit clear. Look at the command log to see what I have done. Basically, I started with specdB and logfreq, plot them in linear-linear plot, fit them to a line, got my slope. Then I make two new waves, spec = 10^(specdB/10) and freq=10^logfreq, then plot them in log-log scale, fit them to y=(x^b)*(10^a) and got my slope.

Ideally, both slopes should be the same (note that the slope you get from first plot should be divided first by 10, since our specdB is defined as 10 * log(...)), but they are not.
Experiment.zip (41.57 KB)
Ah, thank you!

First, you need to have a reasonable initial guess. Apparently your positive-slope fit represents a local minimum in chi-square space. To get the negative slope you expect, enter a negative slope in the initial guesses. I set the initial guess to {-15,-1} and I got the picture attached as NonlinearFitWithGoodGuesses.png.

Second, even that fit looks bad, but it is mathematically perfectly reasonable. It is the vertical log axis that makes it look bad: see NonlinearFitWithLinearAxis.png to see what the fit sees. In that view, it is perfectly reasonable. The fit has this output:
Coefficient values ± one standard deviation
a =-17.224 ± 0.0133
b =-1.7989 ± 0.00571
That's not exactly what you expected, but it's not unreasonable. I suspect the errors are not uniform in frequency- it may be that a better fit could be had by applying appropriate weighting. I also suspect that you don't really want to include the part at the very left end where the data tail off (in log(S) space, that is).

Hmmm... after I posted this, I saw that the attachments aren't in the order I expected. I have changed the text above to reflect that... And I have attached my version of your experiment file :)

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
John,

Thanks for your time and effort. I understand your point, and it does make sense. At the mean time, I will continue fitting the linear-linear scale, since this gives the result I am expecting.

BTW, something that might be relevant is a feature in Origin called "Apparent Fit". I did not try it myself since I don't have a copy of Origin, but what I have read is that it do exactly what I wanted, i.e. it will fit the curve as it "appears".
ali8 wrote:
BTW, something that might be relevant is a feature in Origin called "Apparent Fit". I did not try it myself since I don't have a copy of Origin, but what I have read is that it do exactly what I wanted, i.e. it will fit the curve as it "appears".

It's hard to know what that means. On the face of it, it sounds like magic or mind-reading. Igor's mind-reading module has never been released :)

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
[quote=ali8]http://www.originlab.com/index.aspx?go=Products/Origin/DataAnalysis/Cur…]

Are you aware, linearization of equations as a way to fit data will skew the uncertainties on the non-linear fitting coefficients? Are you aware that, linearizing data that is non-linear to fit a y = mx + b equation (because it is "easier") can make reliable comparisons to results from non-linear regression analysis essentially impossible. IOW, are you aware that doing "apparent linear scaling" of non-linear data is not scientifically rigorous ... it is just an approximation (and sometimes a really bad one at that)?

No disrespect to the wonders of Origin but, what is shown seems to me to be a way to entice an otherwise clueless, point-and-click data analyst with a glittery "different" method. I might also mutter under my breath that, this "apparent fit" method must have been programmed in along the way by an engineer who needed an answer that could be sold as being reasonable, the rigors of the method behind it be damned ... I cannot see how any self-respecting scientist worth his or her salt would even consider using it.

--> getting on soapbox
Back in the days of hand-drawn graphs and computers with processing speeds in the Hz, linearizing equations and interpreting the end results properly could be considered an art worth its own domain of respect. Today, with the power of computers in the GHz, attempts to linear equations before fitting should be considered the equivalent of making stick drawings with charcoal on cave walls.
--> stepping down from soapbox

Anyway, I know Igor can be programmed to make the same thing happen as with Origin's "apparent fit" whiz-bang. I know it could probably even be made to look "prettier" than what you see with Origin. You might appreciate on reflection why no one has bothered to do include such a fitting method in Igor Pro. Why waste time to design interfaces to fit approximations to data when the true results are more important to present well?

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
jjweimer,

Thanks for your input. I agree with you on the linearization part. It was not my intention to ask for a feature just for the sake of easiness, as it was just to point to something (possibly) relevant to the original question.
It is true that linearization is often used as an "easy" way to do a nonlinear fit, since the "hard" way requires iterative fitting and line fits don't. But in fact, linearizing makes a statement about the nature of your measurement errors. The fundamental assumption of least-squares fitting is that your measurement errors are normally distributed with zero mean and constant variance:

Y = f(x) + e
where e ~ N(0, sigma)

If that describes your situation, then you can do a least-squares fit without worry. If f(x) is nonlinear with respect to the coefficients, you must do an iterative fit to the nonlinear function. If you linearize the equation, then you are introducing a bias because log(f(x)+e) is not a simple linear relationship.

In some situations (chemical concentrations over many orders of magnitude in concentration is a common example) the errors are more like a factor:

Y = f(x)*e
where log(e) ~ N(0, sigma)

in which case linearizing using Log is appropriate, as the transformation results in an equation having errors that are normally distributed with zero mean and constant variance.

Finally, you can relax the constant variance requirement if you use weighting. To do that, you must have some prior estimate of the measurement errors and how they depend on your independent variable. And for the error estimates from your fit to be valid, the measurement errors must still be normally distributed with zero mean; weighting only takes care of the requirement of constant variance.

So, a log transformation may be appropriate under certain circumstances. But since the apparent noise in your example is asymmetric when plotted on a log Y axis (the noise extends downward a long way, and upward a short way) it is clear that the transformed data do not approximate a normal distribution. You need to use weighting to get the appropriate fit to the small magnitudes at the right end of your plot.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com