The density \(f(x \mid \theta)\) fixes the parameter and asks how likely each \(x\) is. The likelihood fixes the observed data and asks how likely they are under each \(\theta\). It is the same formula, read as a function of \(\theta\).
The product assumes the observations are independent. For discrete data, \(f\) is a probability; for continuous data it is a density, so \(L\) is not a probability and need not be below 1.
Write the model's density \(f\), multiply the densities into \(L\), and take logs. Set each partial derivative of \(\ell\) to zero and solve, numerically when there is no closed form. Then check that the solution is a maximum: a negative second derivative with one parameter, or a negative definite Hessian with several.
Normal with known \(\sigma = 1\), so \(\mu\) is the only unknown.
A double cannot store a positive number below about \(10^{-324}\). The likelihood of 2,000 points is far smaller than that, so a computer stores \(L\) as 0, while \(\ell\) is an ordinary number. Every fitting routine maximizes \(\ell\) for this reason.
The MLE of any function of \(\theta\) is that function of \(\hat\theta\). The Anvil uses this: the MLE of a B life (the hours by which a given percent have failed) is the model's quantile at the MLE.
optimize(function(mu) sum(dnorm(x, mu, 1, log = TRUE)), c(0, 10), maximum = TRUE) finds the same peak numerically. Part 1 of The Script.
The observed information is \(I(\hat\theta) = -\ell''(\hat\theta)\). For large \(n\), \(\hat\theta\) is approximately normal with variance \(1/I(\hat\theta)\). That gives the Wald interval.
The parabola on the plot is \(\hat\ell - (\theta - \hat\theta)^2 / (2\,\text{SE}^2)\): the quadratic with the same peak and second derivative as \(\ell\). Where \(\ell\) is lopsided (here, steeper on the left), the Wald interval is symmetric anyway. A likelihood-ratio interval follows the curve instead.
R writes the exponential with rate \(\lambda = 1/\theta\): dexp(x, rate). By invariance, \(\hat\lambda = 1/\bar x\). fitdistrplus reports the rate.
mean(x) is the MLE. fitdist(x / 1000, "exp") reports the rate per thousand hours; 1000 / estimate converts it back. Part 2 of The Script.
With \(\theta = (\theta_1, \theta_2)\), the MLE solves \(\partial\ell/\partial\theta_1 = 0\) and \(\partial\ell/\partial\theta_2 = 0\) together. For the lognormal, both equations solve in closed form. For the Weibull and the gamma, one equation gives the scale as a function of the shape, and substituting it leaves one equation in the shape (the score of the profile likelihood).
\(h'(\beta) = -1/\beta^2 - V_\beta\), where \(V_\beta\) is the variance of \(\ln x_i\) under weights proportional to \(x_i^\beta\). It is always negative, so \(h\) has a single root.
\(\psi\) is the digamma function, \(\psi(\alpha) = \frac{d}{d\alpha}\ln\Gamma(\alpha)\), and \(\psi'\) is the trigamma. The right side is at least 0 (the arithmetic mean is at least the geometric mean), and \(\ln\alpha - \psi(\alpha)\) falls from \(\infty\) to 0, so there is exactly one root.
To solve \(g(s) = 0\): replace \(g\) by its tangent line at the current \(s\) and solve that line. \(s_{\text{new}} = s - g(s)/g'(s)\). Near the root, the number of correct digits roughly doubles each step.
Nested models (exponential inside Weibull at \(\beta = 1\), and inside gamma at \(\alpha = 1\)) also allow the likelihood ratio test: \(2(\hat\ell_{\text{big}} - \hat\ell_{\text{small}})\) is approximately \(\chi^2\) with df equal to the number of extra parameters. Non-nested models are compared with AIC or BIC.
fitdist(x, "weibull"), "gamma", and "lnorm" fit each family; summary() prints estimates, standard errors, logLik, and AIC; denscomp() and qqcomp() draw the comparisons. The Newton loops are written out in part 3 of The Script.
Within one family, MLE maximizes \(\ell(\theta)\). Across families, compare the maxima \(\hat\ell\), charged for parameters: AIC \(= 2k - 2\hat\ell\), lower is better. Only differences matter. With equal \(k\), \(\Delta\text{AIC} = 2\Delta\hat\ell\), and \(e^{\Delta\text{AIC}/2}\) is how many times as likely the data are under the leader.
AIC ranks the candidates you gave it; it says nothing about whether any of them fits well. The probability plot shows where a model misses. Goodness-of-fit tests (Kolmogorov-Smirnov, Anderson-Darling) ask whether one family fits. With thousands of real observations they often reject every family, because no family is exactly right. gofstat() in fitdistrplus prints these statistics beside AIC and BIC.
\(B_p\) is the \(p\) quantile: the age by which a share \(p\) of parts have failed. By invariance its MLE is the fitted model's quantile. The interval uses the delta method on the log scale:
\(V\) is the inverse of the observed information (minus the Hessian of \(\ell\) at the peak), and \(\nabla\) is the gradient of \(\ln B_p\) in the parameters. bootdist() gives a bootstrap interval instead; for the Weibull \(B_1\) here the two agree within an hour.
A failed part contributes its density \(f(t_i)\). A running part at age \(t_i\) contributes only the probability that its life exceeds \(t_i\), the survival function \(S(t_i)\).
For the Weibull the scale still solves in closed form, \(\hat\eta^\beta = \frac1r\sum_{\text{all}} t_i^\beta\) with \(r\) failures, and the shape solves \(\frac1\beta + \frac1r\sum_{\text{failed}}\ln t_i - \frac{\sum_{\text{all}} t_i^\beta\ln t_i}{\sum_{\text{all}} t_i^\beta} = 0\).
Lives: Weibull with \(\beta = 1.8\) and \(\eta = 1{,}500\) hours, seed 2026. Ages on the record date: uniform from 0 to 3,000 hours, seed 2027. The B life chart marks the true values this implies.
fitdist() for each family, gofstat() for the table, quantile(fit, probs = 0.01) for B lives, bootdist() for intervals, and fitdistcens() for running parts. Part 4 of The Script.
| Call | What it returns |
|---|---|
fitdist(x, "weibull") | The MLE. Families: "exp", "weibull", "gamma", "lnorm", or any with a d function. |
summary(fit) | Estimates, standard errors from the observed information, logLik, AIC, and BIC. |
gofstat(list_of_fits) | AIC and BIC side by side, plus Kolmogorov-Smirnov, Cramér-von Mises, and Anderson-Darling statistics. |
denscomp(), qqcomp(), cdfcomp(), ppcomp() | Fitted densities over the histogram, and probability plots for several fits at once. |
quantile(fit, probs = 0.01) | A fitted quantile, such as the B1 life. |
bootdist(fit) | Parametric bootstrap. quantile() on it gives intervals for quantiles. |
fitdistcens(df, "weibull") | The MLE with censored data. Columns left and right; right = NA marks a part still running. |