# Defining Probability Distribution with parameters

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};

• 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. – bbgodfrey Aug 15 '15 at 14:53
• The lines you say have SetDelayed::write message, they run fine for me on MMA 10.2… – Patrick Stevens Aug 15 '15 at 15:11
• 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? – mfvonh Aug 15 '15 at 15:12
• Have you looked at ProductDistribution[]? – J. M. will be back soon Aug 15 '15 at 15:14
• @mfvonh, you are correct. Rookie mistake, I suppose! – apc Aug 15 '15 at 15:22

I just needed to do ClearAll[dist] first, as mfvonh pointed out in the comments.
• Do you mean ClearAll[dist] (capitalization)? – Michael E2 Aug 15 '15 at 18:51