Re: Re: Area Under Curve (Min Length Interval)

*To*: mathgroup at smc.vnet.net*Subject*: [mg53917] Re: [mg53900] Re: [mg53889] Area Under Curve (Min Length Interval)*From*: DrBob <drbob at bigfoot.com>*Date*: Fri, 4 Feb 2005 04:11:12 -0500 (EST)*References*: <200502021125.GAA28978@smc.vnet.net> <200502022310.SAA11934@smc.vnet.net>*Reply-to*: drbob at bigfoot.com*Sender*: owner-wri-mathgroup at wolfram.com

That's a great approach, but be careful. Here's the same code without the plots: dist = ChiSquareDistribution[5]; F[x_] = CDF[dist, x]; Off[Solve::"ifun"] tempsoln = Solve[F[b] - F[a] == 93/100, b][[1, 1]]; soln = Last@NMinimize[{b - a /. tempsoln, b > a > 0}, {a, b}] F@b - F@a /. soln {9.971553966649529, {a -> 0.3725304421496036, b -> 0.5177610388627399}} 0.00459403860285145 The last result should be 0.93, if "soln" gave the desired a and b. This is the correct interval: {a,b}/.tempsoln/.soln {0.37253,10.3441} But this seems slightly more natural: dist = ChiSquareDistribution[5]; F[x_] = CDF[dist, x]; Off[Solve::"ifun"] tempsoln = Solve[F[b] - F[a] == 93/100, b][[1, 1]]; {difference, aRule} = NMinimize[{b - a /. tempsoln, a > 0}, {a}]; solution = Flatten@{aRule, b -> (a + difference /. aRule)} {a -> 0.37253, b -> 10.3441} F@b-F@a/.solution 0.93 PDF[dist,#]&/@{a,b}/.solution {0.0250979,0.0250979} Note that b isn't actually a variable in the objective function, either way. Bobby On Wed, 2 Feb 2005 18:10:41 -0500 (EST), Chris Chiasson <chris.chiasson at gmail.com> wrote: > I think Bruce's code would usually work, but Minimize isn't able to > pick up on what is happening or what you want; I'm not sure which. > Anyway, here are a few lines of code that graphically demonstrate what > is happening and give the (locally) correct solution. > > << Statistics`ContinuousDistributions` > F[x_] = CDF[ChiSquareDistribution[5], x]; > NMinimize[{b - a, F[b] - F[a] == 93/100, b > a > 0}, {a, b}] > tempsoln = Solve[F[b] - F[a] == 93/100, b][[1, 1]] > intersectingsurfaces = Plot3D[#, {a, 0, 2}, {b, 0, 40}, AxesLabel -> {"a", > "b", "c"}, DisplayFunction -> Identity] & /@ {F[b] - F[a], 0.93} > Show[intersectingsurfaces, > ViewPoint -> {0, 0, 1}, DisplayFunction -> $DisplayFunction] > Plot[Evaluate[b /. tempsoln], {a, 0, 1.3}, AxesLabel -> {"a", "b"}] > Plot[Evaluate[b - a /. tempsoln], {a, 0, 1.3}, AxesLabel -> {"a", "b-a"}] > NMinimize[{b - a /. tempsoln, b > a > 0}, {a, b}] > > For clarity, these commands may be evaluated one at a time. > > Regards, > > On Wed, 2 Feb 2005 06:25:53 -0500 (EST), Bruce Colletti > <vze269bv at verizon.net> wrote: >> Re Mathematica 5.1. >> >> How would I compute the minimum length interval over which the area under f(x) is given? >> >> For instance, as shown below, f(x) is the PDF of a chi-square distributed random variable whose CDF is F[x]. Seeking the minimum length 93%-interval [a,b], the code returns "Obtained solution does not satisfy the following constraints within Tolerance -> 0.001..." Fiddling with options has been futile. >> >> Any ideas? Thankx. >> >> Bruce >> >> F[x_] := CDF[ChiSquareDistribution[5], x] >> >> Minimize[{b - a, F[b] - F[a] == 0.93, b > a > 0}, {a, b}] >> >> NMinimize[{b - a, F[b] - F[a] == 0.93, b > a > 0}, {a, b}] >> >> > > -- DrBob at bigfoot.com www.eclecticdreams.net

**References**:**Area Under Curve (Min Length Interval)***From:*Bruce Colletti <vze269bv@verizon.net>

**Re: Area Under Curve (Min Length Interval)***From:*Chris Chiasson <chris.chiasson@gmail.com>

**Re: Matrix equations**

**Re: Re: Latex + Mathematica EPS file problems**

**Re: Area Under Curve (Min Length Interval)**

**Re: Area Under Curve (Min Length Interval)**