I have the following data:
data = {{15, 1}, {18, 1470.7`/1476.9333333333334`}, {21, 1326.2333333333333`/1476.9333333333334`}, {24, 316.8`/1476.9333333333334`}};
Based on the data and knowledge of the underlying dynamics, Hill function, i.e., $f (x) = a^n / (a^n + x^n)$, can be a good candidate for fitting; and, $a$ and $n$ to be determined from the data. So, we have:
nlm = NonlinearModelFit[data, a^n/(a^n + x^n), {a, n}, x]
which gives error:
The function value {-1475.9327805109833`+0.0002583292146366989`I,-1469.699783452097`+0.0001011495715564914`I,-1325.2332352782923`+0.00004579492074835434` I,-44.140176596973895`+0.00002305423442489074` I} is not a list of \real numbers withdimensions {4} at {a,n} = {-3.5525189040549865`,-5.13906385562555`}.
How can this be fixed?
EDIT
Now, by adding the constraint $a > 0$ and $n > 0$, the error is fixed and Mathematica returns an answer:
nlm = NonlinearModelFit[data, {a^n/(a^n + x^n), a > 0, n > 0}, {a, n}, x]
***2.17245*10^17/(2.17245*10^17 + x^6.18796)***
But, it doesn't seem it fits the data:
Show[ListPlot[data], Plot[nlm[x], {x, 15, 24}], Frame -> True]
{a^n/(a^n + x^n), a > 0, n > 0}
; please have a look at the documentation. $\endgroup$c a^n/(a^n + x^n)
so there are 3 parameters with just 4 data points. That suggests overfitting and fudging to me. Some tempering of the feeling of a good fit can be achieved by using theSinglePredictionBands
option. $\endgroup$