Fitting power law with loglog or exponential?
$begingroup$
I have $x$- and $y$-data, and I want a power-law fit ($y=ax^b$). I always fit $log(x)$ and $log(y)$ by $p_1x+p_2$ (Matlab poly1
), but when I fit $x$ and $y$ with $p_1x^{p_2}$, I did not get exactly the same result. Why?!
And what is the best way for doing this? First take logs then linear fit??
optimization
$endgroup$
add a comment |
$begingroup$
I have $x$- and $y$-data, and I want a power-law fit ($y=ax^b$). I always fit $log(x)$ and $log(y)$ by $p_1x+p_2$ (Matlab poly1
), but when I fit $x$ and $y$ with $p_1x^{p_2}$, I did not get exactly the same result. Why?!
And what is the best way for doing this? First take logs then linear fit??
optimization
$endgroup$
$begingroup$
You're minimizing the sum of the squared deviations of the function values and the data points for y. A deviation $u$ at large $y$ becomes after taking logarithms $log(y+u) - log(y) approx dfrac{u}{y}$. Therefore, when taking logarithms you are going to be more tolerant of deviations at large y. The best way to obtain the fit is to do the nonlinear fit directly with $y = p_1 x^{p_2}$, and only use the linear fit of $log(y)$ as a function of $log(x)$ to find a good initial guess.
$endgroup$
– Count Iblis
Dec 4 '18 at 4:28
add a comment |
$begingroup$
I have $x$- and $y$-data, and I want a power-law fit ($y=ax^b$). I always fit $log(x)$ and $log(y)$ by $p_1x+p_2$ (Matlab poly1
), but when I fit $x$ and $y$ with $p_1x^{p_2}$, I did not get exactly the same result. Why?!
And what is the best way for doing this? First take logs then linear fit??
optimization
$endgroup$
I have $x$- and $y$-data, and I want a power-law fit ($y=ax^b$). I always fit $log(x)$ and $log(y)$ by $p_1x+p_2$ (Matlab poly1
), but when I fit $x$ and $y$ with $p_1x^{p_2}$, I did not get exactly the same result. Why?!
And what is the best way for doing this? First take logs then linear fit??
optimization
optimization
edited Dec 4 '18 at 3:24
Saad
19.7k92352
19.7k92352
asked Dec 4 '18 at 3:17
mehrdadmehrdad
62
62
$begingroup$
You're minimizing the sum of the squared deviations of the function values and the data points for y. A deviation $u$ at large $y$ becomes after taking logarithms $log(y+u) - log(y) approx dfrac{u}{y}$. Therefore, when taking logarithms you are going to be more tolerant of deviations at large y. The best way to obtain the fit is to do the nonlinear fit directly with $y = p_1 x^{p_2}$, and only use the linear fit of $log(y)$ as a function of $log(x)$ to find a good initial guess.
$endgroup$
– Count Iblis
Dec 4 '18 at 4:28
add a comment |
$begingroup$
You're minimizing the sum of the squared deviations of the function values and the data points for y. A deviation $u$ at large $y$ becomes after taking logarithms $log(y+u) - log(y) approx dfrac{u}{y}$. Therefore, when taking logarithms you are going to be more tolerant of deviations at large y. The best way to obtain the fit is to do the nonlinear fit directly with $y = p_1 x^{p_2}$, and only use the linear fit of $log(y)$ as a function of $log(x)$ to find a good initial guess.
$endgroup$
– Count Iblis
Dec 4 '18 at 4:28
$begingroup$
You're minimizing the sum of the squared deviations of the function values and the data points for y. A deviation $u$ at large $y$ becomes after taking logarithms $log(y+u) - log(y) approx dfrac{u}{y}$. Therefore, when taking logarithms you are going to be more tolerant of deviations at large y. The best way to obtain the fit is to do the nonlinear fit directly with $y = p_1 x^{p_2}$, and only use the linear fit of $log(y)$ as a function of $log(x)$ to find a good initial guess.
$endgroup$
– Count Iblis
Dec 4 '18 at 4:28
$begingroup$
You're minimizing the sum of the squared deviations of the function values and the data points for y. A deviation $u$ at large $y$ becomes after taking logarithms $log(y+u) - log(y) approx dfrac{u}{y}$. Therefore, when taking logarithms you are going to be more tolerant of deviations at large y. The best way to obtain the fit is to do the nonlinear fit directly with $y = p_1 x^{p_2}$, and only use the linear fit of $log(y)$ as a function of $log(x)$ to find a good initial guess.
$endgroup$
– Count Iblis
Dec 4 '18 at 4:28
add a comment |
1 Answer
1
active
oldest
votes
$begingroup$
Almost as Count Iblis commented, when you use least-squares methods, you want to minimize
$$SSQ_1=sum_{i=1}^n left(y_i^{(calc)}-y_i^{(exp)} right)^2$$ When you linearized the model, you minimize
$$SSQ_2=sum_{i=1}^n left(logleft(y_i^{(calc)}right)-logleft(y_i^{(exp)}right) right)^2$$
$$logleft(y_i^{(calc)}right)-logleft(y_i^{(exp)}right)=logleft(frac{y_i^{(calc)} }{y_i^{(exp)} } right)=logleft(1+frac{y_i^{(calc)} -y_i^{(exp)}}{y_i^{(exp)} } right)$$ If the errors are "small", using $log(1+epsilon)sim epsilon$, you then have
$$logleft(y_i^{(calc)}right)-logleft(y_i^{(exp)}right) sim frac{y_i^{(calc)} -y_i^{(exp)}}{y_i^{(exp)} }$$ which means that
$$SSQ_2 sim sum_{i=1}^n left(frac{y_i^{(calc)} -y_i^{(exp)}}{y_i^{(exp)} } right)^2$$ which means that, using linearization and $SSQ_2$, you minimize more or less the sum of the squares of the relative errors while, using $SSQ_1$ you minimize the sum of the squares of the absolute errors.
For illustration purposes, let us consider the following data set
$$ left(
begin{array}{cc}
x & y \
1 & 15 \
2 & 30 \
3 & 52 \
4 & 80 \
5 & 125 \
6 & 200
end{array}
right)$$ and for simplicity use the model $y=e^{a+bx}$. If we take logarithms and perform the linear regression we shall get
$$log(y)=2.32851+0.504671 xtag 1$$ to which will correspond $SSQ_2=0.03665$.
Using the nonlinear regression, we shall get
$$y=exp({2.49690+0.467135 x})tag 2$$ which, as you noticed, shows different values for the parameters.
Now, let us perform the nonlinear regression using
$$SSQ_3=sum_{i=1}^n left(frac{y_i^{(calc)} -y_i^{(exp)}}{y_i^{(exp)} } right)^2$$ We shall obtain
$$y=exp({2.30824+0.507829 x})tag 3$$ Observe how close are the parameters in $(1)$ and $(3)$. Moreover, $SSQ_3=0.03676$ so close to $SSQ_2$ !
In any manner, when you face nonlinear regression prolems, you need stimates of the parameters to be tuned. Linearization (when possible) is the way to go. But, when you have the estimates, you must continue with the nonlinear regression since what is measured is $y$ and not any of its possible transforms.
$endgroup$
$begingroup$
What qualifies as a "small" error here? I'm guessing if the error is several orders of magnitude that's no longer small as log(x) != x in that domain.
$endgroup$
– tibbe
Dec 7 '18 at 15:40
$begingroup$
@tibbe. Consider an error of $10$% and $log(1.1)=0.095$. Are they similar or not for you ? Cheers.
$endgroup$
– Claude Leibovici
Dec 7 '18 at 15:52
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
});
});
}, "mathjax-editing");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "69"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
noCode: true, onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3025085%2ffitting-power-law-with-loglog-or-exponential%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Almost as Count Iblis commented, when you use least-squares methods, you want to minimize
$$SSQ_1=sum_{i=1}^n left(y_i^{(calc)}-y_i^{(exp)} right)^2$$ When you linearized the model, you minimize
$$SSQ_2=sum_{i=1}^n left(logleft(y_i^{(calc)}right)-logleft(y_i^{(exp)}right) right)^2$$
$$logleft(y_i^{(calc)}right)-logleft(y_i^{(exp)}right)=logleft(frac{y_i^{(calc)} }{y_i^{(exp)} } right)=logleft(1+frac{y_i^{(calc)} -y_i^{(exp)}}{y_i^{(exp)} } right)$$ If the errors are "small", using $log(1+epsilon)sim epsilon$, you then have
$$logleft(y_i^{(calc)}right)-logleft(y_i^{(exp)}right) sim frac{y_i^{(calc)} -y_i^{(exp)}}{y_i^{(exp)} }$$ which means that
$$SSQ_2 sim sum_{i=1}^n left(frac{y_i^{(calc)} -y_i^{(exp)}}{y_i^{(exp)} } right)^2$$ which means that, using linearization and $SSQ_2$, you minimize more or less the sum of the squares of the relative errors while, using $SSQ_1$ you minimize the sum of the squares of the absolute errors.
For illustration purposes, let us consider the following data set
$$ left(
begin{array}{cc}
x & y \
1 & 15 \
2 & 30 \
3 & 52 \
4 & 80 \
5 & 125 \
6 & 200
end{array}
right)$$ and for simplicity use the model $y=e^{a+bx}$. If we take logarithms and perform the linear regression we shall get
$$log(y)=2.32851+0.504671 xtag 1$$ to which will correspond $SSQ_2=0.03665$.
Using the nonlinear regression, we shall get
$$y=exp({2.49690+0.467135 x})tag 2$$ which, as you noticed, shows different values for the parameters.
Now, let us perform the nonlinear regression using
$$SSQ_3=sum_{i=1}^n left(frac{y_i^{(calc)} -y_i^{(exp)}}{y_i^{(exp)} } right)^2$$ We shall obtain
$$y=exp({2.30824+0.507829 x})tag 3$$ Observe how close are the parameters in $(1)$ and $(3)$. Moreover, $SSQ_3=0.03676$ so close to $SSQ_2$ !
In any manner, when you face nonlinear regression prolems, you need stimates of the parameters to be tuned. Linearization (when possible) is the way to go. But, when you have the estimates, you must continue with the nonlinear regression since what is measured is $y$ and not any of its possible transforms.
$endgroup$
$begingroup$
What qualifies as a "small" error here? I'm guessing if the error is several orders of magnitude that's no longer small as log(x) != x in that domain.
$endgroup$
– tibbe
Dec 7 '18 at 15:40
$begingroup$
@tibbe. Consider an error of $10$% and $log(1.1)=0.095$. Are they similar or not for you ? Cheers.
$endgroup$
– Claude Leibovici
Dec 7 '18 at 15:52
add a comment |
$begingroup$
Almost as Count Iblis commented, when you use least-squares methods, you want to minimize
$$SSQ_1=sum_{i=1}^n left(y_i^{(calc)}-y_i^{(exp)} right)^2$$ When you linearized the model, you minimize
$$SSQ_2=sum_{i=1}^n left(logleft(y_i^{(calc)}right)-logleft(y_i^{(exp)}right) right)^2$$
$$logleft(y_i^{(calc)}right)-logleft(y_i^{(exp)}right)=logleft(frac{y_i^{(calc)} }{y_i^{(exp)} } right)=logleft(1+frac{y_i^{(calc)} -y_i^{(exp)}}{y_i^{(exp)} } right)$$ If the errors are "small", using $log(1+epsilon)sim epsilon$, you then have
$$logleft(y_i^{(calc)}right)-logleft(y_i^{(exp)}right) sim frac{y_i^{(calc)} -y_i^{(exp)}}{y_i^{(exp)} }$$ which means that
$$SSQ_2 sim sum_{i=1}^n left(frac{y_i^{(calc)} -y_i^{(exp)}}{y_i^{(exp)} } right)^2$$ which means that, using linearization and $SSQ_2$, you minimize more or less the sum of the squares of the relative errors while, using $SSQ_1$ you minimize the sum of the squares of the absolute errors.
For illustration purposes, let us consider the following data set
$$ left(
begin{array}{cc}
x & y \
1 & 15 \
2 & 30 \
3 & 52 \
4 & 80 \
5 & 125 \
6 & 200
end{array}
right)$$ and for simplicity use the model $y=e^{a+bx}$. If we take logarithms and perform the linear regression we shall get
$$log(y)=2.32851+0.504671 xtag 1$$ to which will correspond $SSQ_2=0.03665$.
Using the nonlinear regression, we shall get
$$y=exp({2.49690+0.467135 x})tag 2$$ which, as you noticed, shows different values for the parameters.
Now, let us perform the nonlinear regression using
$$SSQ_3=sum_{i=1}^n left(frac{y_i^{(calc)} -y_i^{(exp)}}{y_i^{(exp)} } right)^2$$ We shall obtain
$$y=exp({2.30824+0.507829 x})tag 3$$ Observe how close are the parameters in $(1)$ and $(3)$. Moreover, $SSQ_3=0.03676$ so close to $SSQ_2$ !
In any manner, when you face nonlinear regression prolems, you need stimates of the parameters to be tuned. Linearization (when possible) is the way to go. But, when you have the estimates, you must continue with the nonlinear regression since what is measured is $y$ and not any of its possible transforms.
$endgroup$
$begingroup$
What qualifies as a "small" error here? I'm guessing if the error is several orders of magnitude that's no longer small as log(x) != x in that domain.
$endgroup$
– tibbe
Dec 7 '18 at 15:40
$begingroup$
@tibbe. Consider an error of $10$% and $log(1.1)=0.095$. Are they similar or not for you ? Cheers.
$endgroup$
– Claude Leibovici
Dec 7 '18 at 15:52
add a comment |
$begingroup$
Almost as Count Iblis commented, when you use least-squares methods, you want to minimize
$$SSQ_1=sum_{i=1}^n left(y_i^{(calc)}-y_i^{(exp)} right)^2$$ When you linearized the model, you minimize
$$SSQ_2=sum_{i=1}^n left(logleft(y_i^{(calc)}right)-logleft(y_i^{(exp)}right) right)^2$$
$$logleft(y_i^{(calc)}right)-logleft(y_i^{(exp)}right)=logleft(frac{y_i^{(calc)} }{y_i^{(exp)} } right)=logleft(1+frac{y_i^{(calc)} -y_i^{(exp)}}{y_i^{(exp)} } right)$$ If the errors are "small", using $log(1+epsilon)sim epsilon$, you then have
$$logleft(y_i^{(calc)}right)-logleft(y_i^{(exp)}right) sim frac{y_i^{(calc)} -y_i^{(exp)}}{y_i^{(exp)} }$$ which means that
$$SSQ_2 sim sum_{i=1}^n left(frac{y_i^{(calc)} -y_i^{(exp)}}{y_i^{(exp)} } right)^2$$ which means that, using linearization and $SSQ_2$, you minimize more or less the sum of the squares of the relative errors while, using $SSQ_1$ you minimize the sum of the squares of the absolute errors.
For illustration purposes, let us consider the following data set
$$ left(
begin{array}{cc}
x & y \
1 & 15 \
2 & 30 \
3 & 52 \
4 & 80 \
5 & 125 \
6 & 200
end{array}
right)$$ and for simplicity use the model $y=e^{a+bx}$. If we take logarithms and perform the linear regression we shall get
$$log(y)=2.32851+0.504671 xtag 1$$ to which will correspond $SSQ_2=0.03665$.
Using the nonlinear regression, we shall get
$$y=exp({2.49690+0.467135 x})tag 2$$ which, as you noticed, shows different values for the parameters.
Now, let us perform the nonlinear regression using
$$SSQ_3=sum_{i=1}^n left(frac{y_i^{(calc)} -y_i^{(exp)}}{y_i^{(exp)} } right)^2$$ We shall obtain
$$y=exp({2.30824+0.507829 x})tag 3$$ Observe how close are the parameters in $(1)$ and $(3)$. Moreover, $SSQ_3=0.03676$ so close to $SSQ_2$ !
In any manner, when you face nonlinear regression prolems, you need stimates of the parameters to be tuned. Linearization (when possible) is the way to go. But, when you have the estimates, you must continue with the nonlinear regression since what is measured is $y$ and not any of its possible transforms.
$endgroup$
Almost as Count Iblis commented, when you use least-squares methods, you want to minimize
$$SSQ_1=sum_{i=1}^n left(y_i^{(calc)}-y_i^{(exp)} right)^2$$ When you linearized the model, you minimize
$$SSQ_2=sum_{i=1}^n left(logleft(y_i^{(calc)}right)-logleft(y_i^{(exp)}right) right)^2$$
$$logleft(y_i^{(calc)}right)-logleft(y_i^{(exp)}right)=logleft(frac{y_i^{(calc)} }{y_i^{(exp)} } right)=logleft(1+frac{y_i^{(calc)} -y_i^{(exp)}}{y_i^{(exp)} } right)$$ If the errors are "small", using $log(1+epsilon)sim epsilon$, you then have
$$logleft(y_i^{(calc)}right)-logleft(y_i^{(exp)}right) sim frac{y_i^{(calc)} -y_i^{(exp)}}{y_i^{(exp)} }$$ which means that
$$SSQ_2 sim sum_{i=1}^n left(frac{y_i^{(calc)} -y_i^{(exp)}}{y_i^{(exp)} } right)^2$$ which means that, using linearization and $SSQ_2$, you minimize more or less the sum of the squares of the relative errors while, using $SSQ_1$ you minimize the sum of the squares of the absolute errors.
For illustration purposes, let us consider the following data set
$$ left(
begin{array}{cc}
x & y \
1 & 15 \
2 & 30 \
3 & 52 \
4 & 80 \
5 & 125 \
6 & 200
end{array}
right)$$ and for simplicity use the model $y=e^{a+bx}$. If we take logarithms and perform the linear regression we shall get
$$log(y)=2.32851+0.504671 xtag 1$$ to which will correspond $SSQ_2=0.03665$.
Using the nonlinear regression, we shall get
$$y=exp({2.49690+0.467135 x})tag 2$$ which, as you noticed, shows different values for the parameters.
Now, let us perform the nonlinear regression using
$$SSQ_3=sum_{i=1}^n left(frac{y_i^{(calc)} -y_i^{(exp)}}{y_i^{(exp)} } right)^2$$ We shall obtain
$$y=exp({2.30824+0.507829 x})tag 3$$ Observe how close are the parameters in $(1)$ and $(3)$. Moreover, $SSQ_3=0.03676$ so close to $SSQ_2$ !
In any manner, when you face nonlinear regression prolems, you need stimates of the parameters to be tuned. Linearization (when possible) is the way to go. But, when you have the estimates, you must continue with the nonlinear regression since what is measured is $y$ and not any of its possible transforms.
edited Dec 4 '18 at 10:33
answered Dec 4 '18 at 6:14
Claude LeiboviciClaude Leibovici
122k1157134
122k1157134
$begingroup$
What qualifies as a "small" error here? I'm guessing if the error is several orders of magnitude that's no longer small as log(x) != x in that domain.
$endgroup$
– tibbe
Dec 7 '18 at 15:40
$begingroup$
@tibbe. Consider an error of $10$% and $log(1.1)=0.095$. Are they similar or not for you ? Cheers.
$endgroup$
– Claude Leibovici
Dec 7 '18 at 15:52
add a comment |
$begingroup$
What qualifies as a "small" error here? I'm guessing if the error is several orders of magnitude that's no longer small as log(x) != x in that domain.
$endgroup$
– tibbe
Dec 7 '18 at 15:40
$begingroup$
@tibbe. Consider an error of $10$% and $log(1.1)=0.095$. Are they similar or not for you ? Cheers.
$endgroup$
– Claude Leibovici
Dec 7 '18 at 15:52
$begingroup$
What qualifies as a "small" error here? I'm guessing if the error is several orders of magnitude that's no longer small as log(x) != x in that domain.
$endgroup$
– tibbe
Dec 7 '18 at 15:40
$begingroup$
What qualifies as a "small" error here? I'm guessing if the error is several orders of magnitude that's no longer small as log(x) != x in that domain.
$endgroup$
– tibbe
Dec 7 '18 at 15:40
$begingroup$
@tibbe. Consider an error of $10$% and $log(1.1)=0.095$. Are they similar or not for you ? Cheers.
$endgroup$
– Claude Leibovici
Dec 7 '18 at 15:52
$begingroup$
@tibbe. Consider an error of $10$% and $log(1.1)=0.095$. Are they similar or not for you ? Cheers.
$endgroup$
– Claude Leibovici
Dec 7 '18 at 15:52
add a comment |
Thanks for contributing an answer to Mathematics Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3025085%2ffitting-power-law-with-loglog-or-exponential%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
$begingroup$
You're minimizing the sum of the squared deviations of the function values and the data points for y. A deviation $u$ at large $y$ becomes after taking logarithms $log(y+u) - log(y) approx dfrac{u}{y}$. Therefore, when taking logarithms you are going to be more tolerant of deviations at large y. The best way to obtain the fit is to do the nonlinear fit directly with $y = p_1 x^{p_2}$, and only use the linear fit of $log(y)$ as a function of $log(x)$ to find a good initial guess.
$endgroup$
– Count Iblis
Dec 4 '18 at 4:28