# Finding better curved line of best fit

I have a set of hand generated data that follows somewhat closely to an exponential curve:

I can come up with an exponential equation to the line that gives the values on the 3rd row, and Someone else here helped me come up with the 4th row which is an even better estimate. What could I do to improve the accuracy of this curve? Specifically because I'm losing a ton of profit at quantity 24 and charging too much at 36-144

Equation 1: $P(Q)=7.527(Q)^{-.361}$

Equation 2: $P(Q)=\frac{1+0.02481\;(\log_{10}(Q))^2}{0.03156+0.20417\;(\log_{10}(Q))^2}$

• Do you have some requirements for the general shape of the curve? If not, you could use interpolation to get a $9$-th degree polynomial which would match up at all of the points you give, but it probably wouldn't be so good at estimating whatever you are trying to estimate – Peter Woolfitt Jan 29 '15 at 1:49
• All I know about that is the limited info I could understand from googling it just now... But if it helps, I'm just trying to estimate the curve so I can get prices between those quantity brackets. (more or less than my endpoints is irrelevant) Say someone chooses a quantity of 27, I could get a value per quantity between my points 24 and 36 along that same curve. It doesn't have to hit my points exactly, but i can't be off on any by more than 5ish cents. – Justin Tennant Jan 29 '15 at 8:26
• Beware the dangers of high order polynomial fits: Polynomial best fit line for very large values – dantopa Mar 15 '17 at 22:59

We differ on the coefficients for the two functional forms you presented.

The $m=9$ data points are $$\begin{array}{rr} q & p \\\hline 12 & 382 \\ 24 & 300 \\ 36 & 172 \\ 72 & 129 \\ 144 & 106 \\ 288 & 92 \\ 544 & 77 \\ 1000 & 61 \\ 3000 & 52 \end{array}$$

First function

The trial function is $$p(q) = a q^{b}.$$ The least squares solution is $$\left[ \begin{array}{l} a \\ b \end{array} \right]_{LS} = \left\{ \left( a , b \right) \in\mathbb{R}^{2} \colon r^{2} = \sum_{k=1}^{m} \left( p_{k} - a q_{k}^b \right)^{2} \text{ is minimized} \right\}$$ The minimum value of $r^{2}(a,b) = 5668$ is achieved at $$\left[ \begin{array}{l} a \\ b \end{array} \right]_{LS} = \left[ \begin{array}{c} 1256.48 \\ -0.487344 \end{array} \right]$$ A plot of $r^{2}(a,b)$ marking the solution is shown below.

The next plot shows the data points in black and the predictions in red. Note the scales are logarithmic.

The table below has columns which display the quantity, the input price, the predicted price, and the difference expressed a unit price. For example, for quantity $q=12$ $$\frac{382-374.303}{12} = 0.641,$$ less the a cent.

$$\begin{array}{rrrrrr} q & p & s & unit\\\hline 12 & 382 & 374.303 & 0.641 \\ 24 & 300 & 267.005 & 1.375 \\ 36 & 172 & 219.13 & -1.309 \\ 72 & 129 & 156.314 & -0.380 \\ 144 & 106 & 111.504 & -0.038 \\ 288 & 92 & 79.5401 & 0.0433 \\ 544 & 77 & 58.3416 & 0.0343 \\ 1000 & 61 & 43.3635 & 0.0176 \\ 3000 & 52 & 25.3865 & 0.009 \\ \end{array}$$

Second function

The trial function is now $$p(q) = \frac{a + b \log^{2} q} {\alpha + \beta \log^{2} q}.$$ The least squares solution is $$\left[ \begin{array}{l} a \\ b \\ \alpha \\ \beta \end{array} \right]_{LS} = \left\{ \left( a , b, \alpha, \beta \right) \in\mathbb{R}^{r} \colon r^{2} = \sum_{k=1}^{m} \left( p_{k} - \frac{a + b \log^{2} q_{k}} {\alpha + \beta \log^{2} q_{k}} \right)^{2} \text{ is minimized} \right\}$$ The minimum value of $r^{2}(a,b, \alpha, \beta) = 3702$ is achieved at $$\left[ \begin{array}{l} a \\ b \\ \alpha \\ \beta \end{array} \right]_{LS} = \left[ \begin{array}{c} 2837.57 \\ 4.69051 \\ 0.91957 \\ 1.03876 \end{array} \right]$$

The following plot shows the data points in black and the predictions in red.

The following table below displays the quantity, the input price, the predicted price, and the difference expressed a unit price..

$$\begin{array}{rrrrrr} q & p & s & unit\\\hline 12 & 382 & 390.874 & -0.774 \\ 24 & 300 & 252.821 & 1.966 \\ 36 & 172 & 203.228 & -0.867 \\ 72 & 129 & 146.768 & -0.247 \\ 144 & 106 & 111.132 & -0.036 \\ 288 & 92 & 87.2876 & 0.016 \\ 544 & 77 & 71.7632 & 0.010 \\ 1000 & 61 & 60.6384 & 0.000 \\ 3000 & 52 & 46.4884 & 0.002 \\ \end{array}$$