       Empirical CDF

• To: mathgroup at smc.vnet.net
• Subject: [mg58912] Empirical CDF
• From: "David Kahle" <david.kahle at richmond.edu>
• Date: Sat, 23 Jul 2005 05:32:26 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```MathGroup -

swidrygiello posted on Fri, 13 Sep 2002 a question on how to create the
empirical cumulative distribution function (ECDF) with Mathematica.  Since
then, few others (Mark Fisher, [mg36613], for example) have posted
responses utilizing the Interpolation[] command.  However, similar results
can be achieved using the simple code :

For[i=1,i<(Length[rand]+1),preF[x_,i_]:=UnitStep[x-rand[[i]]],i++]
F[x_]:=Sum[preF[x,i],{i,Length[rand]}]/Length[rand]

Where 'rand' is the vector containing the random observations.  The
resulting function F is right continuous, limits to 0 and 1 as we would
like it to, and has the correct step sizes.  Even better, Mathematica is
more comfortable manipulating UnitStep functions than it is piecewise
functions defined with the Which[] command.  For example, if we would like
to integrate the ECDF to test for certain orderings (Stochastic dominance,
etc.), Mathematica understands integrating the F as defined above, but if
we use the Which[] command it resorts to numerical techniques which
typically fail for various reasons.  Hope it helps.

David Kahle
david.kahle at richmond.edu

```

• Prev by Date: Re: Re: New to Mathematica- How to write functions????????
• Next by Date: Re: No more memory available.
• Previous by thread: Re: Follow-on: StyleForm and font selection
• Next by thread: Re: Empirical CDF