Previous Up Next

9.4.23 Distribution fitting by maximum likelihood: fitdistr

The fitdistr command finds the parameters for a distribution of a specified type that best fit a set of samples.


Examples.

You can fit a lognormal distribution to samples x1,x2,…,xn by fitting a normal distribution to the sample logarithms log x1,logx2,…,logxn because log-likelihood functions are the same. For example, generate some samples according to the lognormal rule with parameters µ=5 and σ2=2:
Input:

X:=randvar(normal,mean=5,variance=2):; S:=sample(eval(exp(X),0),1000):;

Then fit the normal distribution to logS:
Input:

Y:=fitdistr(log(S),normal)

Output:

normald(5.04754808715,1.42751619912)

The mean of Y is about 5.05 and the variance is about 2.04. Now the variable Z=exp(Y) has the sought lognormal distribution.


Previous Up Next