We can now add a confidence interval for our sample mean, a nice touch.

Even with its limitations, tcdf can then be a useful tool.

Adding tcdf to the inventory sample:

inventory2=: 3 : 0
pr=.500$0
'i l c h K k p s S'=.200,100,2,0.1,10,1,0.95,80,200
for. i.2000 do.
    v=. i<.l poissonran 500  NB. sales Poisson with mean l
    r=. (S-i-v)*(s>i-v)*.p>[EMAIL PROTECTED] NB. bring inventory to level S if 
it fals
below s, probability of delivering purchased merchandise p
    pr=.pr+(c*v)-((i-v)*h)+(r>0)*K+k*r NB. profit for day
    i=.0>.i+r-v
end.
res=. dstat pr1=.pr%2000 NB. average daily profit
a=:0.001*(0.001*>.1000*200 tcdf  0.001*i.>.1000*<:%:200 )i.!.(2^_35)0.95 NB.
beyond 200, tcdf is unreliable
NB.                                                      i instead of I to
increase comparison tolerance
res=:res, '90.0% confidence interval for mean (student):',(8j3)":(mean
pr1)(-,+)(stddev pr1)*a%500
)

With such a large sample, assuming a normal would be the way to go.  I
preferred to remain true to the java illustration I was translating to J.


On Tue, Aug 12, 2008 at 11:04 PM, Roger Hui <[EMAIL PROTECTED]> wrote:

> Your suggestions would not fix the problems.
> There many values y which exceeds %:x but
> x tcdf y is not theoretically or even practically 1.
> For example,
>
>   3 tcdf 2.35336
> |assertion failure: tcdf
> |   (%:x)>|y
>
> But (from tables) the value should be 0.95.
>
> Moreover, for any finite y (less than 0 or otherwise),
> x tcdf y should mathematically not be 0. e.g.
>
>    3 tcdf _1e_30
> 0.5
>
> So this is a case where y<0 but the mathematical
> answer is 0.5, contrary to
>
> > 0 instead of assert when y<0 or when y<0 and the
> > calculation is not 0.
>
>
>
> ----- Original Message -----
> From: Robert Cyr <[EMAIL PROTECTED]>
> Date: Tuesday, August 12, 2008 18:02
> Subject: Re: [Jprogramming] general Gamma distribution
> To: Programming forum <[email protected]>
>
> > concerning Roger Hui's formula for the students CDF,
> >
> > It would be handy to return
> >
> > 1 instead of assert when y>0 or when y>0 and the calculation
> > returns less
> > than 0
> >
> > 0 instead of assert when y<0 or when y<0 and the
> > calculation is not 0.
> >
> > On Tue, Aug 12, 2008 at 8:40 PM, Robert Cyr
> > <[EMAIL PROTECTED]> wrote:
> >
> > > There appears to be a sign problem in the formula.
> > >
> > > The formula either form Wolfram or wikipedia are:
> > >
> > > tcdf=: 4 : 0
> > >  assert. (%:x)>|y
> > >  0.5 + y * (!-:x+1) * ((0.5,-:1+x) H. 1.5 x%~-*:y) %
> > (%:o.x) * !<:-:x
> > > )
> > >
> > > As noted by others, the limit also needs to be adjusted.
> > > The limits probably are too high, as tcdf cannot exceed
> > 1.  It seems to be
> > > in that region that problem results occur.
> > >
> > >
> > > On Tue, Aug 12, 2008 at 5:38 PM, Roger Hui
> > <[EMAIL PROTECTED]> wrote:
> > >
> > >> For large x one may want to use the N(0,1) CDF
> > >> in a pinch.  From
> > >> http://www.jsoftware.com/jwiki/Essays/Normal_CDF
> > >>
> > >> erf   =: (1 H. 1.5)@*: * 2p_0.5&* % ^@:*:
> > >> n01cdf=: -: @ >: @ erf @ %&(%:2)
> > >>
> > >>   10 tcdf 3
> > >> 0.993328
> > >>    n01cdf 3
> > >> 0.99865
> > >>
> > >> The bad  100 tcdf 9  result is likely due to extreme
> > >> accumulation of numerical errors.  On my machine I get:
> > >>
> > >>   100 tcdf 9
> > >> 1.03437e17
> > >>
> > >>   n01cdf 9
> > >> 1
> > >>   1 - n01cdf 9
> > >> _2.22045e_16
> > >>
> > >>
> > >>
> > >> ----- Original Message -----
> > >> From: John Randall <[EMAIL PROTECTED]>
> > >> Date: Tuesday, August 12, 2008 14:07
> > >> Subject: Re: [Jprogramming] general Gamma distribution
> > >> To: Programming forum <[email protected]>
> > >>
> > >> > Roger Hui wrote:
> > >> > > It's the absolute value of y that should be bounded,
> > >> > > not just y itself.  Thus:
> > >> > >
> > >> > > tcdf=: 4 : 0
> > >> > >  assert. (%:x)>|y
> > >> > >  0.5 + y * (!-:x-1) * ((0.5,-:1+x) H. 1.5 x%~-*:y) %
> > >> > (%:o.x) * !<:-:x
> > >> > > )
> > >> > >
> > >> > >
> > >> > Mathworld <http://mathworld.wolfram.com/Studentst-
> > >> > Distribution.html> has
> > >> > different formulations (equations 7 and  8), which
> > rely on
> > >> > the incomplete
> > >> > beta function and are not subject to the hypergeometric bounds.
> > >> >
> > >> > I don't think the restriction is bad when x (degrees of freedom)
> > >> > is above
> > >> > about 10.  For example
> > >> >
> > >> >    10 tcdf 3
> > >> > 0.993328
> > >> >
> > >> > but it is not good if x is smaller.   High values
> > of y
> > >> > give strange results:
> > >> >
> > >> >    100 tcdf 9
> > >> > _7.15204e15
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to