Skip to content
Statistics LabMAST20005 · 2020

Fitting a distribution

Before estimating anything you have to commit to a model. These sections fit the two skewed models the assignments used — the exponential and the lognormal — estimate their parameters by maximum likelihood, and check the fit with quantiles.

The assignment datasets are not reproduced here; each lab starts with a simulated sample of the same size and shape. Paste any data to analyse it, and compare the 2020 results in the margin.

§2.1Coursework A1 Q1

An exponential model and its QQ plot

Thirty plant heights, measured after six weeks, were strongly right-skewed. For an exponential model with mean θ the log-likelihood ℓ(θ)=−nlog⁡θ−∑xi/θ\ell(\theta)=-n\log\theta-\sum x_i/\theta is maximised at the sample mean, θ^=xˉ\hat\theta=\bar x.

To judge the fit, the notebook compared Type 6 sample quantiles, which interpolate the order statistics at position (n+1)p(n+1)p, with the model quantiles  πp=−θlog⁡(1−p)\;\pi_p=-\theta\log(1-p). Against Exp(1) the same points fall on a line of slope 1/θ instead of 1, so either reference works.

30 positive values

Compare against

Median

69.6

IQR 105.4

Mean

110.6

range 0.1 – 586.8

MLE θ̂ = x̄

110.59

Reference line

slope 1

y = x

Figure 2.1.Box plot of the sample (R’s Tukey hinges and 1.5 × IQR whiskers). A long right whisker and high outliers are the signature of a skewed, exponential-like shape — not a normal one.
  • Type 6 sample quantile vs model quantile
  • Reference line, slope 1
Figure 2.2.QQ plot at p = 0, 0.01, …, 0.99, laid out as in the notebook: sample quantiles across, theoretical quantiles up. If the data came from Exp(θ₀), the points hug a line through the origin with slope 1.
Show the numbers as a table
psample (type 6)theoretical
0.000.1000.0000
0.010.1001.0050
0.020.1002.0203
0.030.1003.0459
0.041.9724.0822
0.054.3905.1293
0.066.8086.1875
0.078.5127.2571
0.089.6288.3382
0.0910.7449.4311
0.1011.89010.5361
0.1113.09911.6534
0.1214.30812.7833
0.1315.40613.9262
0.1415.46815.0823
0.1515.53016.2519
0.1615.59217.4353
0.1717.78718.6330
0.1820.29819.8451
0.1922.80921.0721
0.2023.76022.3144
0.2123.85323.5722
0.2223.94624.8461
0.2324.13026.1365
0.2424.44027.4437
0.2524.75028.7682
0.2625.26430.1105
0.2726.62831.4711
0.2827.99232.8504
0.2929.35634.2490
0.3031.95035.6675
0.3134.58537.1064
0.3237.22038.5662
0.3340.40740.0478
0.3443.78641.5515
0.3547.16543.0783
0.3648.92844.6287
0.3749.17646.2035
0.3849.42447.8036
0.3949.89749.4296
0.4050.92051.0826
0.4151.94352.7633
0.4253.11654.4727
0.4356.46456.2119
0.4459.81257.9818
0.4563.16059.7837
0.4664.09061.6186
0.4764.55563.4878
0.4865.02065.3926
0.4966.87267.3345
0.5069.60069.3147
0.5172.32871.3350
0.5274.20473.3969
0.5374.73175.5023
0.5475.25877.6529
0.5577.30579.8508
0.5687.25682.0981
0.5797.20784.3970
0.58107.15886.7501
0.59108.84489.1598
0.60109.96091.6291
0.61111.07694.1609
0.62112.45696.7584
0.63113.94499.4252
0.64115.432102.1651
0.65117.760104.9822
0.66120.984107.8810
0.67124.208110.8663
0.68126.632113.9434
0.69126.756117.1183
0.70126.880120.3973
0.71127.060123.7874
0.72128.920127.2966
0.73130.780130.9333
0.74132.640134.7074
0.75134.350138.6294
0.76136.024142.7116
0.77137.698146.9676
0.78139.048151.4128
0.79140.164156.0648
0.80141.280160.9438
0.81147.951166.0731
0.82164.722171.4798
0.83181.493177.1957
0.84197.148183.2581
0.85205.270189.7120
0.86213.392196.6113
0.87221.514204.0221
0.88225.156212.0264
0.89228.318220.7275
0.90231.480230.2585
0.91279.687240.7946
0.92349.344252.5729
0.93419.001265.9260
0.94475.344281.3411
0.95515.520299.5732
0.96555.696321.8876
0.97586.800350.6558
0.98586.800391.2023
0.99586.800460.5170

