Fit a general logistic curve to the data in Example 28.2.1 without variable transformations.
Solution.
Once we have the data
x, y, we can set up the sum-of-squares function S according to (29.1.3). The parameters are to be represented by the components b(1), b(2), b(3) in some order (I use the order \(M, a, s\)). First, use a mindless guess for initial point, [0; 0; 1]. The orientation of data vectors x, y does not matter here since we no longer make a linear system out of them.
y = [1 1 1 5 8 10 27 44 62 93 101 110 112 115 116 117 118 120]; x = 1:numel(y); f = @(x, b) b(1)./(1 + exp(-(x-b(2))/b(3))); % the model equation opt = fminsearch(@(b) sum((y - f(x, b)).^2), [0; 0; 1]); % optimal (?) b t = linspace(min(x), max(x), 1000)'; plot(t, f(t, opt), 'b', x, y, 'r*') disp(opt)
The two middle lines describe the logic of the method: set up a model as a function of explanatory variable(s)
x and parameter(s) b, then minimize the sum of squares of the deviations y - f(x, b). Finally, the optimal (?) values of parameter b are used to plot the best-fitting curve.
The above code fails, as is often the case with multivariable optimization. We should think of a better way to choose the initial point. For example, the first parameter \(M\) is the carrying capacity, and this is clearly at least as large as 120. The second parameter is the \(x\)-coordinate of its center which looks like 10. And the third parameter is about a tenth of the horizontal span of the non-flat part, maybe 2. An initial point like
[120; 10; 2] does the job. Note that the fit is much better than what we achieved in Example 28.2.1.
