MathGroup Archive 2013

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: User-defined Probability Mass Function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg131447] Re: User-defined Probability Mass Function
  • From: Bob Hanlon <hanlonr357 at gmail.com>
  • Date: Sun, 7 Jul 2013 23:22:07 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-outx@smc.vnet.net
  • Delivered-to: mathgroup-newsendx@smc.vnet.net

Clear[pointDistribution];


pointDistribution /: PDF[
   pointDistribution[spt_, prob_], x_] :=
  Piecewise[{#[[1]], Equal[x, #[[2]]]} & /@
    Thread[{prob, spt}]];


pointDistribution /: CDF[
   pointDistribution[spt_, prob_], x_] :=
  Module[{s, p},
   {s, p} = Thread[SortBy[
      Thread[{spt, prob}], N[#[[1]]] &]];
   Piecewise[Reverse[
     {#[[1]], GreaterEqual[x, #[[2]]]} & /@
      Thread[{Accumulate[p], s}]]]];


pointDistribution /: Mean[
   pointDistribution[spt_, prob_]] :=
  spt.prob;


pointDistribution /: Variance[
   pointDistribution[spt_, prob_]] :=
  Module[
   {m = Mean[pointDistribution[spt, prob]]},
   ((spt - m)^2).prob];


pointDistribution /: StandardDeviation[
   pointDistribution[spt_, prob_]] :=
  Sqrt[Variance[pointDistribution[spt, prob]]];


pointDistribution /: expectation[
   expr_, x_,
   pointDistribution[spt_, prob_]] :=
  (expr /. ({(x -> #)} & /@ spt)).prob;


The standfard structure for Expectation was not used because the target
(pointDistribution) of the upvalue cannot be buried too deeply in the
definition.


pointDistribution /: Mode[
   pointDistribution[spt_, prob_]] :=
  Module[
   {m = Pick[support, Thread[prob == Max[prob]]]},
   If[Length[m] == 1, m[[1]], m]];


support = {-2.1, 3.45, 7};
prob = {0.5, 0.3, 0.2};
dist = pointDistribution[support, prob];


PDF[dist, x]


Piecewise[{{0.5, x == -2.1}, {0.3, x == 3.45},
     {0.2, x == 7}}, 0]


Mode[dist]


-2.1


Mean[dist]


1.385


Mean[dist] == expectation[x, x, dist]


True


Variance[dist]


13.6575


Variance[dist] ==
 expectation[(x - Mean[dist])^2, x, dist]


True


StandardDeviation[dist]


3.69561


CDF[dist, x]


Piecewise[{{1., x >= 7}, {0.8, x >= 3.45},
     {0.5, x >= -2.1}}, 0]


DiscretePlot[
 PDF[dist, x], {x, support},
 Frame -> True, Axes -> False,
 AxesOrigin -> {0, 0}]


Plot[CDF[dist, x],
 {x, Min[support] - 1, Max[support] + 1},
 Frame -> True, Axes -> False,
 AxesOrigin -> {0, 0},
 Exclusions -> support,
 ExclusionsStyle -> AbsoluteDashing[{2, 5}]]


support2 = {-2.1, 3.45, Pi};
prob2 = {.5, .3, .2};


dist2 = pointDistribution[support2, prob2];


PDF[dist2, x]


Piecewise[{{0.5, x == -2.1}, {0.3, x == 3.45},
     {0.2, x == Pi}}, 0]


CDF[dist2, x]


Piecewise[{{1., x >= 3.45}, {0.7, x >= Pi},
     {0.5, x >= -2.1}}, 0]



Bob Hanlon




On Sat, Jul 6, 2013 at 5:04 AM, <bruce.colletti at gmail.com> wrote:

> The questions below can presumably be answered in terms of
> ProbabilityDistribution, so here goes...
>
> How do I create a distribution for the discrete random variable whose
> support is {-2.1, 3.45, 7} having corresponding probabilities {0.5, 0.3,
> 0.2}?
>
> What if the support is {-2.1, 3.45, pi}?
>
> If ProbabilityDistribution cannot support these, then what?
>
> Thanks.
>
> Bruce
>
>




  • Prev by Date: Re: User-defined Probability Mass Function
  • Next by Date: Re: Problems Exporting to LaTeX, Windows 8, Mathematica 9
  • Previous by thread: Re: User-defined Probability Mass Function
  • Next by thread: Re: User-defined Probability Mass Function