0
$\begingroup$

I have this custom distribution that I want to use in Mathematica, but there appears to be some sort of problem I don't understand.

Also, when I compute the mean for the custom distribution via Mathematica, I get 2.74084, while the correct answer is 1.577661

Can someone help me? Thanks...

PvA[v_, A_] := (A^v*Exp[-A])/Factorial[v];
SumF[P_, i_, A_] := Sum[P[[vv + 1]]*PvA[i - vv + 1, A], {vv, 2, i}];
Pr[Aval_, k_] := Module[{A = Aval, P = Table[0, {k + 1}]},
   P[[1]] = 1 - A;
   P[[2]] = (1 - A)*(Exp[A] - 1);
   For[i = 2, i <= k, i++, 
    P[[i + 1]] = (1/
        PvA[0, A])*(P[[i]] - (P[[1]] + P[[2]])*PvA[i - 1, A] - 
        SumF[P, i - 1, A])];
   Last[P]];
α = 0.5;
X = ProbabilityDistribution[((Pr[α, -1 + x]/
      Sum[Pr[α, j], {j, 0, -1 + x}]) - (Pr[α, x]/
      Sum[Pr[α, j], {j, 0, x}])), {x, 1, 30}]

Table::iterb: Iterator {x} does not have appropriate bounds.

Table::iterb: Iterator {x} does not have appropriate bounds.

Last::nolast: {} has zero length and no last element.

Table::iterb: Iterator {1+j} does not have appropriate bounds.

General::stop: Further output of Table::iterb will be suppressed during this calculation.

Last::nolast: {} has zero length and no last element.

Last::nolast: {} has zero length and no last element.

General::stop: Further output of Last::nolast will be suppressed during this calculation.
In[1893]:= N[Mean[X]]

Out[1893]= 2.74084
Sum[x*((Pr[α, -1 + x]/
      Sum[Pr[α, j], {j, 0, -1 + x}]) - (Pr[α, x]/
      Sum[Pr[α, j], {j, 0, x}])), {x, 1, 30}]
1.57661
$\endgroup$

1 Answer 1

1
$\begingroup$
$Version

(* "13.3.0 for Mac OS X ARM (64-bit) (June 3, 2023)" *)

Clear["Global`*"]

PvA[v_, A_] := (A^v*Exp[-A])/Factorial[v];

SumF[P_, i_, A_] := Sum[P[[vv + 1]]*PvA[i - vv + 1, A], {vv, 2, i}];

You need to keep Pr from evaluating unless k has an integer value

Pr[Aval_, k_Integer] := 
  Module[{A = Aval, P = Table[0, {k + 1}]}, P[[1]] = 1 - A;
   P[[2]] = (1 - A)*(Exp[A] - 1);
   For[i = 2, i <= k, i++, 
    P[[i + 1]] = (1/PvA[0, A])*(P[[i]] - (P[[1]] + P[[2]])*PvA[i - 1, A] - 
        SumF[P, i - 1, A])];
   Last[P]];

α = 0.5;

X is a discrete distribution so you must specify a step size

X = ProbabilityDistribution[((Pr[α, -1 + x]/
      Sum[Pr[α, j], {j, 0, -1 + x}]) - (Pr[α, x]/
      Sum[Pr[α, j], {j, 0, x}])), {x, 1, 30, 1}]

enter image description here

Mean[X]

(* 1.57661 *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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