0

I have a set of data like this

When plotting the curve for the above set of data I get a graph like this

How would I go about figuring out the quartic regression formula for a curve that would best fit the plotted points?

EDIT: This site does it perfectly. I just can't figure out how it works

EDIT2: The data set is basically a frequency distribution. With the X axis showing the difference between two specific days and the y axis shows how many times that difference has occurred (ex: difference of 0 days happened 26 times, 1 day happened 14 times etc). So although it does tend towards 0 it can increase suddenly which is why I thought of a polynomial regression.

  • I think you can directly and very easily fit any polynomial to data if you're using Excel ... Otherwise, here's some theory: https://en.wikipedia.org/wiki/Polynomial_regression – Matti P. Jun 19 '19 at 11:38
  • Hi.. And no I am not using Excel. I am actually trying to do it using PHP. The data set is dynamic and can vary from situation to situation, so I am have to figure out the quartic regression formula for each data set on the fly @MattiP. – user538578964 Jun 19 '19 at 11:40
  • The Wikipedia article should give you a starting point. I have also treated a similar question here: https://math.stackexchange.com/questions/3076868/linear-regression-computation-as-y-ax/3076898#3076898. Note that the degree of the polynomial is higher in your case, and therefore the matrix that you have to invert is bigger ($5 \times 5$). But the idea is the same. – Matti P. Jun 19 '19 at 11:44
  • Thanks for the link. Will read and check @MattiP. – user538578964 Jun 19 '19 at 11:54
  • You may be much better off with splines than with polynomial regression. Search splines php. Here's one example: https://www.script-tutorials.com/smooth-curve-graphs-with-php-and-gd/ – Ethan Bolker Jun 19 '19 at 11:57
  • Hi.. What I ultimately need is a curve of best fit for the graph.. Is that possible using splines? @EthanBolker Thanks :) – user538578964 Jun 19 '19 at 12:02
  • @user538578964 Your link to the data fails. Only a part of data is visible, not the whole. – JJacquelin Jun 28 '19 at 05:23

1 Answers1

1

Suggestions in response to the comment

What I ultimately need is a curve of best fit for the graph.

"Curve of best fit" is not a well defined term. You have to decide what works best for your application.

Splines are the standard way to find a smooth curve that goes through all the points. That may be what the online app you link to does under the covers.

If you have $n$ points you can interpolate and find a polynomial of degree $n$ that goes through all the points. That will often oscillate a lot and not "look right".

You can find a polynomial of fixed low degree (suggested by the "quartic" in your title) that is the best approximation (in a precise sense) but does not necessarily go through the points. The simplest example is the (linear) regression line.

Y0ur data seem to decrease (more or less) toward $0$. No polynomial will behave like that. Perhaps a function of the form $y = ce^{-kx}$ would work. (It would not go through all the points.) Excel can find $c$ and $k$ from the data (you may have to transform it first).

Ethan Bolker
  • 95,224
  • 7
  • 108
  • 199
  • Your answer made things a bit clearer. I edited my question please take a look at the edit whenever you get the chance. Is there any "blanket formula" to figure out the formula of the quartic regression for any data set. Whereever I search I can only find the tutorials for the linear regression. I tried to apply the same principle but it didnt work out.. Thanks – user538578964 Jun 19 '19 at 13:02