Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2002
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2002

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

Search the Archive

Re: How to call BinomialDistribution from within a package?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg32228] Re: [mg32220] How to call BinomialDistribution from within a package?
  • From: jmt <jmt at agat.net>
  • Date: Wed, 9 Jan 2002 03:17:15 -0500 (EST)
  • References: <200201070816.DAA11589@smc.vnet.net>
  • Reply-to: jmt at agat.net
  • Sender: owner-wri-mathgroup at wolfram.com

Use :

BeginPackage["myPackage`",{"NeededPackage1`","NeededPackage2`",...}]


On Monday 07 January 2002 09:16, Merser wrote:
> I've tried to put this function: MediánCI  into a package.
>
> This function works fine running as a plain notebook.
>
> It look like the call to BinomialDistribution isn't working when called
> within a package?
>
> Does anybody has any idear what I'm doing wrong here ? I'm running
> Mathematica 4.0 on W2K.
>
>
>
> BeginPackage["MedianCI`", "Statistics`DiscreteDistributions`",
> "Statistics`DescriptiveStatistics`"]
> Off[General::spell1];
>
> MedianCI::usage = "MedianCI[data, conf=.95] Returns median with CI at
> confidence level=95%"
>
> Begin["`Private`"]
>
> bdist[n_] := BinomialDistribution[n, .5]
> cdf[x_, n_] := CDF[bdist[n], x]
>
> Clear[MedianCI];
> MedianCI[data_, conf_:.95] :=
>   Block[ {d, n, bdist, cdf, alfa, p, plo, phi, lo = 0, hi},
>     d = Sort[data];
>     n = Length[d];
>
>
>
>     alfa = (1 - conf)/2;
>
>     While[(p = cdf[lo, n]) < alfa,
>        lo++;
>        plo = p;
>       ];
>
>     hi = lo + 1;
>     While[(phi = cdf[hi, n]) < (1 - alfa),
>        hi++;
>        ];
>
>     m =Median[d];
>     {{"Median", "CI low", "CI high", "Confidence level"},
>       {m, d[[lo]], d[[hi + 1]], phi - plo}}
>     ]
> End[]
> EndPackage[]
>
>
>
>
>
> test:
>
> Median[Range[11]] // TableForm
>
> {{"Median", "CI low", "CI high", "Confidence level"},
>
> {6, List,  2, -MedianCI`Private`plo +
> MedianCI`Private`CDF[BinomialDistribution[11, 0.5`], 1]}}
>
>
>
> correct:
>
> {{"Median", "CI low", "CI high", "Confidence level"},
>
>       {6, 2, 10, 0.988281}}


  • Prev by Date: Re: System Ax=b!
  • Next by Date: RE: How to call BinomialDistribution from within a package?
  • Previous by thread: How to call BinomialDistribution from within a package?
  • Next by thread: How to call BinomialDistribution from within a package?