title: Calculating expectation for a custom distribution in Mathematica
body: <p>This question builds on the great answers I got on an earlier question:</p>
  
  <p><a href="https://stackoverflow.com/questions/5583456/can-one-extend-the-functionality-of-pdf-cdf-finddistributionparameters-etc-in-m">Can one extend the functionality of PDF, CDF, FindDistributionParameters etc in Mathematica?</a></p>
  
  <p>To start I have PDFs and CDFs for two custom distributions: nlDist and dplDist as you can see from the code dplDist builds upon nlDist.</p>
  
  <pre><code>    nlDist /: PDF[nlDist[alpha_, beta_, mu_, sigma_], 
     x_] := (1/(2*(alpha + beta)))*alpha* 
     beta*(E^(alpha*(mu + (alpha*sigma^2)/2 - x))* 
        Erfc[(mu + alpha*sigma^2 - x)/(Sqrt[2]*sigma)] + 
       E^(beta*(-mu + (beta*sigma^2)/2 + x))* 
        Erfc[(-mu + beta*sigma^2 + x)/(Sqrt[2]*sigma)]); 
  
  nlDist /: 
    CDF[nlDist[alpha_, beta_, mu_, sigma_], 
     x_] := ((1/(2*(alpha + beta)))*((alpha + beta)*E^(alpha*x)* 
          Erfc[(mu - x)/(Sqrt[2]*sigma)] - 
         beta*E^(alpha*mu + (alpha^2*sigma^2)/2)*
          Erfc[(mu + alpha*sigma^2 - x)/(Sqrt[2]*sigma)] + 
         alpha*E^((-beta)*mu + (beta^2*sigma^2)/2 + alpha*x + beta*x)*
          Erfc[(-mu + beta*sigma^2 + x)/(Sqrt[2]*sigma)]))/ 
     E^(alpha*x);         
  
  dplDist /: PDF[dplDist[alpha_, beta_, mu_, sigma_], x_] := 
    PDF[nlDist[alpha, beta, mu, sigma], Log[x]]/x;
  dplDist /: CDF[dplDist[alpha_, beta_, mu_, sigma_], x_] := 
    CDF[nlDist[alpha, beta, mu, sigma], Log[x]];
  
  Plot[PDF[dplDist[3.77, 1.34, -2.65, 0.40], x], {x, 0, .3}, 
   PlotRange -&gt; All]
  Plot[CDF[dplDist[3.77, 1.34, -2.65, 0.40], x], {x, 0, .3}, 
   PlotRange -&gt; All]
  </code></pre>
  
  <p>In my earlier question, joebolte's and sasha's answers and recommendation to use TagSet helped me get this far.  Now, my questions relate to the dplDist.  </p>
  
  <p>I now need to calculate expectation from some point on the x axis of the PDF.  In survival analysis they refer to this as mean residual life.  Something like the following:</p>
  
  <pre><code>Expectation[X \[Conditioned] X &gt; 0.1, 
    X \[Distributed] dplDist[3.77, 1.34, -2.65, 0.40]] - 0.1
  </code></pre>
  
  <p>This doesn't work, essentially just returning the inputs as text.</p>
  
  <p>I understand how I can use TagSet to define PDFs and CDFs for custom distributions, how do I do something similar for Expectation[]?</p>
  
  <hr>
  
  <p>I'll post more about this follow up in a separate question, but I also need a strategy for calculating goodness of fit of the dplDist relative to some data to which I've fit the distribution.</p>
  
  <hr>
  
  <p>Many thanks to all.</p>