In your comments you mention that the responses are means of 3 values. If the response you're really interested in is the mean of 3 values, then we're ready to go. If the response should be the individual values and you really have a repeated measures design, then you should use something other than Mathematica. The functions LinearModelFit
and NonlinearModelFit
are just fine for simple models (with "simple" meaning just one error term).
To fit $k$ just replace $1/b$ with $k$. The underlying model that NonlinearModelFit
thinks it's estimating is for the $i$-th observation
$$y_i=\frac{a}{e^{-k (t_i-t_0)}+1}+\epsilon_i$$
where $y_i$ is the response, $a$, $k$, and $t_0$ are parameters to be estimated, $t$ is the predictor variable and $\epsilon_i$ has a normal distribution with mean 0 and variance $\sigma^2$.
nlm1 = NonlinearModelFit[data, a/(1 + E^(-k (t - t0))), {{a, 1}, {t0, 50}, {k, 0.1}}, t];
nlm1["ParameterConfidenceIntervalTable"]
We see that your desired 0.30 value for $k$ is included in the 95% confidence interval.
A plot of the predicted response vs the residuals suggests that the error term is incorrectly structured in that the variability seems to increase with an increase in predicted response.
ListPlot[Transpose[{nlm1["PredictedResponse"], nlm1["FitResiduals"]}]]
You also considered taking the logs of the responses.
data2 = data;
data2[[All, 2]] = Log[data2[[All, 2]]];
nlm2 = NonlinearModelFit[data2, Log[a/(1 + E^(-k (t - t0)))], {{a, 1}, {t0, 50}, {k, 0.1}}, t];
nlm2["ParameterConfidenceIntervalTable"]
Note that your desired 0.30+ value for $k$ is not within a much tighter 95% confidence interval.
The residual plot doesn't display the increase in variability as before which suggests meeting the model assumptions better than the other model. In other words, this model provides a better fit to the data. It just doesn't provide a fit that coincides with your desires.
ListPlot[Transpose[{nlm2["PredictedResponse"], nlm2["FitResiduals"]}]]
The data should really be analyzed according to how it was collected. And if the 3 values that constitute the means are available, that's what should be used in an analysis. But while one can use Mathematica to do so, that would entail a bit of programming as opposed to using NonlinearModelFit
.
Manipulate[Show[ListPlot[Around[#[[1]], #[[2]]] & /@ Transpose[{data, sd}]], Plot[A/(1 + E^(-(t - t0)*b1)), {t, 0, 400}]], {{A, 6.26}, 4, 8}, {{t0, 197.7}, 160, 200}, {{b1, .025}, 0.02, 0.04}]
and manually varying the parameters, you can see why $0.03$ gives a worse fit. This is even more pronounced if you useListLogPlot
andLogPlot
, where the growth rate coincides with the slope of the line in the exponential phase of the growth (of course, using logarithmic plots can be a bit misleading, because the residuals are not equally scaled, but still). $\endgroup$ListPlot
withListLogPlot
, andPlot
withLogPlot
. $\endgroup$