Fitting data to a unknown function

Extrapolation where you have no data and no theoretically-based curve is risky business (unless you're selling fake news where it seems to have the desired effect).

Update

If one smooths the data before fitting, that is a big no-no. It induces serial correlation (which the fitted model assumes doesn't exist), causes the estimates of precision (standard errors of parameters and confidence and prediction bands) to be much smaller than they should be, and gets you less precise estimates of the parameters. It's done all of the time and one of the things that has kept me in business all of these years. So the moral is: Don't do it!

End of Update

One can, however, obtain prediction intervals conditional on the chosen model. But, again, this does not address any uncertainty with the chosen model form especially if there is no theoretically based curve form.

So at minimum one should create confidence or prediction bands based on the chosen model. That can be done with NonlinearModelFit and the starting values and recommendations of @swish:

nlm = NonlinearModelFit[aww, a + b CDF[NormalDistribution[c, d], x] +
  e CDF[NormalDistribution[f, g], x],
  {{a, 1.0431}, {b, -0.5282}, {c, 7.0730}, {d, -1.1435}, {e, -5.3846*^6},
  {f, -45.37464}, {g, -8.5473}}, x, MaxIterations -> 100000];

A plot of the fit and 95% single prediction bands follows:

bands95[x_] = nlm["SinglePredictionBands"];
Show[Plot[{nlm[x], bands95[x]}, {x, Min[aww[[All, 1]]], 15}], ListPlot[aww]]

Prediction bands

Further one should always look at the residuals. Here is the histogram of the residuals:

Histogram[nlm["FitResiduals"], Frame -> True, FrameLabel -> {"Residual", "Count"}]

Histogram of residuals

And a plot of the residuals vs the predicted values can suggest where there is a consistent lack of fit:

ListPlot[Transpose[{nlm["PredictedResponse"], nlm["FitResiduals"]}],
 Frame -> True, FrameLabel -> {"Predicted response", "Residual"}]

Residuals vs predicted


data = {{0, 0.201519}, {0.693147, 0.339104}, {1.09861, 
    0.390401}, {1.38629, 0.410394}, {1.60944, 0.412307}, {1.79176, 
    0.417754}, {1.94591, 0.435408}, {2.07944, 0.444448}, {2.19722, 
    0.44524}, {2.30259, 0.442406}, {2.3979, 0.447151}, {2.48491, 
    0.437103}, {2.56495, 0.459182}, {2.63906, 0.46491}, {2.70805, 
    0.471748}, {2.8029, 0.468653}, {2.89037, 0.467473}, {2.94444, 
    0.469316}, {3.02013, 0.473278}, {3.11327, 0.47169}, {3.19846, 
    0.474257}, {3.27697, 0.464787}, {3.3669, 0.47889}, {3.46549, 
    0.49119}, {3.54085, 0.483291}, {3.58352, 0.481487}, {3.69704, 
    0.482514}, {3.77617, 0.479843}, {3.87106, 0.482569}, {3.94135, 
    0.485608}, {4.00722, 0.493137}, {4.1106, 0.5}, {4.17863, 
    0.498063}, {4.27102, 0.501595}, {4.35004, 0.501828}, {4.4347, 
    0.506954}, {4.5269, 0.508308}, {4.61155, 0.509924}, {4.68992, 
    0.518376}, {4.76985, 0.522628}, {4.84523, 0.523864}, {4.93102, 
    0.523511}, {5.02758, 0.533681}, {5.10417, 0.533301}, {5.18193, 
    0.5349}, {5.26333, 0.542174}, {5.36073, 0.555209}, {5.43189, 
    0.557592}, {5.51772, 0.563697}, {5.61202, 0.571544}, {5.70691, 
    0.582026}, {5.76335, 0.582014}, {5.85009, 0.5952}, {5.93492, 
    0.59866}, {6.01713, 0.610044}, {6.11193, 0.619297}, {6.17291, 
    0.628049}, {6.26708, 0.637543}, {6.34656, 0.64715}, {6.41987, 
    0.652515}, {6.51345, 0.666603}, {6.61286, 0.678222}, {6.67611, 
    0.686927}, {6.7542, 0.703593}, {6.83354, 0.718134}, {6.92997, 
    0.735695}, {7.0236, 0.757207}, {7.09035, 0.773825}, {7.16482, 
    0.788462}, {7.25558, 0.81023}, {7.36073, 0.833882}, {7.44522, 
    0.852115}, {7.52476, 0.867163}, {7.62487, 0.885581}, {7.72828, 
    0.909325}, {7.93179, 0.94279}, {8.23179, 0.97279}, {8.53179, 
    0.99279}, {8.83179, 1.01079}, {9.11788, 1.01579}, {9.11788, 
    1.01579}, {9.51788, 1.0209}};

{xmin, xmax} = MinMax[data[[All, 1]]];

order = 4;

coef = Array[a[# - 1] &, order + 1];

model = Piecewise[{
    {coef.xmax^Range[0, order], x > xmax},
    {coef.x^Range[0, order], xmin <= x <= xmax}}];

nlm = NonlinearModelFit[data, model, coef, x];

f[x_] = nlm // Normal

enter image description here

Plot[f[x], {x, xmin, 1.1 xmax},
 PlotStyle -> Thick,
 Epilog -> {Red , AbsolutePointSize[3], Point[data]}]

enter image description here

Tags:

Fitting