1
$\begingroup$

In order to find the critical values for the significance of a discrete distribution, for example BinomialDistribution[20,0.6], i need a function which works on the cumulated distrubtion function CDF and the point density function PDF.

Let pBin(x) be the probability of value x and cBin(x) the cumulated probability. Now i want to know the first x where the statement cBin(x)+1-cBin(y)>0.05 is true with y being the first value for which pBin(x)>=pBin(y) is true while y>x.

I tried to work with Select and Position but none of my attempts worked.

$\endgroup$
  • $\begingroup$ Please show the work you've done so far. Click on the gold help when editing for code formatting help. $\endgroup$ – ciao Apr 5 '15 at 18:30
3
$\begingroup$
dt = RandomVariate[BinomialDistribution[20, 0.6], 100];

dist = EmpiricalDistribution[dt];
range = Range[Min@#, 1 + Max@#] &@dist["Domain"];
pairs = Select[MapIndexed[Function[{x, pos}, Join @@ {{x},
       Select[range[[First[pos] + 1 ;;]],
        PDF[dist, #] <= PDF[dist, x] && CDF[dist, x] + 1 - CDF[dist, #] >= .05 &, 1]}],
    range], Length@# > 1 &, 1]
(* {{8,16}} *)

Row[Histogram[dt, {1}, #, ImageSize -> 400, 
ChartElementFunction -> (If[pairs[[1, 1]] < {##}[[1]][[1, 2]] <= pairs[[1, 1]] + 1 || 
     pairs[[1, 2]] < {##}[[1]][[1, 2]] <= pairs[[1, 2]] + 1, 
   {Red, ChartElementDataFunction["Rectangle"][##]}, 
   ChartElementDataFunction["GradientRectangle", 
     "ColorScheme" -> "Rainbow", "GradientOrigin" -> Top][##]] &)] & /@ {"PDF", "CDF"}]

enter image description here

| improve this answer | |
$\endgroup$
  • $\begingroup$ This is a very good method if the distribution is not too asymmetric. When choosing BinomialDistribution[20,0.9] however, the critical value is already reached at 16, but because this method can't find the corresponding pos it will instead give the pair {17,20}. $\endgroup$ – kon Apr 6 '15 at 11:51
  • $\begingroup$ dt={19, 18, 18, 18, 16, 18, 19, 16, 17, 17, 18, 17, 19, 16, 19, 17, 17, \ 19, 17, 17, 19, 17, 18, 18, 19, 17, 14, 19, 20, 20, 18, 18, 18, 18, \ 18, 19, 15, 18, 18, 20, 17, 18, 19, 19, 20, 17, 19, 19, 17, 19, 17, \ 19, 17, 18, 17, 19, 18, 19, 18, 20, 18, 19, 19, 18, 19, 18, 17, 18, \ 18, 18, 17, 17, 19, 18, 18, 17, 17, 20, 18, 18, 15, 20, 18, 18, 20, \ 16, 19, 17, 20, 19, 18, 18, 18, 18, 19, 16, 20, 19, 20, 17} $\endgroup$ – kon Apr 6 '15 at 12:28
  • $\begingroup$ In the PDF Histogram the probability of 16 is 0.05 alone, and the cumulated probability is 0.08 $\endgroup$ – kon Apr 6 '15 at 12:31
  • $\begingroup$ ... Looks like you are taking First x such that (1) cBin(x) > 0.05 if ylst= {y s.t y>x && pBin(x)<pBin(y)}=={}, (2) cBin(x)+1-cBin(ylst[[1]])>0.05 otherwise. Is this correct? $\endgroup$ – kglr Apr 6 '15 at 12:48
  • $\begingroup$ well technically the probability of y=21 in the example should be 0, and the cumulated probability 1. Maybe the easiest solution is expanding the range for y. I think your solution by distinguishing the cases should give the correct result too. $\endgroup$ – kon Apr 6 '15 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.