4
$\begingroup$

I have a family of probability distributions, indexed by elements in $\mathcal I =\mathbb N \times [0,1] \times [0,1]$. For each $(A,B,C) \in \mathcal I$ I know how to define the corresponding distribution $\mathcal D_{A,B,C}$.

dist := 
   ProbabilityDistribution[
   PDF[BinomialDistribution[A, y*B + (1 - y)*0.5], x]   
   PDF[BernoulliDistribution[C], y], 
   {x, 0, A, 1}, 
   {y, 0, A, 1}];

What I want is to define a probability distribution with parameters, so that fixing parameters n,p,q will yield $\mathcal D_{A,B,C}$.

I have tried the obvious, e.g.

dist[n_,p_,q_] := 
   ProbabilityDistribution[
   PDF[BinomialDistribution[n, y*p + (1 - y)*0.5], x]   
   PDF[BernoulliDistribution[q], y], 
   {x, 0, n, 1}, 
   {y, 0, n, 1}];

But I get an error message of the form SetDelayed::write: Tag ProbabilityDistribution in...is Protected.

I'm thinking there's some simple solution I don't know about (I'm new to Mathematica). I have also tried this (I don't know whether it amounts to the same thing):

dist[n_, p_, q_] := 
 ProbabilityDistribution[
 PDF[BinomialDistribution[i, y*j + (1 - y)*0.5], x] 
 PDF[BernoulliDistribution[k], y], 
 {x, 0, i, 1}, 
 {y, 0, i, 1}] /. {i -> n, j -> p, k -> q};
$\endgroup$
  • 1
    $\begingroup$ Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory Tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. $\endgroup$ – bbgodfrey Aug 15 '15 at 14:53
  • $\begingroup$ The lines you say have SetDelayed::write message, they run fine for me on MMA 10.2… $\endgroup$ – Patrick Stevens Aug 15 '15 at 15:11
  • 1
    $\begingroup$ Mathematica will evaluate dist before dist[...], so the SetDelayed error is because your dist[n_,p_,q_] := ... statement is becoming ProbabilityDistribution[...][n_,p_,q_] := ... when evaluated. Does it work if you ClearAll[dist] first? $\endgroup$ – mfvonh Aug 15 '15 at 15:12
  • 1
    $\begingroup$ Have you looked at ProductDistribution[]? $\endgroup$ – J. M. will be back soon Aug 15 '15 at 15:14
  • $\begingroup$ @mfvonh, you are correct. Rookie mistake, I suppose! $\endgroup$ – apc Aug 15 '15 at 15:22
3
$\begingroup$

I just needed to do ClearAll[dist] first, as mfvonh pointed out in the comments.

$\endgroup$
  • $\begingroup$ Do you mean ClearAll[dist] (capitalization)? $\endgroup$ – Michael E2 Aug 15 '15 at 18:51
  • $\begingroup$ Yes, thank you. $\endgroup$ – apc Aug 15 '15 at 18:53

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.