How to fit data to a piecewise function?
$begingroup$
My question today regards a set of data that I wish to fit a piecewise-defined continuous function. This data set covers a domain of x-values from $0$ to $mu$ on the x-axis.
What I need is to determine a value $x_0 in {rm I!R}+$ and two functions of given forms $f_1: [0, x_0] mapsto {rm I!R}$ and $f_2: [x_0, mu] mapsto {rm I!R}$ such that $f_1$ and $f_2$ are both continuous and $f_1(x_0) = f_2(x_0)$ and $f_1 cup f_2$ is the piecewise function of this type which best fits the data.
Can I please have some information/instruction on the background theory regarding how to do this? Would linear least squares and elementary multivariable calculus be enough given that $f_1$ and $f_2$ must both be smooth on $(0, x_0)$ and $(x_0, mu)$ respectively?
In this case, I need to find $f_1 = ax^frac{3}{2}$ for some $a in {rm I!R}$ and $f_2 = bx + c$ for some $b, c in {rm I!R}$ such that $b in [-d,d]$ for some given $d in {rm I!R}$; so the goal is essentially to find a piecewise function consisting of a power law curve and a line that is nearly horizontal which best fits the data I am looking at.
I would very much appreciate help on this problem if you would be so kind.
calculus linear-algebra statistics least-squares piecewise-continuity
$endgroup$
|
show 4 more comments
$begingroup$
My question today regards a set of data that I wish to fit a piecewise-defined continuous function. This data set covers a domain of x-values from $0$ to $mu$ on the x-axis.
What I need is to determine a value $x_0 in {rm I!R}+$ and two functions of given forms $f_1: [0, x_0] mapsto {rm I!R}$ and $f_2: [x_0, mu] mapsto {rm I!R}$ such that $f_1$ and $f_2$ are both continuous and $f_1(x_0) = f_2(x_0)$ and $f_1 cup f_2$ is the piecewise function of this type which best fits the data.
Can I please have some information/instruction on the background theory regarding how to do this? Would linear least squares and elementary multivariable calculus be enough given that $f_1$ and $f_2$ must both be smooth on $(0, x_0)$ and $(x_0, mu)$ respectively?
In this case, I need to find $f_1 = ax^frac{3}{2}$ for some $a in {rm I!R}$ and $f_2 = bx + c$ for some $b, c in {rm I!R}$ such that $b in [-d,d]$ for some given $d in {rm I!R}$; so the goal is essentially to find a piecewise function consisting of a power law curve and a line that is nearly horizontal which best fits the data I am looking at.
I would very much appreciate help on this problem if you would be so kind.
calculus linear-algebra statistics least-squares piecewise-continuity
$endgroup$
1
$begingroup$
Google "piecewise regression" or "segmented regression". Also, you'll need to be able to state if $d$ is known or needs to be estimated along with the other parameters. And finally, is the variability about the two segments the same? You might want to consult with a statistician.
$endgroup$
– JimB
Jan 17 at 1:13
1
$begingroup$
Usually it requires an iterative estimation process. Rarely is there a closed-form solution. But if you're willing to "just make a hack", I hope it's not for anything important.
$endgroup$
– JimB
Jan 17 at 1:26
1
$begingroup$
Good. The usual approach is to let the data estimate all of the parameters including $d$. See en.wikipedia.org/wiki/Segmented_regression.
$endgroup$
– JimB
Jan 17 at 2:51
1
$begingroup$
As long as the two models are linear with respect to parameters, it is pretty simple and very unexpensive fixing $d=x_k$ (the $x$being sorted first) and varying $k$. When the best $k$ has been obtained, you have very good estimates adn you can easily polish all parameters (including $d$) using a simple optimizer.
$endgroup$
– Claude Leibovici
Jan 17 at 4:04
1
$begingroup$
As @ClaudeLeibovici stated your model IS linear with respect to the parameters. Not knowing that is another reason to consult a statistician.
$endgroup$
– JimB
Jan 17 at 4:13
|
show 4 more comments
$begingroup$
My question today regards a set of data that I wish to fit a piecewise-defined continuous function. This data set covers a domain of x-values from $0$ to $mu$ on the x-axis.
What I need is to determine a value $x_0 in {rm I!R}+$ and two functions of given forms $f_1: [0, x_0] mapsto {rm I!R}$ and $f_2: [x_0, mu] mapsto {rm I!R}$ such that $f_1$ and $f_2$ are both continuous and $f_1(x_0) = f_2(x_0)$ and $f_1 cup f_2$ is the piecewise function of this type which best fits the data.
Can I please have some information/instruction on the background theory regarding how to do this? Would linear least squares and elementary multivariable calculus be enough given that $f_1$ and $f_2$ must both be smooth on $(0, x_0)$ and $(x_0, mu)$ respectively?
In this case, I need to find $f_1 = ax^frac{3}{2}$ for some $a in {rm I!R}$ and $f_2 = bx + c$ for some $b, c in {rm I!R}$ such that $b in [-d,d]$ for some given $d in {rm I!R}$; so the goal is essentially to find a piecewise function consisting of a power law curve and a line that is nearly horizontal which best fits the data I am looking at.
I would very much appreciate help on this problem if you would be so kind.
calculus linear-algebra statistics least-squares piecewise-continuity
$endgroup$
My question today regards a set of data that I wish to fit a piecewise-defined continuous function. This data set covers a domain of x-values from $0$ to $mu$ on the x-axis.
What I need is to determine a value $x_0 in {rm I!R}+$ and two functions of given forms $f_1: [0, x_0] mapsto {rm I!R}$ and $f_2: [x_0, mu] mapsto {rm I!R}$ such that $f_1$ and $f_2$ are both continuous and $f_1(x_0) = f_2(x_0)$ and $f_1 cup f_2$ is the piecewise function of this type which best fits the data.
Can I please have some information/instruction on the background theory regarding how to do this? Would linear least squares and elementary multivariable calculus be enough given that $f_1$ and $f_2$ must both be smooth on $(0, x_0)$ and $(x_0, mu)$ respectively?
In this case, I need to find $f_1 = ax^frac{3}{2}$ for some $a in {rm I!R}$ and $f_2 = bx + c$ for some $b, c in {rm I!R}$ such that $b in [-d,d]$ for some given $d in {rm I!R}$; so the goal is essentially to find a piecewise function consisting of a power law curve and a line that is nearly horizontal which best fits the data I am looking at.
I would very much appreciate help on this problem if you would be so kind.
calculus linear-algebra statistics least-squares piecewise-continuity
calculus linear-algebra statistics least-squares piecewise-continuity
asked Jan 16 at 22:19
2017Algebraist2017Algebraist
505
505
1
$begingroup$
Google "piecewise regression" or "segmented regression". Also, you'll need to be able to state if $d$ is known or needs to be estimated along with the other parameters. And finally, is the variability about the two segments the same? You might want to consult with a statistician.
$endgroup$
– JimB
Jan 17 at 1:13
1
$begingroup$
Usually it requires an iterative estimation process. Rarely is there a closed-form solution. But if you're willing to "just make a hack", I hope it's not for anything important.
$endgroup$
– JimB
Jan 17 at 1:26
1
$begingroup$
Good. The usual approach is to let the data estimate all of the parameters including $d$. See en.wikipedia.org/wiki/Segmented_regression.
$endgroup$
– JimB
Jan 17 at 2:51
1
$begingroup$
As long as the two models are linear with respect to parameters, it is pretty simple and very unexpensive fixing $d=x_k$ (the $x$being sorted first) and varying $k$. When the best $k$ has been obtained, you have very good estimates adn you can easily polish all parameters (including $d$) using a simple optimizer.
$endgroup$
– Claude Leibovici
Jan 17 at 4:04
1
$begingroup$
As @ClaudeLeibovici stated your model IS linear with respect to the parameters. Not knowing that is another reason to consult a statistician.
$endgroup$
– JimB
Jan 17 at 4:13
|
show 4 more comments
1
$begingroup$
Google "piecewise regression" or "segmented regression". Also, you'll need to be able to state if $d$ is known or needs to be estimated along with the other parameters. And finally, is the variability about the two segments the same? You might want to consult with a statistician.
$endgroup$
– JimB
Jan 17 at 1:13
1
$begingroup$
Usually it requires an iterative estimation process. Rarely is there a closed-form solution. But if you're willing to "just make a hack", I hope it's not for anything important.
$endgroup$
– JimB
Jan 17 at 1:26
1
$begingroup$
Good. The usual approach is to let the data estimate all of the parameters including $d$. See en.wikipedia.org/wiki/Segmented_regression.
$endgroup$
– JimB
Jan 17 at 2:51
1
$begingroup$
As long as the two models are linear with respect to parameters, it is pretty simple and very unexpensive fixing $d=x_k$ (the $x$being sorted first) and varying $k$. When the best $k$ has been obtained, you have very good estimates adn you can easily polish all parameters (including $d$) using a simple optimizer.
$endgroup$
– Claude Leibovici
Jan 17 at 4:04
1
$begingroup$
As @ClaudeLeibovici stated your model IS linear with respect to the parameters. Not knowing that is another reason to consult a statistician.
$endgroup$
– JimB
Jan 17 at 4:13
1
1
$begingroup$
Google "piecewise regression" or "segmented regression". Also, you'll need to be able to state if $d$ is known or needs to be estimated along with the other parameters. And finally, is the variability about the two segments the same? You might want to consult with a statistician.
$endgroup$
– JimB
Jan 17 at 1:13
$begingroup$
Google "piecewise regression" or "segmented regression". Also, you'll need to be able to state if $d$ is known or needs to be estimated along with the other parameters. And finally, is the variability about the two segments the same? You might want to consult with a statistician.
$endgroup$
– JimB
Jan 17 at 1:13
1
1
$begingroup$
Usually it requires an iterative estimation process. Rarely is there a closed-form solution. But if you're willing to "just make a hack", I hope it's not for anything important.
$endgroup$
– JimB
Jan 17 at 1:26
$begingroup$
Usually it requires an iterative estimation process. Rarely is there a closed-form solution. But if you're willing to "just make a hack", I hope it's not for anything important.
$endgroup$
– JimB
Jan 17 at 1:26
1
1
$begingroup$
Good. The usual approach is to let the data estimate all of the parameters including $d$. See en.wikipedia.org/wiki/Segmented_regression.
$endgroup$
– JimB
Jan 17 at 2:51
$begingroup$
Good. The usual approach is to let the data estimate all of the parameters including $d$. See en.wikipedia.org/wiki/Segmented_regression.
$endgroup$
– JimB
Jan 17 at 2:51
1
1
$begingroup$
As long as the two models are linear with respect to parameters, it is pretty simple and very unexpensive fixing $d=x_k$ (the $x$being sorted first) and varying $k$. When the best $k$ has been obtained, you have very good estimates adn you can easily polish all parameters (including $d$) using a simple optimizer.
$endgroup$
– Claude Leibovici
Jan 17 at 4:04
$begingroup$
As long as the two models are linear with respect to parameters, it is pretty simple and very unexpensive fixing $d=x_k$ (the $x$being sorted first) and varying $k$. When the best $k$ has been obtained, you have very good estimates adn you can easily polish all parameters (including $d$) using a simple optimizer.
$endgroup$
– Claude Leibovici
Jan 17 at 4:04
1
1
$begingroup$
As @ClaudeLeibovici stated your model IS linear with respect to the parameters. Not knowing that is another reason to consult a statistician.
$endgroup$
– JimB
Jan 17 at 4:13
$begingroup$
As @ClaudeLeibovici stated your model IS linear with respect to the parameters. Not knowing that is another reason to consult a statistician.
$endgroup$
– JimB
Jan 17 at 4:13
|
show 4 more comments
1 Answer
1
active
oldest
votes
$begingroup$
I don't know what software package you might want to use but here is one of many ways to estimate the parameters using R.
First note that for the resulting function to be continuous you need
$$a x_0^{3/2} = b x_0 + c$$
So we could take $c = a x_0^{3/2} - b x_0$.
# Generate data from a segmented model and plot it
a = 2
b = 0.125
x = c(0:50)/10
x0 = 2
c = a*x0^(3/2) - b*x0
set.seed(12345)
y = (x<x0)*a*x^(3/2) + (x>=x0)*(b*x+c) + rnorm(51,0,0.5)
plot(x,y, las=1)
# Function to calculate sum of squared distance from observed value
ss = function(parameters, y) {
a = parameters[1]
b = parameters[2]
x0 = parameters[3]
c = a*x0^(3/2) - b*x0
sum((y - ((x<x0)*a*x^(3/2) + (x>=x0)*(b*x + a*x0^(3/2) - b*x0)))^2)
}
Now with some starting values (and good starting values are very valuable) find the estimates that minimize the sum of squares:
sol = optim(c(1.5,0.1,1.5), ss, y=y)
sol$par
#[1] 2.05963514 0.04598089 2.01290367
Plot the data and the fit:
$endgroup$
$begingroup$
Wonderful answer, thank you. My research group uses Matlab and I am not aware that any of us are familiar with $R$. However, I am certain that we will take your advice here into account. I will keep the question open for now in case there is any more input that could be helpful, whether from you or from other users.
$endgroup$
– 2017Algebraist
Jan 17 at 3:48
$begingroup$
upon further evaluation of your answer, I think you may have mistaken $d$ for the value I referred to as $x_0$ in the problem statement. If this is a mistake, can you please amend your answer? $x_0$ is supposed to be the knot/transition value for the piecewise function, not $d$. $d$ is just a positive number that specifies the range of acceptable slope values for the line segment
$endgroup$
– 2017Algebraist
Jan 17 at 4:04
1
$begingroup$
What I didn't include was the estimation of confidence intervals for the parameters or for the predictions. When you do use Matlab, I would argue it is essential to report on the "goodness" of the fitted function.
$endgroup$
– JimB
Jan 17 at 4:05
1
$begingroup$
Got it. I'll change $d$ to $x_0$.
$endgroup$
– JimB
Jan 17 at 4:06
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%2f3076366%2fhow-to-fit-data-to-a-piecewise-function%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$
I don't know what software package you might want to use but here is one of many ways to estimate the parameters using R.
First note that for the resulting function to be continuous you need
$$a x_0^{3/2} = b x_0 + c$$
So we could take $c = a x_0^{3/2} - b x_0$.
# Generate data from a segmented model and plot it
a = 2
b = 0.125
x = c(0:50)/10
x0 = 2
c = a*x0^(3/2) - b*x0
set.seed(12345)
y = (x<x0)*a*x^(3/2) + (x>=x0)*(b*x+c) + rnorm(51,0,0.5)
plot(x,y, las=1)
# Function to calculate sum of squared distance from observed value
ss = function(parameters, y) {
a = parameters[1]
b = parameters[2]
x0 = parameters[3]
c = a*x0^(3/2) - b*x0
sum((y - ((x<x0)*a*x^(3/2) + (x>=x0)*(b*x + a*x0^(3/2) - b*x0)))^2)
}
Now with some starting values (and good starting values are very valuable) find the estimates that minimize the sum of squares:
sol = optim(c(1.5,0.1,1.5), ss, y=y)
sol$par
#[1] 2.05963514 0.04598089 2.01290367
Plot the data and the fit:
$endgroup$
$begingroup$
Wonderful answer, thank you. My research group uses Matlab and I am not aware that any of us are familiar with $R$. However, I am certain that we will take your advice here into account. I will keep the question open for now in case there is any more input that could be helpful, whether from you or from other users.
$endgroup$
– 2017Algebraist
Jan 17 at 3:48
$begingroup$
upon further evaluation of your answer, I think you may have mistaken $d$ for the value I referred to as $x_0$ in the problem statement. If this is a mistake, can you please amend your answer? $x_0$ is supposed to be the knot/transition value for the piecewise function, not $d$. $d$ is just a positive number that specifies the range of acceptable slope values for the line segment
$endgroup$
– 2017Algebraist
Jan 17 at 4:04
1
$begingroup$
What I didn't include was the estimation of confidence intervals for the parameters or for the predictions. When you do use Matlab, I would argue it is essential to report on the "goodness" of the fitted function.
$endgroup$
– JimB
Jan 17 at 4:05
1
$begingroup$
Got it. I'll change $d$ to $x_0$.
$endgroup$
– JimB
Jan 17 at 4:06
add a comment |
$begingroup$
I don't know what software package you might want to use but here is one of many ways to estimate the parameters using R.
First note that for the resulting function to be continuous you need
$$a x_0^{3/2} = b x_0 + c$$
So we could take $c = a x_0^{3/2} - b x_0$.
# Generate data from a segmented model and plot it
a = 2
b = 0.125
x = c(0:50)/10
x0 = 2
c = a*x0^(3/2) - b*x0
set.seed(12345)
y = (x<x0)*a*x^(3/2) + (x>=x0)*(b*x+c) + rnorm(51,0,0.5)
plot(x,y, las=1)
# Function to calculate sum of squared distance from observed value
ss = function(parameters, y) {
a = parameters[1]
b = parameters[2]
x0 = parameters[3]
c = a*x0^(3/2) - b*x0
sum((y - ((x<x0)*a*x^(3/2) + (x>=x0)*(b*x + a*x0^(3/2) - b*x0)))^2)
}
Now with some starting values (and good starting values are very valuable) find the estimates that minimize the sum of squares:
sol = optim(c(1.5,0.1,1.5), ss, y=y)
sol$par
#[1] 2.05963514 0.04598089 2.01290367
Plot the data and the fit:
$endgroup$
$begingroup$
Wonderful answer, thank you. My research group uses Matlab and I am not aware that any of us are familiar with $R$. However, I am certain that we will take your advice here into account. I will keep the question open for now in case there is any more input that could be helpful, whether from you or from other users.
$endgroup$
– 2017Algebraist
Jan 17 at 3:48
$begingroup$
upon further evaluation of your answer, I think you may have mistaken $d$ for the value I referred to as $x_0$ in the problem statement. If this is a mistake, can you please amend your answer? $x_0$ is supposed to be the knot/transition value for the piecewise function, not $d$. $d$ is just a positive number that specifies the range of acceptable slope values for the line segment
$endgroup$
– 2017Algebraist
Jan 17 at 4:04
1
$begingroup$
What I didn't include was the estimation of confidence intervals for the parameters or for the predictions. When you do use Matlab, I would argue it is essential to report on the "goodness" of the fitted function.
$endgroup$
– JimB
Jan 17 at 4:05
1
$begingroup$
Got it. I'll change $d$ to $x_0$.
$endgroup$
– JimB
Jan 17 at 4:06
add a comment |
$begingroup$
I don't know what software package you might want to use but here is one of many ways to estimate the parameters using R.
First note that for the resulting function to be continuous you need
$$a x_0^{3/2} = b x_0 + c$$
So we could take $c = a x_0^{3/2} - b x_0$.
# Generate data from a segmented model and plot it
a = 2
b = 0.125
x = c(0:50)/10
x0 = 2
c = a*x0^(3/2) - b*x0
set.seed(12345)
y = (x<x0)*a*x^(3/2) + (x>=x0)*(b*x+c) + rnorm(51,0,0.5)
plot(x,y, las=1)
# Function to calculate sum of squared distance from observed value
ss = function(parameters, y) {
a = parameters[1]
b = parameters[2]
x0 = parameters[3]
c = a*x0^(3/2) - b*x0
sum((y - ((x<x0)*a*x^(3/2) + (x>=x0)*(b*x + a*x0^(3/2) - b*x0)))^2)
}
Now with some starting values (and good starting values are very valuable) find the estimates that minimize the sum of squares:
sol = optim(c(1.5,0.1,1.5), ss, y=y)
sol$par
#[1] 2.05963514 0.04598089 2.01290367
Plot the data and the fit:
$endgroup$
I don't know what software package you might want to use but here is one of many ways to estimate the parameters using R.
First note that for the resulting function to be continuous you need
$$a x_0^{3/2} = b x_0 + c$$
So we could take $c = a x_0^{3/2} - b x_0$.
# Generate data from a segmented model and plot it
a = 2
b = 0.125
x = c(0:50)/10
x0 = 2
c = a*x0^(3/2) - b*x0
set.seed(12345)
y = (x<x0)*a*x^(3/2) + (x>=x0)*(b*x+c) + rnorm(51,0,0.5)
plot(x,y, las=1)
# Function to calculate sum of squared distance from observed value
ss = function(parameters, y) {
a = parameters[1]
b = parameters[2]
x0 = parameters[3]
c = a*x0^(3/2) - b*x0
sum((y - ((x<x0)*a*x^(3/2) + (x>=x0)*(b*x + a*x0^(3/2) - b*x0)))^2)
}
Now with some starting values (and good starting values are very valuable) find the estimates that minimize the sum of squares:
sol = optim(c(1.5,0.1,1.5), ss, y=y)
sol$par
#[1] 2.05963514 0.04598089 2.01290367
Plot the data and the fit:
edited Jan 17 at 4:10
answered Jan 17 at 3:36
JimBJimB
55537
55537
$begingroup$
Wonderful answer, thank you. My research group uses Matlab and I am not aware that any of us are familiar with $R$. However, I am certain that we will take your advice here into account. I will keep the question open for now in case there is any more input that could be helpful, whether from you or from other users.
$endgroup$
– 2017Algebraist
Jan 17 at 3:48
$begingroup$
upon further evaluation of your answer, I think you may have mistaken $d$ for the value I referred to as $x_0$ in the problem statement. If this is a mistake, can you please amend your answer? $x_0$ is supposed to be the knot/transition value for the piecewise function, not $d$. $d$ is just a positive number that specifies the range of acceptable slope values for the line segment
$endgroup$
– 2017Algebraist
Jan 17 at 4:04
1
$begingroup$
What I didn't include was the estimation of confidence intervals for the parameters or for the predictions. When you do use Matlab, I would argue it is essential to report on the "goodness" of the fitted function.
$endgroup$
– JimB
Jan 17 at 4:05
1
$begingroup$
Got it. I'll change $d$ to $x_0$.
$endgroup$
– JimB
Jan 17 at 4:06
add a comment |
$begingroup$
Wonderful answer, thank you. My research group uses Matlab and I am not aware that any of us are familiar with $R$. However, I am certain that we will take your advice here into account. I will keep the question open for now in case there is any more input that could be helpful, whether from you or from other users.
$endgroup$
– 2017Algebraist
Jan 17 at 3:48
$begingroup$
upon further evaluation of your answer, I think you may have mistaken $d$ for the value I referred to as $x_0$ in the problem statement. If this is a mistake, can you please amend your answer? $x_0$ is supposed to be the knot/transition value for the piecewise function, not $d$. $d$ is just a positive number that specifies the range of acceptable slope values for the line segment
$endgroup$
– 2017Algebraist
Jan 17 at 4:04
1
$begingroup$
What I didn't include was the estimation of confidence intervals for the parameters or for the predictions. When you do use Matlab, I would argue it is essential to report on the "goodness" of the fitted function.
$endgroup$
– JimB
Jan 17 at 4:05
1
$begingroup$
Got it. I'll change $d$ to $x_0$.
$endgroup$
– JimB
Jan 17 at 4:06
$begingroup$
Wonderful answer, thank you. My research group uses Matlab and I am not aware that any of us are familiar with $R$. However, I am certain that we will take your advice here into account. I will keep the question open for now in case there is any more input that could be helpful, whether from you or from other users.
$endgroup$
– 2017Algebraist
Jan 17 at 3:48
$begingroup$
Wonderful answer, thank you. My research group uses Matlab and I am not aware that any of us are familiar with $R$. However, I am certain that we will take your advice here into account. I will keep the question open for now in case there is any more input that could be helpful, whether from you or from other users.
$endgroup$
– 2017Algebraist
Jan 17 at 3:48
$begingroup$
upon further evaluation of your answer, I think you may have mistaken $d$ for the value I referred to as $x_0$ in the problem statement. If this is a mistake, can you please amend your answer? $x_0$ is supposed to be the knot/transition value for the piecewise function, not $d$. $d$ is just a positive number that specifies the range of acceptable slope values for the line segment
$endgroup$
– 2017Algebraist
Jan 17 at 4:04
$begingroup$
upon further evaluation of your answer, I think you may have mistaken $d$ for the value I referred to as $x_0$ in the problem statement. If this is a mistake, can you please amend your answer? $x_0$ is supposed to be the knot/transition value for the piecewise function, not $d$. $d$ is just a positive number that specifies the range of acceptable slope values for the line segment
$endgroup$
– 2017Algebraist
Jan 17 at 4:04
1
1
$begingroup$
What I didn't include was the estimation of confidence intervals for the parameters or for the predictions. When you do use Matlab, I would argue it is essential to report on the "goodness" of the fitted function.
$endgroup$
– JimB
Jan 17 at 4:05
$begingroup$
What I didn't include was the estimation of confidence intervals for the parameters or for the predictions. When you do use Matlab, I would argue it is essential to report on the "goodness" of the fitted function.
$endgroup$
– JimB
Jan 17 at 4:05
1
1
$begingroup$
Got it. I'll change $d$ to $x_0$.
$endgroup$
– JimB
Jan 17 at 4:06
$begingroup$
Got it. I'll change $d$ to $x_0$.
$endgroup$
– JimB
Jan 17 at 4:06
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%2f3076366%2fhow-to-fit-data-to-a-piecewise-function%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
1
$begingroup$
Google "piecewise regression" or "segmented regression". Also, you'll need to be able to state if $d$ is known or needs to be estimated along with the other parameters. And finally, is the variability about the two segments the same? You might want to consult with a statistician.
$endgroup$
– JimB
Jan 17 at 1:13
1
$begingroup$
Usually it requires an iterative estimation process. Rarely is there a closed-form solution. But if you're willing to "just make a hack", I hope it's not for anything important.
$endgroup$
– JimB
Jan 17 at 1:26
1
$begingroup$
Good. The usual approach is to let the data estimate all of the parameters including $d$. See en.wikipedia.org/wiki/Segmented_regression.
$endgroup$
– JimB
Jan 17 at 2:51
1
$begingroup$
As long as the two models are linear with respect to parameters, it is pretty simple and very unexpensive fixing $d=x_k$ (the $x$being sorted first) and varying $k$. When the best $k$ has been obtained, you have very good estimates adn you can easily polish all parameters (including $d$) using a simple optimizer.
$endgroup$
– Claude Leibovici
Jan 17 at 4:04
1
$begingroup$
As @ClaudeLeibovici stated your model IS linear with respect to the parameters. Not knowing that is another reason to consult a statistician.
$endgroup$
– JimB
Jan 17 at 4:13