# The best way to guess the needed data using Mathematica?

I have a question, which is not entirely related to Mathematica, and would appreciate any help on this matter.

I have the following dataset, which shows the growth of a bacterium in a specific medium:

data = {{0, Around[0.974286, 0.288609]}, {3, Around[0.491667, 0.165076]}, {6, Around[0.829444, 0.404031]},
{17, Around[0.2075, 0.191127]}, {19, Around[0.137692, 0.0961902]}, {22, Around[0.199412, 0.241207]},
{24, Around[0.0893333, 0.0359497]}};

ListPlot[data, AxesOrigin -> {-1, 0}, Ticks -> {{0, 3, 6, 17, 19, 22, 24}, Automatic}]


I need the data for the time points: $$t = 9$$ h, $$15$$ h, $$18$$ h, and $$21$$ h. This experiment was done years ago, and it's not possible to repeat it to obtain the values for the mentioned time points. Is there a method or approach in Mathematica's tool kit to provide some, at least naive, guesses for these values?

• Do you have a model by which you think bacteria populations grow? Like, it's exponential, or logistic, or goverened by some differential equation? Otherwise there's probably not much more to do that linear interpolation. Feb 23 at 14:25
• More details about the measurements would be helpful (although dealing with that makes your question more a appropriate for stats.stackexchange.com). For example, are the sampling efforts identical for each time period? Same number of petri dishes? Are these the same petri dishes (or whatever experimental units) surveyed over time? That would mean dealing with repeated measurement analysis which unfortunately Mathematica does not do directly.
– JimB
Feb 23 at 16:24

To perform a fit you can use NonlinearModelFit. For example,

model = A  Exp[-t/\[Tau]]
fit = NonlinearModelFit[data, model, {A, \[Tau]}, t]
bands90[x_] = fit["MeanPredictionBands", ConfidenceLevel -> .9];
fromFit = Transpose@{missing, fit /@ missing}


I think from fit and bands90 you can construct some meaningful uncertainty estimates. (You could change the confidence level for 1σ uncertainty, for example).

Then we can visualize with the interpolation from my other answer,

Show[
ListPlot[{data, filled, fromFit}, AxesOrigin -> {-1, 0}, Ticks -> {{0, 3, 6, 17, 19, 22, 24}, Automatic}],
Plot[{fit[t], bands90[t]}, {t, 0, 24}, PlotStyle -> Red, Filling -> {2 -> {1}}]
]


(The styling can be adjusted, obviously.)

• Rather than post what I have, I upvoted this since it is similar but better. Here is the code I used to get a fit in case it helps. Values and bounds were by eyeball and quite approximate. data = {{0, 1}, {3, .5}, {6, .85}, {17, .2}, {19, .15}, {22, .2}, {24, .1}}; bnds = {{.7, 1.3}, {.35, .65}, {.45, 1.2}, {0, .4}, {.03, .22}, {0, .4}, {.08, .12}}; func[a_, b_, x_] := a*Exp[-b*x] constraints = Join[{a > 0, b > 0},Table[bnds[[j, 1]] <= func[a, b, data[[j, 1]]] <= bnds[[j, 2]], {j,7}]]; ff = FindFit[data, {func[a, b, x], constraints}, {a, b}, x] Out[119]= {a -> 0.827451, b -> 0.0804594} Feb 23 at 18:16
• I now realize the data was explicitly available. Better code: vals = data /. Around[a_, b_] :> a; bnds = data[[All, 2]] /. Around[a_, b_] :> {a - b, a + b}; func[a_, b_, x_] := a*Exp[-b*x] constraints = Join[{a > 0, b > 0}, Table[bnds[[j, 1]] <= func[a, b, vals[[j, 1]]] <= bnds[[j, 2]], {j, 7}]]; ff = FindFit[vals, {func[a, b, x], constraints}, {a, b}, x] {a -> 0.832239, b -> 0.0789424} This will show the fit is sort of stretching things, at some data points. Show[{Plot[func[a, b, x] /. ff, {x, 0, 25}], ListPlot[data]} , PlotRange -> All] Feb 23 at 19:25
• @Anovice (the interpolation is cubic, not linear.) One way to understand the comparison is as a systematic uncertainty. Since there is no accessible ground truth and the governing differential equation is only an assumption, you can treat the difference between different fit models as an additional uncertainty. That the interpolation and fit agree within errors is comforting, of course. But how seriously you should take it becomes a statistics question, not a Mathematica question :) Feb 23 at 19:39
• If you want 1σ statistical posterior uncertainties you should use ConfidenceLevel -> 0.68. But you should have clear eyes about what those uncertainties mean. For example, the red band is much narrower than the known, measured, uncertainties. So the red band represents something more like "given all of these points, what do I think REALLY happened", rather than "if I had done the experiment in real conditions, I'd have measured a standard deviation of this size." Obviously the latter can't be true: there are places where you have measurements with larger uncertainties than the fit gives. Feb 24 at 10:30
• Or, maybe: "given all of these points, if I ran the experiment as many times as I could what would the average behavior be." Anyway I'd encourage you to look into the statistical methods that are standard in your field. I'm a scientist, but I'm largely uneducated about typical practices in a biology setting. Feb 24 at 10:32

Without a definite model one honest thing to do is to just interpolate. Mathematica's interpolation is order 3 by default, you can set InterpolationOrder->1 for linear interpolation.

f = Interpolation[data]

missing = {9, 15, 18, 21};
filled = Transpose[{missing, f /@ missing}];
ListPlot[{data, filled}, AxesOrigin -> {-1, 0}, Ticks -> {{0, 3, 6, 17, 19, 22, 24}, Automatic}]


gives

• Beyond this you get into real science, but you could try fitting the data to some model, getting parameters with uncertainties, and then evaluating the model at the times of interest. Feb 23 at 14:45
• If you look at the filled data it is printed as {{9, 0.8±0.9}, {15, 0.4±0.5} ...}, the ±s are the uncertainties. If you apply Fullform@filled you will see it as Around expressions. Feb 23 at 15:16
• For a fit you can use NonlinearModelFit though I'm not sure how that interacts with uncertain data. Feb 23 at 15:19