1
$\begingroup$

I would please like to ask for how to cumulate and plot the difference between cumulative disitribution functions (:=CDFs).

Example:

prob = {0.1, 0.2, 0.4, 0.2, 0.1}
(* Define distributions *)
empA = EmpiricalDistribution[prob -> {0, 0.5, 1, 2, 3}]
empB = EmpiricalDistribution[prob -> {-0.5, -0.25, 1.5, 3, 4}]  
(* Plot cumulative distribution functions *)
CDFA = DiscretePlot[CDF[empA][x], {x, -1, 5, 0.25}, Frame -> True, 
  ExtentSize -> Right, ExtentMarkers -> {"Filled", "Empty"}, 
  PlotRange -> {0, 1.1}, PlotStyle -> {Blue}]
CDFB = DiscretePlot[CDF[empB][x], {x, -1, 5, 0.25}, Frame -> True, 
  ExtentSize -> Right, ExtentMarkers -> {"Filled", "Empty"}, 
  PlotRange -> {0, 1.1}, PlotStyle -> {Red}]
(* Plot difference between cumulative distribution functions *)
DELTA = DiscretePlot[CDF[empB][x] - CDF[empA][x], {x, -1, 5, 0.25}, 
  Frame -> True, ExtentSize -> Right, 
  ExtentMarkers -> {"Filled", "Empty"}, PlotRange -> {-0.5, 0.5}, 
  PlotStyle -> {Green}]

Considering DELTA, I would like to obtain and plot its cumulative value over x as specified.

$\endgroup$
1
$\begingroup$

I'm curious as to why you'd want to do this.

delta = Table[{x, CDF[empB][x] - CDF[empA][x]}, {x, -1, 5, 0.25}]
delta[[All, 2]] = Accumulate[delta[[All, 2]]];
ListPlot[delta]

Cumulative difference

$\endgroup$
  • $\begingroup$ Thank you very much indeed - exactly what I have been asking for. As to why I want to do this, I am considering a graphical illustration for what it means a random variable to stochastically dominate another in first (my green DELTA plot) and second (your delta plot) order. Because DELTA is not always of one sign, there is no first order stochastic dominance. Because the accumulated DELTA also is not of one sign - A is "better" in the first part, but then loses too much in the second -, there is also no second order stochastic dominance. $\endgroup$ – Sinistrum Oct 10 at 5:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.