Note that there are some explanatory texts on larger screens.

plurals
  1. POFitting a curve "around" data points in R
    primarykey
    data
    text
    <p>i have a data set consisting of a collection of points. the points are distributed on the plane in such a way that they can be roughly bounded by a parabola. i am trying to find a way of fitting a parabola to the boundary of the points.</p> <p>this is what i have at present:</p> <pre><code>a = 1 b = 2 c = 3 parabola &lt;- function(x) { a * x^2 + b * x + c } N = 10000 x &lt;- runif(N, -4, 3) y &lt;- runif(N, 0, 10) data &lt;- data.frame(x, y) data &lt;- subset(data, y &gt;= parabola(x)) plot(data, xlim = c(-5, 5), ylim = c(0, 10), col = "grey") fr &lt;- function(x) { PAR = x[1] * data$x^2 + x[2] * data$x + x[3] # sum((PAR - data$y)^2 + 100 * plogis(PAR - data$y, scale = 0.00001)) } par = optim(c(0, 0, 0), fr)$par a = par[1] b = par[2] c = par[3] curve(parabola, add = TRUE, lty = "dashed") </code></pre> <p>this creates a sample data set and then fits a curve to the boundary. the objective function consists of a "normal" squared error term, which fits a parabola to the data as well as a second logistic term which penalizes points which live below the parabola. the parameters (100 and 0.00001) of this second term were determined by trial and error.</p> <p>the code plots the points as well as the fitted parabola.</p> <p>now this system works... but only some of the time. sometimes it produces a fit that is completely wrong and i guess that in these instances the parameters for the logistic term are just inappropriate. run the code a few times to see what i mean.</p> <p>i am sure that there must be a more robust way of solving this problem. ideas and suggestions?</p> <p>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload