# Upper/lower bound and initial domain for lognormal distribution

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 ;
}

-
How about looking at the code of freely available lognormal distribution implementations, such as R? –  mpiktas May 31 '11 at 13:07
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! –  whuber May 31 '11 at 15:29
@whuber: because of the chain rule, that statement is not true for, e.g., the PDF (which @reyman64 solved already). –  Erik P. May 31 '11 at 15:55
@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. –  whuber May 31 '11 at 16:55
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.