I have the following data:
dat["Sag"] ={1.277, 1.913, 1.48, 1.472, 1.787, 1.736, 1.896, 1.715, 1.131}
I want to fit a normal Distribution to it and get the according mean prediction bands. Letter one I can only get by using NonlinearModelFit. Both things are not a problem. Only when comparing the fit results between FindDistributionParameters and NonlinearModelFit I get way different results. Here the code:
\[ScriptCapitalH] =
DistributionFitTest[dat["Sag"], NormalDistribution[\[Mu], \[Sigma]],
"HypothesisTestData"];
\[ScriptCapitalH]["FittedDistributionParameters"]
(*{\[Mu]->1.60078,\[Sigma]->0.259774}*)
pdf[rad_] = PDF[\[ScriptCapitalH]["FittedDistribution"], rad];(*getting the PDF*)
(*creating data for fitting*)
hlist = HistogramList[dat["Sag"], 7, PDF];
fDat = Table[{(hlist[[1, n + 1]] + hlist[[1, n]])/2,
hlist[[2, n]]}, {n, Length[hlist[[2, All]]]}];
(*fitting the data*)
fitFkt = NonlinearModelFit[fDat,
PDF[NormalDistribution[\[Mu], \[Sigma]], sag], {\[Mu], \[Sigma]},
sag];
fitFkt["BestFitParameters"]
(*{\[Mu] -> 1.71268, \[Sigma] -> 0.320319}->Wondering why that is different*)
(*Mean prediction bands*)
cl[0.95] = fitFkt["MeanPredictionBands", ConfidenceLevel -> 0.95][[2]];
cl[0.9] = fitFkt["MeanPredictionBands", ConfidenceLevel -> 0.9][[2]];
cl[0.5] = fitFkt["MeanPredictionBands", ConfidenceLevel -> 0.5][[2]];
(*Plotting fits*)
pdfPlot =
Plot[{pdf[sag], fitFkt[sag], cl[0.5], cl[0.9], cl[0.95]}, {sag, 0,
3}, Filling -> {2 -> {3}, 3 -> {4}, 4 -> {5}},
PlotLegends -> "Expressions",
PlotLabel ->
"Comparison of fitting result by FindDistributionParameters
(pdf(sag) ) and NonlinearModelFit (fktFit(sag))\nincluding mean
prediction bands for confidence level (0.5, 0.9, 0.95) "]
(*Median und Standardabweichung*)
med["Sag"] = Median[dat["Sag"]]
std["Sag"] = StandardDeviation[dat["Sag"]]
The blue curve and the orange curve are the fitting results for FindDistributionParameters and NonlinearModelFit, respectively. As one can see the do not match at all. Interestingly, the NonlinearModelFit µ value fits better the Median. In opposition, MiniTab gets also the fit parameter values of FindDistributionParameters.
Do I something wrong with NonlinearModelFit?
My goal is to get a better idea about the uncertainty of the fit, as only 9 samples have been used. I tried that with the mean prediction bands. however, the fit doesn't match with FindDistributionParameters.
Is there an alternative way to get the uncertainty of the fit?
Using an estimation for the uncertainty of sigma:
HoldForm[\[CapitalDelta]\[Sigma]/\[Sigma] = 1/Sqrt[
2 (N - 1)]] // TraditionalForm
1/Sqrt[2 (N - 1)] std["Sag"] + std["Sag"] /. N -> 9
In this way I would get Dsigma+sigma that includes the number of samples and would in that way account for the low number of samples in the fit result.
Letter one is what I am locking for.