Validation¶
What the numbers of apatools were compared with, and where they intentionally differ from the benchmark. The same information, in the context of each method, is on the module pages; this page is the overview.
Principles¶
An independent reference wherever there is one. R is the reference implementation of much of what apatools reports (
plm,splm,spatialreg,spdep,lmtest,MASS,lme4,lavaan,coefficientalpha,irr). Where there is none, the reference is the definition: a dense matrix inverse for a trace series, OLS with dummies for a within estimator, a likelihood written out in numpy for an ML fit, finite differences for a gradient.Disagreements are findings. Comparing with R and with the literature found four errors in what the engines or earlier versions of apatools reported: the Anselin LM tests of spreg’s panel module (squared trace, wrong variance), the Breusch–Pagan and Koenker–Bassett tests of
slm_tests(squares of the regressors instead of the regressors), the AIC and BIC of the spatial error model (lambdanot counted) and the standard error of Fleiss’ kappa (2–3 times too small). All are fixed and listed in the changelog.Conventions are documented, not hidden. Where an engine’s convention differs from R’s (degrees of freedom, the count of parameters in the AIC, the sidedness of a p-value) apatools keeps one and says which; the difference is pinned in the tests so that a change is noticed.
Tests are checked by breaking the code. A new test is accepted when deliberately wrong code makes it fail.
What was compared with what¶
module |
compared with |
what |
|---|---|---|
|
R: base |
OLS diagnostics (1e-6), GLM dispersion and goodness of fit (1e-8), RLM coefficients (0.2 %), mixed models (0.5 %) |
|
R: |
ML estimates, standard errors, log-likelihood, LM tests, Moran’s I, heteroskedasticity tests |
|
dense inverse of |
point estimates (1e-6 to 1e-8), gradients of the delta method, standard errors (within the noise of the simulations) |
|
R: |
coefficients, standard errors, R², F, tests of effects, LM tests, spatial ML models |
|
linearmodels, spreg, OLS with dummies, two numpy likelihoods |
the R engine’s conversion into apatools’ objects |
|
lavaan through the lavaan engine |
loadings, regressions, standardized estimates and their standard errors, fit indices |
|
lavaan (bifactor, delta method), |
estimates (1e-5), standard errors (1–2 %) |
|
the formulas of |
|
|
the textbook formulas and the APA rules |
round trips of the conversions |
|
the example of psmpy |
balance improves, reproducible with a seed |
Where apatools does not mirror the R benchmark¶
These are the differences that change a printed number, by module; the reasons are on the module pages.
module |
quantity |
apatools |
R |
tested in |
|---|---|---|---|---|
|
AIC, BIC |
do not count the error variance |
count it (+2, +log n) |
|
|
Moran’s I of OLS residuals, p-value |
two-sided |
one-sided ( |
|
|
fixed-effects standard errors |
|
|
|
|
adjusted R² |
|
|
|
|
random-effects standard errors, Hausman test |
standard errors slightly smaller (up to 3 %) |
|
|
|
spatial lag / error coefficient names |
|
|
|
|
R² of random effects |
pseudo R² |
R² of the transformed model |
— |
|
covariance of spatial parameter and coefficients |
spreg: full matrix; splm: block-diagonal |
as splm |
— |
|
mixed models, RLM, GLM influence |
statsmodels’ optimizers and tolerances |
lme4, MASS, base R |
|
|
GFI, AIC, BIC, log-likelihood, standardized residual covariances |
semopy: its own definitions |
lavaan: the usual ML values |
|
|
omega of items with unequal variances |
standardized items by default |
raw sum score |
|
What was not compared with R¶
There is no standard R function for: the Hosmer–Lemeshow and Cameron–Trivedi tests as implemented, the randomized
quantile residual test, the group Cook’s distance of mixed models, the approximate tests of robust models, the
Baltagi–Song–Koh joint and spatial tests (splm::bsktest failed with the Matrix package installed here; they are
checked through their relations to plmtest and slmtest), the LR test of time effects with its degrees-of-freedom
scaling, and the permutation Moran test. These are validated by their definitions and by simulations of their size and
power, which are described on the module pages.
Running the checks¶
pytest tests # everything possible on this machine
APATOOLS_RSCRIPT=no-such-rscript pytest # the suite without R: the R tests are skipped
The R tests need Rscript and the packages plm, splm, spdep, spatialreg, lmtest, MASS, lme4, lavaan,
semPlot and coefficientalpha; tests/r_reference.py finds them and skips the test when one is missing. The
continuous-integration job with R runs the lavaan tests.