5
$\begingroup$

Observe:

(* create a simple sum of DUs distribution *)
dist = TransformedDistribution[
   a + b, {a \[Distributed] DiscreteUniformDistribution[{1, 6}], 
    b \[Distributed] DiscreteUniformDistribution[{1, 6}]}];

(* get the CDF of that, make my own PD for kicks *)
cdf = CDF[dist, x];
myPD = ProbabilityDistribution[{"CDF", cdf}, {x, 2, 12, 1}];

(* verify - mine and intrinsic are equivalent *)
PDF[myPD, Range[2, 12]] == PDF[dist, Range[2, 12]]
CDF[myPD][Range[2, 12]] == CDF[dist][Range[2, 12]]

(* poop out some RV based on intrinsic *)
rv = RandomVariate[dist, 360];

(* do a fit test on intrinsic, then mine *)
DistributionFitTest[rv, dist, "PearsonChiSquare"]
DistributionFitTest[rv, myPD, "PearsonChiSquare"]

(*

True

True

Indeterminate

0.476108

*)

Any ideas why Indeterminate results? I do note that doing

PDF[dist, {6, 7}]
PDF[myPD, {6, 7}]

gives correct results, but doing

CDF[dist, {6, 7}]
CDF[myPD, {6, 7}]

gives proper results for myPD, but a steaming mess for dist...

On MMA 9.01/Windows, btw.

$\endgroup$
  • 2
    $\begingroup$ The CDF is required for the chi square test in order to build bins. If CDF doesn't compute DFT will fail. As for why the CDF fails I'm not sure. $\endgroup$ – Andy Ross Jun 16 '15 at 17:41
  • $\begingroup$ @AndyRoss: Thanks Andy - I'm thinking bug tag might be appropriate? $\endgroup$ – ciao Jun 16 '15 at 22:30
6
$\begingroup$

Apparently in version 9 listability of the CDF for TransformedDistribution, at least in this particular case, was broken. As of version 10 this is no longer the case.

However, there does appear to be a bug here. Named tests like PearsonChiSquareTest actually call DistributionFitTest under the hood so I will use the former to help point to the problem.

The HypothesisTestData object has some developer properties that illuminate that the problem occurs in the binning of the data.

htd = PearsonChiSquareTest[rv, dist, "HypothesisTestData"];
htd["CompleteTestStatistic"]

(* {{{360., {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    0, 0, 0, 0, 0}}, "PearsonChiSquare"}} *)

The second argument contains the counts of data in the various bins that the test has automatically computed. Note that they are all empty.

However, with your user defined distribution the bins get filled up with data.

htd = PearsonChiSquareTest[rv, myPD, "HypothesisTestData"];
htd["CompleteTestStatistic"]

(* {{{15.7633, {29, 21, 48, 50, 56, 63, 28, 40, 17, 8}}, "PearsonChiSquare"}} *)

I suspect the issue may be that Quantile cannot be computed for dist and DistributionFitTest isn't handling this well.

Quantile[dist, .5]

(* Quantile[
 TransformedDistribution[\[FormalX]1 + \[FormalX]2, {\[FormalX]1 \
\[Distributed] 
    DiscreteUniformDistribution[{1, 6}], \[FormalX]2 \[Distributed] 
    DiscreteUniformDistribution[{1, 6}]}], 0.5] *)

Quantile[myPD, .5]

(* 7 *)
| improve this answer | |
$\endgroup$
  • $\begingroup$ Neat analysis, +1 and accept, will add bug tag. $\endgroup$ – ciao Jun 16 '15 at 23:22

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.