An estimate is useful only if the software combines the data and prior information correctly and reports uncertainty on the intended scale. This chapter asks three practical questions: does estimation reproduce a known answer, do the model-comparison statistics use the right information, and do the diagnostics identify unreliable sampling?
Maximum likelihood estimation (MLE) selects the parameters that best explain the observations. Maximum a posteriori estimation (MAP) also incorporates prior information and selects the highest point of the posterior. Bayesian sampling describes the whole posterior, including its uncertainty. The generalized method of moments (GMM) chooses parameters that satisfy specified relationships between model and sample quantities, with weighting when those relationships cannot all be met exactly.
Seven positive observations are chosen so that their base-10 logarithms are 1.1, 1.4, 1.7, 2.0, 2.3, 2.6, and 2.9. Their log-space mean is exactly 2 and the sum of squared deviations from that mean is 2.52. This small dataset allows the reference estimates to be calculated directly, without fitting software.
The test fits the same observations by MLE, flat-prior MAP, and Bulletin 17C GMM. The flat-prior comparison explicitly disables the optional Jeffreys scale prior: it asks whether MAP reproduces MLE when the prior contributes no preference within the allowed range. Exact likelihood inference divides by
| Calculation | Independent target in log space | Recorded result and meaning |
|---|---|---|
| MLE and flat-prior MAP mean | 2.000000 | Both fitted points satisfy the analytical 95% joint likelihood-ratio and standard-error checks. Their data log likelihoods agree within |
| MLE and flat-prior MAP standard deviation | 0.600000 | The likelihood scale uses the seven-observation divisor. |
| GMM mean | 2.000000 | Within |
| GMM standard deviation | 0.648074 | Within |
The different standard deviations are the intended consequence of the two finite-sample formulas. They are not evidence of an inconsistent logarithm or a failed fit. All comparisons passed under their respective rules.
The next comparison adds Normal information about the mean. Its center is
| Prior or equivalent GMM penalty | Center and width | Behavior tested |
|---|---|---|
| Flat | No preference over the fitted region | Reproduce the unpenalized estimate and uncertainty. |
| Wide and centered | Center 2; standard deviation 100 times the unpenalized standard error | Add very little information. |
| Narrow and centered | Center 2; standard deviation 0.1 times the unpenalized standard error | Reduce uncertainty without moving the preferred location. |
| Narrow and shifted | Center two unpenalized standard errors above 2; same narrow width | Move the estimate toward the prior and change its uncertainty. |
For each case, BestFit refits both mean and scale. Independently derived equations and the curvature of the objective supply the reference fit and covariance. The tests also compare the fitted interval with the familiar fixed-variance information-combination reference,
where
The four-regime comparisons passed. MAP fits satisfy the analytical joint 95% criterion; GMM location errors satisfy the 1.96-standard-error criterion. Covariance entries agree with the independent calculations within the larger of
Three experiments isolate the general estimation routines. Each contains 1,000 observations or paired rows. The distribution chapter gives the additional family-specific recovery designs.
| Estimation experiment | Test setup and procedure | Result |
|---|---|---|
| Bayesian Normal analysis | Generate a Normal sample with mean 100 and standard deviation 15, using seed 12345; estimate both parameters with the production Bayesian configuration. | Both generating values are inside the central 95% posterior intervals; each monitored parameter has |
| Normal MAP | Generate mean 100 and standard deviation 10; fit the posterior mode and calculate uncertainty from its curvature. | Both generating values are within 1.96 estimated standard errors of the fitted values. |
| Two-step GMM | Generate responses with mean 2 and standard deviation 1, paired with independent Uniform(-1,1) auxiliary values, using seed 24680. Fit the two conditions that the mean residual and the mean auxiliary-value-weighted residual are zero. | The generating mean 2 is within 1.96 standard errors, using the two-step sandwich covariance. |
The GMM covariance calculation combines the sensitivity of the moment equations with their observed variability; this is why it is called a sandwich covariance. The known mean is used only to generate and assess the data, not supplied as the fitted answer.
Thirteen-family MLE recovery checks complement these general experiments. Most compare generating values with standard-error intervals. Generalized Normal and Generalized Logistic use 95% profile intervals; Generalized Pareto additionally checks its 0.99 quantile. A separate Ln-Normal calculation compares the fitted result with the exact natural-log mean and standard deviation of the same sample. All meet their specified criteria. Parameter tables and the distinction between original and logarithmic scales appear in the distribution chapter.
A separate experiment uses 1,000 observations generated with mean 100 and standard deviation 15, but treats the observation standard deviation as known. The prior for the unknown mean is Normal with center 120 and standard deviation 5. The intentionally displaced prior tests whether the data and prior are combined with the correct relative weights.
For this known-scale case, equation (E.2) gives an exact posterior: use the sample mean for
The test samples the posterior and compares its mean, standard deviation, and two central 95% endpoints with this exact Normal answer. The accepted absolute differences are 0.05, 0.03, and 0.10, respectively; all passed. The result verifies the shape and width of a posterior with informative prior input, not merely whether an interval happens to contain the generating mean.
A profile calculation varies one parameter and refits the other parameters at each step. This matters when parameters are related: holding the other parameters fixed can make an interval too narrow.
The reference example uses a smooth two-parameter quadratic log likelihood with correlation 0.8 and an optimum at zero. At a fixed first parameter bbmle supplies an independent numerical calculation at eight equally spaced midpoints from -3.5 to 3.5.
| Quantity | Independent reference | BestFit comparison |
|---|---|---|
| Profile at |
-0.125 | Agrees within |
| Profile at |
-1.125 | Agrees within |
| Profile at |
-6.125 | Agrees within |
| 90% profile interval | -1.644854 to 1.644854 | Both endpoints agree within |
| Interval if the second parameter were incorrectly held fixed | -0.986912 to 0.986912 | Comparison illustrates the narrower conditional slice; it is not the reported profile interval. |
All eight profile values, the optimum, and the interval passed for MLE and for MAP with a flat prior. An informative-prior variant checks that MAP refits using the complete posterior, and a restricted-support variant checks ten valid points on a 16-point grid. Invalid points are not included in the numerical agreement claim. The 90% level is part of this particular external comparison; it is not the 95% recovery rule used elsewhere.
Figure E.1. Allowing the second parameter to adjust produces the wider profile interval. The curves and points show the independent analytical and R references; BestFit's tested profile values agree within $10^{-10}$. They are not plotted as separately retained BestFit estimates.
Covariance is checked independently on ten Normal observations: 1.2, 0.7, 1.9, 1.1, 0.4, 1.6, 0.9, 1.3, 1.0, and 1.5, with known standard deviation 0.5. The reference mean is 1.16, its variance is
The deviance information criterion (DIC) and widely applicable information criterion (WAIC) balance fit against model complexity. They help compare candidate models fitted to the same data; a small value by itself does not establish that a model is physically appropriate.
The setup contains five Normal observations, 2.4, 2.9, 3.5, 4.1, and 4.8, and forty fixed candidate pairs of mean and standard deviation. Using the same pairs in both calculations removes random sampling differences. BestFit and R evaluate how well each pair explains each observation, producing 200 individual log-likelihood values. The tests compare those values first and then compare the summary statistics. The independent packages are R BayesianTools 0.1.9 and loo 2.10.0.
| Quantity | External result | BestFit tolerance | Result |
|---|---|---|---|
| Mean deviance | 13.0457484595105 | 1e-10 absolute |
Passed |
| Deviance at posterior mean | 12.6377539947693 | 1e-10 absolute |
Passed |
| Effective DIC parameters | 0.407994464741220 | 1e-10 absolute |
Passed |
| DIC | 13.4537429242518 | 1e-10 absolute |
Passed |
| lppd | -6.35851654848624 | 1e-10 absolute |
Passed |
| Effective WAIC parameters | 0.351001866165060 | 1e-10 absolute |
Passed |
| WAIC | 13.4190368293026 | 1e-10 absolute |
Passed |
All individual and summary comparisons passed. Here deviance is minus twice the log likelihood; lppd is the sum of log predictive densities for the observed data. The effective-parameter terms measure the complexity penalty, which need not be an integer. Agreement in both components establishes more than agreement in the final DIC or WAIC total.
Two additional checks fit 100 Normal observations generated with mean 100 and standard deviation 10. They independently recompute the Akaike information criterion (AIC) and Bayesian information criterion (BIC) at the MAP estimate. Both use the data likelihood, excluding the prior density, and agree within
Leave-one-out cross-validation asks how well a model predicts an observation when that observation is left out of the fit. Pareto-smoothed importance sampling (PSIS) approximates this comparison by reweighting the available posterior draws. It also reports when those weights are too uneven for a reliable approximation.
The same five observations and forty fixed parameter pairs were passed through R loo. BestFit compares the prediction score for each omitted observation, its smoothed weights, the Pareto shape diagnostic
| Quantity | R loo result |
BestFit tolerance | Result |
|---|---|---|---|
| ELPD-LOO | -6.70094841652149 | 1e-10 absolute |
Passed |
| Effective LOO parameters | 0.342431868035246 | 1e-10 absolute |
Passed |
| LOOIC | 13.4018968330430 | 1e-10 absolute |
Passed |
| SE(LOOIC) | 1.95756902272540 | 1e-10 absolute |
Passed |
All aggregate comparisons passed. The five reference Pareto values are 0.0682, -0.0302, 0.4116, 0.3062, and 0.3209. With only forty draws, the applicable reliability threshold is 0.375804. The third observation therefore requires attention even though its
Six additional sets of 256 importance ratios test progressively heavier tails and a degenerate case. These represent increasingly uneven contributions from the posterior draws. Smoothed weights,
Exact leave-one-out refits, moment matching, and chain-relative-efficiency adjustment are not implemented. The influence diagnostic compares the Pareto shape and the sample-size-dependent reliability threshold with R loo. This check is separate from the deterministic formatting and serialization of diagnostic results.
The GMM specification test asks whether two proposed moment relationships can both be satisfied by one parameter. Ten response values are 0.2, 0.5, 0.7, 1.1, 1.4, 1.8, 2.1, 2.6, 3.2, and 4.0. They are paired, in that order, with auxiliary values 0.5, 1.0, and so on through 5.0. The two sample moments are the average residual
BestFit and R gmm 1.9.1 fit these same data twice. The first fit weights the two moment discrepancies equally. The second updates the weights using their covariance. For the first fit, the independent optimum and weighted discrepancy
For efficient two-step GMM, the reference values are
| Comparison | R or analytical value | Tolerance | Result |
|---|---|---|---|
| Fixed-weight variance | 0.145652392138090 | 1e-8 |
Passed |
| Efficient two-step variance | 0.132600447299456 | 1e-8 |
Passed |
| Hansen |
10.0755078518454 | 1e-7 |
Passed |
| Hansen p-value | 0.00150253202968641 | 1e-8 |
Passed |
The variance and specification comparisons all passed. The small p-value indicates that these particular data are inconsistent with both moment conditions holding at once; a correct test should detect that disagreement. It does not indicate a software failure. The covariance reference is also reconstructed directly from the independent moment derivatives and moment variability.
BestFit does not label an arbitrary fixed-weight discrepancy as a Hansen test: the first fit's Hansen statistic and p-value are unavailable. The chi-square interpretation applies to the efficient second-step weighting used in the second fit.
An optimizer needs the direction in which its objective improves, called the gradient. A controlled GMM example uses the moment
Influence diagnostics ask which observations most affect an estimate or its uncertainty. On the seven log-space observations used above, each observation's fit influence, variance influence, and combined leverage are compared with an independent R gmm calculation. Every value agrees within
One influence check records an accepted limitation. Removing one value from a sample changes the sample mean by a known amount, so exact deletion provides a direct comparison. The test checks the seven-value sample and then adds an unusually high eighth value. BestFit and exact deletion both identify the added observation as most influential, but the diagnostic's magnitude differs from exact deletion by more than 25% on the tested scale. It can identify the leading observation in this example; it must not be interpreted as the exact amount the estimate would change if that observation were removed.
Prior information can describe each parameter separately or describe how two parameters relate. To distinguish those cases, the test gives two parameters separate Uniform(-1,1) priors and also specifies a narrow conditional relationship requiring them to be close together.
The generic prior sampler produces 20,000 pairs. The check compares their behavior with independent Uniform draws: absolute correlation is below 0.03, mean squared separation exceeds 0.60, and fewer than 12% of pairs lie within 0.1 of one another. These findings agree with separate sampling; the independent mean squared separation is
This is the second accepted limitation. The additional joint relationship is not represented by these prior draws. A calculation that needs the full coupled prior, such as a corresponding prior-predictive analysis, cannot treat them as draws from that joint distribution.
Nine fixed collections of four chains test the diagnostic calculations themselves. Some represent well-mixed draws; others deliberately include a shifted chain, unequal spread, strong serial dependence, or a chain stuck in the tail. BestFit and R posterior 1.7.0 receive the identical draws. This isolates the diagnostic formula from the sampler that originally produced the values.
The tests compare rank-normalized split
| Chain design | Draws per chain used | R reference |
R reference conservative ESS | Interpretation |
|---|---|---|---|---|
| Independent Normal draws | 200 | 0.99873 | 774.55 | Little loss of information to chain dependence. |
| One shifted chain | 200 | 1.05158 | 95.16 | The small ESS flags limited useful information. |
| Different chain spreads | 100 | 1.28101 | 447.63 | Chain disagreement is detected by |
| Serial dependence of 0.85 | 240 | 1.04057 | 53.52 | Many stored draws provide much less independent information. |
| One chain stuck in the upper tail | 240 | 1.07719 | 11.70 | Tail information is especially poor. |
| Rounded values with ties | 160 | 1.00049 | 578.87 | Repeated values receive consistent ranks. |
| Initial 80 warmup values discarded | 160 | 0.99901 | 638.26 | Diagnostics use the retained portion of each chain. |
| Repeating integer pattern | 64 | 2.86020 | 5.25 | Severe disagreement is detected. |
| Constant chains | 40 | Unavailable | Unavailable | No spurious convergence or ESS value is reported. |
Every finite
Two further tests examine specific sampler calculations. For the No-U-Turn Sampler (NUTS), a two-parameter posterior has an independently derived gradient. At parameter values 1.25 and -0.75, the expected gradient components are -1.50 and 0.50; both agree within
For adaptive random-walk Metropolis-Hastings (ARWMH), a controlled model rejects every proposal. A rejected proposal leaves the chain at its previous state, and that repeated state must still contribute to the adaptive covariance. The configured four-chain run requires 125 recorded transitions per chain; every acceptance count is zero and every covariance history contains exactly 125 states. Both sampler checks passed. Together with the recovery and diagnostic comparisons, they check behavior that would be missed by merely confirming that a sampling run finishes.