1
$\begingroup$

I'm trying to implement logNormal distribution into my java program because lognormal dist doesn't exist into apache commons math library.

I have no problem to re-write density and cumulative probability function, extending abstract classes of apache commons math library, like this :

 public double cumulativeProbability(double mu, double sigma, double x) {

        if (sigma <= 0.0) {
            throw new IllegalArgumentException("sigma  <= 0");
        }
        if (x <= 0.0) {
            return 0.0;
        }

        return this.cumulativeProbability((Math.log(x) - mu) / sigma);
    }

 public double cumulativeProbability(double x){

        double var = 0.0;
        NormalDistributionImpl normalDist = new NormalDistributionImpl();

        try {
            var = normalDist.cumulativeProbability(x);
        } catch (MathException e) {}

        return var;  
    }


  public double density (double x) {
      return density (mu, sigma, x);
  }


  public static double density (double mu, double sigma, double x) {

      if (sigma <= 0)
         throw new IllegalArgumentException ("sigma <= 0");
      if (x <= 0)
         return 0;
      double diff = Math.log (x) - mu;
      return Math.exp (-diff*diff/(2*sigma*sigma))/
              (Math.sqrt (2*Math.PI)*sigma*x);
   }

Apache commons math need implementation of a list of utilies function to compute the inverse cumulative probability, and i don't know which upper/lowerbound/initial domain my lognormal distribution can take ...

I suppose it's something like this, but i'm not sure : x between [0 ; +infinity] ?

Thanks a lot for your help


p = Desired probability for the critical value.

Access the domain value lower bound, based on p, used to bracket a CDF root. This method is used by inverseCumulativeProbability(double) to find critical values.

  public double getDomainLowerBound(double p){
    return ?;
  }

Access the domain value upper bound, based on p, used to bracket a CDF root. This method is used by inverseCumulativeProbability(double) to find critical values.

  public double getDomainUpperBound(double p){
    return ?;
  }

Access the initial domain value, based on p, used to bracket a CDF root. This method is used by inverseCumulativeProbability(double) to find critical values.

  public double getInitialDomain(double p){
    return ?;
  }

Access the lower bound of the support. Returns: lower bound of the support (might be Double.NEGATIVE_INFINITY)

  public double getSupportLowerBound(){
    return ?;
  }

Access the upper bound of the support. Returns: upper bound of the support (might be Double.POSITIVE_INFINITY)

  public double getSupportUpperBound(){
    return ?;
  }

Use this method to get information about whether the lower bound of the support is inclusive or not. Returns: whether the lower bound of the support is inclusive or not

  public  boolean isSupportLowerBoundInclusive(){
      return ;
  }

Use this method to get information about whether the upper bound of the support is inclusive or not. Returns: whether the upper bound of the support is inclusive or not

  public boolean isSupportUpperBoundInclusive(){
      return ;
  }
$\endgroup$
4
  • $\begingroup$ How about looking at the code of freely available lognormal distribution implementations, such as R? $\endgroup$
    – mpiktas
    Commented May 31, 2011 at 13:07
  • $\begingroup$ The implementation is dead simple: given a value $x$, pass $\exp(x)$ to the appropriate Normal distribution function; given output that is a Normal variate (such as the inverse CDF or the bounds of the support), take its logarithm before passing it on to the caller. (The log of $0$ is $-\infty$.) You don't actually need to know anything else about the lognormal distribution! $\endgroup$
    – whuber
    Commented May 31, 2011 at 15:29
  • $\begingroup$ @whuber: because of the chain rule, that statement is not true for, e.g., the PDF (which @reyman64 solved already). $\endgroup$
    – Erik P.
    Commented May 31, 2011 at 15:55
  • $\begingroup$ @Erik Thank you for pointing this out. You are correct about the PDF; I should have stipulated that that requires a (simple) adjustment. If one follows strict typing and units of measurement procedures, it becomes obvious where such adjustments are needed and where they are not. $\endgroup$
    – whuber
    Commented May 31, 2011 at 16:55

1 Answer 1

3
$\begingroup$

The support for the log normal distribution is the open interval from 0 to infinity. This should give you enough information to implement all methods that have 'Bound' in their name.

I understand that the methods with 'Domain' in their name are used to provide bounds and estimates for the inverse CDF that are easy to compute; for this you can easily follow @whuber's suggestion and return the $\exp$ of the corresponding values for the normal distribution. It's instructive to see what the implementors use for that: if $p \not= \frac{1}{2}$, then the infinite interval on the appropriate side of $\mu$ provides the bounds and the initial estimate is $\mu \pm \sigma$. So you could also directly return the $\exp$ of these values.

$\endgroup$
2
  • $\begingroup$ Thanks for answer ;) But, i have other question, what does "support" mean in getSupportUpperBound et getSupportLowerBound ? $\endgroup$
    – reyman64
    Commented Jun 6, 2011 at 12:52
  • $\begingroup$ "Support" is the set of values that the random variable can attain; that is, the set of values where the probability distribution function (or the probability function for a discrete distribution) is nonzero. $\endgroup$
    – Erik P.
    Commented Jun 6, 2011 at 16:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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