For all the added support that Around
has gotten in recent versions of MMA it would have been nice if there was native support for plotting functions with coefficients that include errors, for example by sampling over the errors and showing "filled in" curves covering the whole area covered by the function depending on the values taken for the coefficients within the error bars.
Unfortunately something like Plot[Around[1, 0.05] x + Around[1, 0.01], {x, 0, 2}]
just doesn't render.
Can we come up with some (hopefully quite general) solution?
One naive approach expanding the equations into a list of equations sampling the mid and end points of the Around Coefficients:
aroundToMinMidMax[{v_?NumberQ,err_?NumberQ}]:={v-err,v,v+err};
expandAroundEquationsToListOfEquations[eq_]:=Module[{aux,coefSets,ii,jj},
aux=Cases[eq,Around[v_,err_]:>{v,err},Infinity];
coefSets=Tuples[aroundToMinMidMax/@aux];
Table[
ii=1;
eq/.Around[v_,err_]:>coefSets[[jj,ii++]],
{jj,1,Length[coefSets]}]
];
Which can then be plotted like this:
fillingRules[numCurves_] :=
Flatten[Table[{i -> {j}}, {i, 1, numCurves - 1}, {j, i + 1,
numCurves}]];
eq = Around[1, 0.1] x + Around[0.5, 0.02];
expanedEqList = expandAroundEquationsToListOfEquations[eq];
Length[expanedEqList]
Plot[expanedEqList, {x, 0, 1}, PlotStyle -> ColorData[97][1],
Filling -> fillingRules[9]]
LinearModelFit
, you can get the prediction bands directly without resorting toAround
. Do you have a situation where the polynomial coefficient estimators are estimated independently? $\endgroup$