[ 
https://issues.apache.org/jira/browse/MATH-1373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15338359#comment-15338359
 ] 

Brent Worden edited comment on MATH-1373 at 6/19/16 4:22 AM:
-------------------------------------------------------------

I am not completely convinced this change is correct.

Referencing on of the citations, 
http://mathworld.wolfram.com/LogNormalDistribution.html, the density function 
is parameterized the same way LogNormalDistribution is parameterized with
* MathWorld's M being equivalent to Commons Math's scale
* MathWorld's S being equivalent to Commons Math's shape

The distribution mean according to MathWorld is Exp(M + S^2 / 2) which 
corresponds to Exp(scale + shape^2 / 2) and is how it is coded in 
LogNormalDistribution.

Likewise, MathWorld states the distribution variance Exp(S^2 + 2 M) * (Exp(S^2 
- 1) which is Exp(shape^2 + 2 scale) * (Exp(shape^2 - 1).  Again, this matches 
the implementation.

Furthermore, generating a large sample from the distribution results in sample 
means and variances that are pretty close to the population values returned 
from the getNumericalMean and getNumericalVariance methods.  Here is the code I 
am using to make that claim:

{code}
    @Test
    public void testMeanAndVariance() {
        LogNormalDistribution dist = new LogNormalDistribution(5.375, 1.125);
        double[] x = new double[100000];
        for (int i = 0; i < x.length; ++i) {
            x[i] = dist.inverseCumulativeProbability(Math.random());
        }
        double actualMean = new Mean().evaluate(x);
        double actualVariance = new Variance().evaluate(x);

        double expectedMean = dist.getNumericalMean();
        double expectedVariance = dist.getNumericalVariance();

        System.out.println(String.format("Mean: %f vs %f (actual vs expected)", 
actualMean, expectedMean));
        System.out.println(String.format("Variance: %f vs %f (actual vs 
expected)", actualVariance, expectedVariance));
    }
{code}



was (Author: brentworden):
I am not completely convinced this change is correct.

Referencing on of the citations, 
http://mathworld.wolfram.com/LogNormalDistribution.html, the density function 
is parameterized the same way LogNormalDistribution is parameterized with
* MathWorld's M being equivalent to Commons Math's scale
* MathWorld's S being equivalent to Commons Math's shape

The distribution mean according to MathWorld is Exp(M + S^2 / 2) which 
corresponds to Exp(scale + shape^2 / 2) and is how it is coded in 
LogNormalDistribution.

Likewise, MathWorld states the distribution variance Exp(S^2 + 2 M) * (Exp(S^2 
- 1) which is Exp(shape^2 + 2 scale) * (Exp(shape^2 - 1).  Again, this matches 
the implementation.

Furthermore, generating a large sample from the distribution results in sample 
means and variances that are pretty close to the expected values returned from 
the getNumericalMean and getNumericalVariance methods.  Here is the code I am 
using to make that claim:

{code}
    @Test
    public void testMeanAndVariance() {
        LogNormalDistribution dist = new LogNormalDistribution(5.375, 1.125);
        double[] x = new double[100000];
        for (int i = 0; i < x.length; ++i) {
            x[i] = dist.inverseCumulativeProbability(Math.random());
        }
        double actualMean = new Mean().evaluate(x);
        double actualVariance = new Variance().evaluate(x);

        double expectedMean = dist.getNumericalMean();
        double expectedVariance = dist.getNumericalVariance();

        System.out.println(String.format("Mean: %f vs %f (actual vs expected)", 
actualMean, expectedMean));
        System.out.println(String.format("Variance: %f vs %f (actual vs 
expected)", actualVariance, expectedVariance));
    }
{code}


> In LogNormalDistribution.java, it appears shape & scale are 
> reversed/mis-labelled.
> ----------------------------------------------------------------------------------
>
>                 Key: MATH-1373
>                 URL: https://issues.apache.org/jira/browse/MATH-1373
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 3.6.1
>            Reporter: Karl D. Gierach
>            Priority: Minor
>         Attachments: MATH-1373.patch
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> When I compute the logshape and log scale based on the formulas on 
> wikipedia's lognormal distribution page that use empirical mean and variance, 
> I found that the getNumericalMean() method was not returning the empirical 
> mean.
> However, upon just trying to reverse the shape and scale parameters in the 
> constructor proved to fix the problem, and the object then returns the 
> correct empirical mean.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to