Getting started¶
Install¶
pip install apatools
Python 3.10 or newer. The development version: pip install git+https://github.com/ellariel/apatools.git.
The base installation is light: it contains apatools.calc and apatools.format and needs only numpy and scipy. Every
other module has its own, heavier dependencies and is installed through an extra of the same name; importing a module
without its extra gives an ImportError that names the extra to install. Extras can be combined, e.g.
pip install "apatools[lm,plm]".
install |
module |
brings in |
|---|---|---|
|
|
numpy, scipy |
|
|
pandas, statsmodels |
|
|
pandas, statsmodels, spreg, libpysal |
|
|
pandas, spreg, libpysal, patsy |
|
|
pandas, semopy |
|
|
pandas, psmpy |
|
|
pandas, scipy, statsmodels |
|
|
the |
|
|
the |
|
|
the |
|
everything |
all of the above |
R engines¶
Three engines run in R, started as a subprocess (Rscript); no Python package is needed besides the extra of the
module (see engines for what they are good for and how R is found):
used by |
R packages |
|---|---|
|
|
|
|
|
|
Install R, then in R: install.packages(c("lavaan", "semPlot", "plm", "splm", "spdep")).
The shape of the API¶
Every modelling module has the same four parts, so that what you learn for one carries over:
a fitting function (
lm,slm,plm,sem,psm) that takes a data frame and returns(results, metrics)(semandpsmreturn their own tables), whereresultsare the engine’s fitted objects andmetricsa list of dictionaries with fit statistics. Arguments of the engine are passed as<model>_<stage>_<argument>, e.g.ols_fit_cov_type="HC1"orslm_fe_model_method="LU".a report function (
lm_report,slm_report,plm_report,sem_report) that turns them into APA-style tables: coefficient, standard error, test statistic, p-value (formatted without a leading zero,<.001), significance stars, confidence limits and a one-line fit summary in the first row.a tests function (
lm_tests,slm_tests,plm_tests) that collects the specification tests in one tidy table (columnstest,model,statistic,df,p-value,report).for spatial lag models, an effects function (
slm_effects,plm_effects) with the direct, indirect and total effects.
Pass format_pval=True and add_stars=True to get strings for the manuscript; the default of the tests and effects
functions is raw numbers, from which the stars are always computed.