§2.2Coursework A1 Q2

A lognormal model and an interval for its variance

If ln⁡X∼N(μ,λ)\ln X\sim N(\mu,\lambda) then the MLEs are the mean and the divide-by-n variance of the logged data. Because ∑(ln⁡Xi−ln⁡X‾)2/λ∼χn−12\sum(\ln X_i-\overline{\ln X})^2/\lambda\sim\chi^2_{n-1}, the 2020 working derived

sd⁡(λ^)=λ2n−1,\operatorname{sd}(\hat\lambda)=\lambda\sqrt{\tfrac{2}{n-1}},
((n−1)λ^χn−1, 1−α/22, (n−1)λ^χn−1, α/22)\left(\frac{(n-1)\hat\lambda}{\chi^2_{n-1,\,1-\alpha/2}},\ \frac{(n-1)\hat\lambda}{\chi^2_{n-1,\,\alpha/2}}\right)

and the port implements those formulas exactly as they were submitted.

15 values

95%

μ̂ = mean of ln x

1.8519

λ̂ (MLE)

1.7865

se(λ̂) = λ̂√(2/(n−1))

0.675245

95% CI for λ, as submitted

(0.9576, 4.444)

textbook SS/χ²: (1.026, 4.761)

  • ln xᵢ
  • Fitted N(μ̂, λ̂) density
  • 95% interval for the spread, as ±√λ around μ̂
lower λupper λ
Figure 2.3.On the log scale a lognormal sample is just a normal sample, so μ̂ and λ̂ are the mean and the (divide-by-n) variance of ln x. The red bars show how wide ±√λ could plausibly be, from the lower to the upper end of the chi-squared interval.

§2.3Coursework A3 Q2

How precise is a sample quantile?

For the exponential, F(x)=1−e−λxF(x)=1-e^{-\lambda x} inverts to πp=−log⁡(1−p)/λ\pi_p=-\log(1-p)/\lambda. The Type 7 sample quantile interpolates the order statistics at position k=1+(n−1)pk=1+(n-1)p, and for large n

π^p≈N ⁣(πp, p(1−p)n f(πp)2),\hat\pi_p \approx N\!\left(\pi_p,\ \frac{p(1-p)}{n\,f(\pi_p)^2}\right),
f(πp)=λ(1−p).f(\pi_p)=\lambda(1-p).

With n = 30 and p = 0.25 the variance is 1/(90λ2)1/(90\lambda^2), so the standard error is 1/(90 λ^)1/(\sqrt{90}\,\hat\lambda).

30 values

0.25

π̂ (Type 7), p = 0.25

4.830

k = 1 + (n−1)p = 8.25

λ̂ = 1 / x̄

0.1336

Model πₚ = −ln(1−p)/λ̂

2.153

Asymptotic se

0.789

≈95% CI (3.28, 6.38)

  • Empirical CDF
  • Fitted Exp(λ̂) CDF
  • ±1.96 se around π̂
Figure 2.4.The sample quantile is where the empirical CDF crosses height p (with Type 7 interpolation between order statistics); the model quantile is where the fitted exponential CDF does. The shaded band is the large-sample interval π̂ ± 1.96 se, with se² = p(1−p) / (n f(πₚ)²) and f(πₚ) = λ(1 − p).