I have some data from a radioactive decay experiment that I'm trying to fit an exponential decay curve on that will take account of the uncertainties on the data, and then ideally return the data for half-life and such (time taken for the y-value to decrease by half)
The uncertainties are entered in using 'around'. Currently my code is (using a cut down data set):
dataHist5 = {{Around[16.5, 1.5],
Around[77.8, 8.8]}, {Around[34.5, 1.5],
Around[60.5, 8.0]}, {Around[52.5, 1.5],
Around[63.8, 8.0]}, {Around[106.5, 1.5],
Around[42.4, 6.5]}, {Around[124.5, 1.5],
Around[41.7, 6.5]}, {Around[142.5, 1.5],
Around[14.6, 3.8]}, {Around[160.5, 1.5],
Around[33.9, 5.8]}, {Around[178.5, 1.5],
Around[29.4, 5.4]}, {Around[196.5, 1.5],
Around[33.5, 5.8]}, {Around[214.5, 1.5],
Around[30.9, 5.6]}, {Around[232.5, 1.5],
Around[31.1, 5.8]}, {Around[250.5, 1.5],
Around[21.5, 4.6]}, {Around[268.5, 1.5],
Around[4.3, 2.1]}, {Around[286.5, 1.5],
Around[6.4, 2.5]}, {Around[322.5, 1.5],
Around[7.5, 2.7]}, {Around[340.5, 1.5],
Around[4.5, 2.1]}, {Around[358.5, 1.5],
Around[11., 3.3]}, {Around[376.5, 1.5],
Around[14.0, 3.7]}, {Around[394.5, 1.5],
Around[14.0, 3.7]}, {Around[466.5, 1.5],
Around[0.6, 0.7]}, {Around[502.5, 1.5],
Around[2.2, 1.5]}, {Around[520.5, 1.5],
Around[9.4, 3.1]}, {Around[538.5, 1.5],
Around[4.1, 2.0]}, {Around[646.5, 1.5],
Around[2.2, 1.5]}, {Around[682.5, 1.5], Around[0.6, 0.7]}}
ListPlot[dataHist5, PlotTheme -> "Detailed"]
model = a Exp[-kt];
fit = FindFit[dataHist5, model, {a, k}, t]
And
FindFit::fitm: Unable to solve for the fit parameters; the design matrix is nonrectangular, non-numerical, or could not be inverted.
for the fitting. However, I think even had I got it to fit, it would just fit the points rather than the uncertainties around the points as well. Anyone know of a good way to implement this and have mathematica report the fitting back? Thanks for the help
EDIT: Trying to recreate JimB's answer to get Chi^2:
data = Transpose[{dataHist5[[All, 1, 1]], dataHist5[[All, 2, 1]]}];
ListLogPlot[data]
logData = data;
logData[[All, 2]] = Log[data[[All, 2]]]/data[[All, 1]];
nlm = NonlinearModelFit[logData, loga/t - k, {loga, k}, t];
nlm["BestFitParameters"]
(*{loga\[Rule]4.47236,k\[Rule]0.00675936}*)
Show[ListPlot[data], Plot[Exp[t nlm[t]], {t, 1, 700}]]
ListPlot[Transpose[{logData[[All, 1]], nlm["FitResiduals"]}],
PlotRange -> All]
nlm["ANOVATable"]