I've generated some confidence intervals for a Q-Q plot in the form of a list plot. However I am having some problems filing between the region. First of all here is the code to generate the intervals:
n = 64;
X = RandomVariate[NormalDistribution[0, 1], n];
\[Mu] = Mean[X];
\[Sigma] = StandardDeviation[X];
\[Alpha] = 0.05;
k = Sqrt[Log[2/\[Alpha]]/(2 n)];
neg = SortBy[Table[{x, InverseCDF[NormalDistribution[\[Mu], \[Sigma]], 1/Length[X] Length[Select[X, # <= x &]] - k]}, {x, X}], #[[2]] &];
pos = SortBy[Table[{x, InverseCDF[NormalDistribution[\[Mu], \[Sigma]], 1/Length[X] Length[Select[X, # <= x &]] + k]}, {x, X}], #[[2]] &];
Show[
{
QuantilePlot[X, NormalDistribution[Mean[X], StandardDeviation[X]],ImageSize->Automatic->200, LabelStyle->12, PlotStyle->Red],
ListLinePlot[{neg, pos}, Filling->{{1->{2}}}, FillingStyle->Directive[{Gray,Opacity[0.1]}]]
}, PlotRange->{{-2,2 }, {-2, 2}}
]
As you can see the filling works as instructed, but it's not what I want. I'd like to fill the region of the plot area which is bounded by the confidence band. I thought I might be able to make a hack by adding an additional diagonal plot which I then hide to reference where the filling occurs. This almost works:
Show[
{
QuantilePlot[X, NormalDistribution[Mean[X], StandardDeviation[X]],ImageSize->Automatic->200, LabelStyle->12, PlotStyle->Red],
ListLinePlot[{neg, pos, Table[{x, x}, {x, -3, 3}]}, Filling->{{1->{3}}, {2->{3}}}, FillingStyle->Directive[{Gray,Opacity[0.1]}]]
}, PlotRange->{{-2,2 }, {-2, 2}}
]
This gets me closer,but I have these regions missing in the corners:
1/Length[X] Length[Select[X, # <= x &]] - k
] and1/Length[X] Length[Select[X, # <= x &]] - k]
can give values less than 0 and greater than 1, respectively. And such values don't work withInverseCDF
(which need to be between 0 and 1). A crude fix is to use something likeMin[0.999999, Max[0.000001, 1/Length[X] Length[Select[X, # <= x &]] - k]]]
andMin[0.999999, Max[0.000001, 1/Length[X] Length[Select[X, # <= x &]] + k]]]
. Zero and one can't be used because that gets you −∞ and +∞ $\endgroup$