### Install and Run StatsPAI Examples (Released Package) Source: https://github.com/brycewang-stanford/statspai/blob/main/examples/README.md Install the released StatsPAI package and then run the example scripts. This is the standard way to run examples after the package has been installed. ```bash python -m pip install statspai python examples/card_iv.py ``` -------------------------------- ### Install and Run StatsPAI Examples (Source Checkout) Source: https://github.com/brycewang-stanford/statspai/blob/main/examples/README.md Install StatsPAI in development mode with plotting dependencies and then run the example scripts. This is useful for development or when working directly from a source checkout. ```bash python -m pip install -e ".[dev,plotting]" python examples/card_iv.py python examples/did_mpdta.py python examples/rd_lee.py python examples/synth_prop99.py python examples/gmethods_timevarying.py python examples/nhefs_whatif.py ``` -------------------------------- ### Quickstart: Full Replication Pipeline Source: https://github.com/brycewang-stanford/statspai/blob/main/docs/guides/replication_workflow.md This snippet demonstrates the core two-step process for creating a replication archive: first generating a draft from data and analysis, then packaging it into a submission-ready zip file. Ensure `statspai` and `pandas` are installed. ```python import statspai as sp import pandas as pd df = pd.read_csv("training_panel.csv") # 1. Question → estimate → draft draft = sp.paper(df, "effect of trained on wage", treatment="trained", y="wage", fmt="qmd") # Quarto-native output # 2. Draft -> submission-oriented replication archive sp.replication_pack(draft, "submission.zip", code="analysis.py") ``` -------------------------------- ### StatsPAI Quick Example Source: https://github.com/brycewang-stanford/statspai/blob/main/README.md A comprehensive example demonstrating various StatsPAI functionalities including estimation, post-estimation, table generation, and robustness workflows. Ensure StatsPAI is installed with necessary dependencies. ```python import statspai as sp # --- Estimation --- card = sp.datasets.card_1995() # Card (1995) returns-to-schooling (n=3010) r1 = sp.regress("lwage ~ educ + exper", data=card, robust='hc1') r2 = sp.ivreg("lwage ~ (educ ~ nearc4) + exper", data=card) mp = sp.datasets.mpdta() # Callaway–Sant'Anna staggered DiD (n=2500) r3 = sp.did(mp, y='lemp', treat='first_treat', time='year', id='countyreal') lee = sp.datasets.lee_2008_senate() # Lee (2008) sharp RD (n=6558) r4 = sp.rdrobust(lee, y='voteshare_next', x='margin', c=0) nsw = sp.datasets.nsw_dw() # LaLonde / NSW-DW job training (n=2675) r5 = sp.dml(nsw, y='re78', treat='treat', covariates=['age', 'education', 're74', 're75']) r6 = sp.causal_forest("re78 ~ treat | age + education + re74 + re75", data=nsw) # --- Post-estimation --- sp.margins(r1, data=card) # Marginal effects sp.test(r1, "educ = exper") # Wald test sp.oster_bounds(card, y='lwage', treat='educ', controls=['exper']) # --- Tables (to Word / Excel / LaTeX) --- sp.modelsummary(r1, r2, output='table2.docx') sp.outreg2(r1, r2, r3, filename='results.xlsx') sp.sumstats(card, vars=['lwage', 'educ', 'exper'], output='table1.docx') # --- Robustness workflow --- sp.spec_curve(card, y='lwage', x='educ', controls=[[], ['exper'], ['exper', 'black']], se_types=['nonrobust', 'hc1']).plot() sp.robustness_report(card, formula="lwage ~ educ + exper", x='educ', winsor_levels=[0.01, 0.05]).plot() sp.subgroup_analysis(card, formula="lwage ~ educ + exper", x='educ', by={'Region': 'south', 'Race': 'black'}).plot() ``` -------------------------------- ### Setting up and Benchmarking GPU Acceleration on Colab Source: https://github.com/brycewang-stanford/statspai/blob/main/docs/guides/gpu_acceleration.md This example demonstrates how to install StatsPAI with JAX and CUDA support, verify the JAX device, and benchmark CPU vs. GPU performance for bootstrap methods on Google Colab. It includes creating a sample dataset and timing both sequential CPU execution and GPU-accelerated vmap'd bootstrap. ```python # In a Colab notebook with a GPU runtime selected !pip install -q statspai jax[cuda12] jaxlib import statspai as sp print(sp.fast.jax_device_info()) # Expect: jax: , default device: cuda # Build a benchmark dataset import numpy as np, pandas as pd rng = np.random.default_rng(0) n, n_firm = 1_000_000, 5_000 firm = rng.integers(0, n_firm, size=n) fe = rng.normal(size=n_firm)[firm] df = pd.DataFrame({ "y": 0.5 * rng.normal(size=n) + fe, "x1": rng.normal(size=n), "x2": rng.normal(size=n), "firm": firm, }) # Time CPU vs GPU import time t0 = time.perf_counter() for _ in range(2_000): _ = sp.fast.feols("y ~ x1 + x2 | firm", df, vcov="hc1") print(f"CPU sequential bootstrap (B=2000): {time.perf_counter() - t0:.1f}s") t0 = time.perf_counter() boot = sp.fast.feols_jax_bootstrap( "y ~ x1 + x2 | firm", df, n_boot=2_000, bootstrap="pairs", vmap_chunk_size=500, # tune up for big-HBM GPUs ) print(f"GPU vmap'd bootstrap (B=2000): {time.perf_counter() - t0:.1f}s") ``` -------------------------------- ### Install and Run Tests Source: https://github.com/brycewang-stanford/statspai/blob/main/README.md Clone the repository, install dependencies including development and plotting tools, and run tests. ```bash git clone https://github.com/brycewang-stanford/statspai.git cd statspai pip install -e ".[dev,plotting,fixest]" pytest ``` -------------------------------- ### Install StatsPAI and Optional Backend Source: https://github.com/brycewang-stanford/statspai/blob/main/docs/guides/migration-from-r.md Install the core StatsPAI library using pip. Optionally, install pyfixest for the HDFE backend to handle large-scale fixed-effects models. ```bash pip install statspai ``` ```bash # Optional HDFE backend (for sp.feols / sp.fepois at scale): pip install pyfixest ``` -------------------------------- ### Install StatsPAI Source: https://github.com/brycewang-stanford/statspai/blob/main/docs/getting-started.md Install the core StatsPAI library using pip. Optional extras can be installed with specific dependencies. ```bash pip install StatsPAI ``` ```bash pip install "StatsPAI[plotting]" # matplotlib / seaborn / plotly figures ``` ```bash pip install "StatsPAI[bayes]" # PyMC + ArviZ for Bayesian estimators ``` ```bash pip install "StatsPAI[tune]" # Optuna for tuned meta-learners / Auto-CATE ``` ```bash pip install "StatsPAI[rd-cct]" # rdrobust for exact CCT RD parity ``` ```bash pip install "StatsPAI[performance]"# JAX backend for fast feols / bootstrap ``` -------------------------------- ### Set Up Python Development Environment Source: https://github.com/brycewang-stanford/statspai/blob/main/CONTRIBUTING.md Create a virtual environment, activate it, and install the project in development mode with necessary dev dependencies. Also, install pre-commit hooks for code quality checks. ```bash # Create virtual environment python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate # Install in development mode pip install -e ".[dev]" # Install pre-commit hooks pre-commit install ``` -------------------------------- ### Setup and Imports Source: https://github.com/brycewang-stanford/statspai/blob/main/docs/guides/mixtape_ch09_did.md Import necessary libraries and set a random seed for reproducibility. ```python import numpy as np import pandas as pd import statspai as sp # Reproducible throughout the chapter: RNG_SEED = 2026 ``` -------------------------------- ### Install StatsPAI from Repository Checkout Source: https://github.com/brycewang-stanford/statspai/blob/main/docs/joss_reviewer_guide.md Install StatsPAI in editable mode with development and plotting extras from a local repository checkout. ```bash python -m pip install -e ".[dev,plotting]" ``` -------------------------------- ### Install StatsPAI Core Package Source: https://github.com/brycewang-stanford/statspai/blob/main/docs/joss_reviewer_guide.md Use these commands to create a virtual environment, activate it, upgrade pip, and install the core StatsPAI package. ```bash python -m venv .venv-joss source .venv-joss/bin/activate python -m pip install --upgrade pip python -m pip install statspai ``` -------------------------------- ### Install StatsPAI with Optional Dependencies Source: https://github.com/brycewang-stanford/statspai/blob/main/StatsPAI_full_data_analysis_skill/SKILL.md Install StatsPAI with specific extras for full functionality. Use `[fixest,plotting]` for high-dim FE and plotting, `[neural]` for neural causal models, and `[text]` for text-as-treatment. A one-shot install for all features is also available. ```bash pip install "statspai[fixest,plotting]" ``` ```bash pip install "statspai[fixest,plotting,neural,text]" ``` -------------------------------- ### Check Examples Coverage Source: https://github.com/brycewang-stanford/statspai/blob/main/plans/2026-06-21-statspai-hardening-month/README.md Verifies the coverage of example scripts, ensuring no more than the maximum allowed missing examples. This is part of the full release or manual full-CI gate before publishing. ```bash .venv/bin/python scripts/examples_coverage.py --check --max-missing 0 ``` -------------------------------- ### Check Example Execution Source: https://github.com/brycewang-stanford/statspai/blob/main/plans/2026-06-21-statspai-hardening-month/README.md Checks the execution of example scripts for failures. This is part of the full release or manual full-CI gate before publishing. ```bash .venv/bin/python scripts/check_example_execution.py --quiet --max-failures 0 ``` -------------------------------- ### Install StatsPAI Package Source: https://github.com/brycewang-stanford/statspai/blob/main/MIGRATION.md Install the StatsPAI package using pip. This is the first step to begin using the new library. ```bash pip install statspai ``` -------------------------------- ### Install Dependencies for Parity Checks Source: https://github.com/brycewang-stanford/statspai/blob/main/docs/joss_reviewer_guide.md Installs the package with development and parity extras, which includes doubleml-for-py. Use this to set up the environment for parity testing. ```bash python -m pip install -e ".[dev,parity]" ``` -------------------------------- ### Required Package Installations Source: https://github.com/brycewang-stanford/statspai/blob/main/StatsPAI_full_data_analysis_skill/SKILL.md Install `pyfixest` for `sp.feols`, `fepois`, `feglm`. Install `[neural]` for neural causal models and `[plotting]` for plotting functionalities. ```python sp.feols(...) without installing pyfixest ``` -------------------------------- ### Install StatsPAI with Optional Dependencies Source: https://github.com/brycewang-stanford/statspai/blob/main/docs/index.md Install the core StatsPAI package or with additional dependencies for plotting, specific estimators, or text analysis. Choose the installation that best suits your needs. ```bash pip install statspai # core ``` ```bash pip install 'statspai[plotting]' # matplotlib + seaborn ``` ```bash pip install 'statspai[fixest]' # pyfixest HDFE ``` ```bash pip install 'statspai[deepiv]' # PyTorch (Deep IV, TARNet) ``` ```bash pip install 'statspai[text]' # sentence-transformers for sbert ``` -------------------------------- ### Install Optional Dependency for R-parity Source: https://github.com/brycewang-stanford/statspai/blob/main/MIGRATION.md Shows the command to install the optional dependency `rdrobust` required for using `bwselect='cct'` in `sp.rdrobust`. This is a one-time installation. ```bash pip install statspai[rd-cct] # adds rdrobust>=1.3 ``` -------------------------------- ### Install Stata Packages Source: https://github.com/brycewang-stanford/statspai/blob/main/benchmarks/hdfe/README.md Install necessary Stata packages for running ppmlhdfe benchmarks. Requires Stata 17+. ```bash ssc install ppmlhdfe, replace ssc install reghdfe, replace ssc install ftools, replace ``` -------------------------------- ### Install Dependencies and Run Pytest Source: https://github.com/brycewang-stanford/statspai/blob/main/docs/joss_validation_dossier.md Installs development and plotting dependencies, then runs pytest on specified test files without coverage. Use this for a full repository checkout check. ```bash python -m pip install -e ".[dev,plotting]" python -m pytest tests/test_ols.py tests/test_did.py tests/test_registry.py -q --no-cov ``` -------------------------------- ### Install StatsPAI Skill via Copy Source: https://github.com/brycewang-stanford/statspai/blob/main/StatsPAI_full_data_analysis_skill/README.md Use this method to copy the skill directory to your Claude skills directory. ```bash cp -r StatsPAI_full_data_analysis_skill ~/.claude/skills/StatsPAI_skill ``` -------------------------------- ### Install StatsPAI with specific extras Source: https://github.com/brycewang-stanford/statspai/blob/main/docs/faq.md Install StatsPAI with optional dependencies for specific estimators like Bayesian methods, neural networks, or performance enhancements. ```bash pip install "StatsPAI[bayes]" ``` ```bash pip install "StatsPAI[neural]" ``` ```bash pip install "StatsPAI[performance]" ``` -------------------------------- ### Install StatsPAI Python Package (Recommended) Source: https://github.com/brycewang-stanford/statspai/blob/main/StatsPAI_full_data_analysis_skill/README.md Installs the core statspai package along with dependencies for fixest and plotting, covering the default pipeline. ```bash pip install "statspai[fixest,plotting]" ``` -------------------------------- ### sp.examples Source: https://github.com/brycewang-stanford/statspai/blob/main/docs/reference/smart.md Provides examples for causal inference methods. ```APIDOC ## sp.examples ### Description Provides examples for causal inference methods. This is a guide-friendly function used by agents and notebook workflows. ### Method Signature ```python sp.examples(...) ``` ### Parameters (Details not provided in source, refer to `::: statspai.examples` for more information) ``` -------------------------------- ### Get StatsPAI Version Source: https://github.com/brycewang-stanford/statspai/blob/main/SECURITY.md Use this command to retrieve the currently installed version of StatsPAI. This is required when reporting a vulnerability. ```python python -c "import statspai; print(statspai.__version__)" ``` -------------------------------- ### Get StatsPAI Version Source: https://github.com/brycewang-stanford/statspai/blob/main/SUPPORT.md Use this command to retrieve the currently installed version of the StatsPAI library. This is often required when reporting issues or seeking support. ```python python -c "import statspai as sp; print(sp.__version__)" ``` -------------------------------- ### Get R and clubSandwich Versions Source: https://github.com/brycewang-stanford/statspai/blob/main/docs/superpowers/plans/2026-04-27-htz-clubsandwich-parity.md Use these commands to retrieve the current R version and the installed version of the 'clubSandwich' package. This information is crucial for pinning fixture versions and auditing potential formula changes. ```bash R --version | head -1 ``` ```bash Rscript -e 'cat(as.character(packageVersion("clubSandwich")))' ``` -------------------------------- ### Choosing an Entry Point for Matching Source: https://github.com/brycewang-stanford/statspai/blob/main/docs/reference/matching.md Demonstrates how to use the sp.match() dispatcher for default nearest-neighbor propensity-score matching and balancing-weight estimators. Also shows how to use standalone functions for overlap weights and balance diagnostics. ```python import statspai as sp # Default nearest-neighbour propensity-score matching. r = sp.match( df, y="earnings", treat="training", covariates=["age", "education", "earnings_pre"], ) # Balancing-weight estimators are available through method=... r_ebal = sp.match(df, y="earnings", treat="training", covariates=["age", "education"], method="ebalance") # ...or as standalone functions with estimator-specific options. w = sp.overlap_weights(df, treat="training", covariates=["age", "education", "earnings_pre"]) diag = sp.balance_diagnostics(df, treat="training", covariates=["age", "education"], weights=w.weights) ``` -------------------------------- ### Quick Start: Generate and Run Baselines Source: https://github.com/brycewang-stanford/statspai/blob/main/benchmarks/hdfe/README.md Generate small and medium datasets, then run the baselines for these datasets. This is the primary command for initial benchmarking. ```bash cd benchmarks/hdfe python3 datasets.py --configs small medium python3 run_baseline.py --datasets small medium ``` -------------------------------- ### Install StatsPAI Source: https://github.com/brycewang-stanford/statspai/blob/main/README.md Install the StatsPAI package using pip. Optional dependencies can be installed for extended functionality. ```bash pip install statspai ``` ```bash pip install statspai[plotting] # matplotlib, seaborn ``` ```bash pip install statspai[fixest] # pyfixest for high-dimensional FE ``` ```bash pip install statspai[bayes] # PyMC + ArviZ for Bayesian estimators ``` ```bash pip install statspai[tune] # Optuna for tuned meta-learners / Auto-CATE ``` ```bash pip install statspai[rd-cct] # rdrobust for exact CCT RD parity ``` ```bash pip install statspai[deepiv] # PyTorch for DeepIV ``` ```bash pip install statspai[neural] # PyTorch for TARNet/CFRNet/DragonNet ``` ```bash pip install statspai[text] # sentence-transformers for sbert text embeddings ``` ```bash pip install statspai[performance] # JAX CPU backend for sp.fast.demean ``` -------------------------------- ### Quick Start: Classic Synthetic Control Method Source: https://github.com/brycewang-stanford/statspai/blob/main/docs/guides/synth.md Demonstrates loading a dataset and applying the classic synthetic control method using the `sp.synth()` dispatcher. Ensure the `statspai` library is imported. ```python import statspai as sp # Load the California Proposition 99 dataset (Abadie et al. 2010 style) df = sp.synth.california_tobacco() # Classic SCM (Abadie, Diamond & Hainmueller 2010) res = sp.synth( df, outcome='cigsale', unit='state', time='year', treated_unit='California', treatment_time=1989, method='classic', ) print(res.summary()) ``` -------------------------------- ### End-to-End Agent Workflow Example Source: https://github.com/brycewang-stanford/statspai/blob/main/docs/guides/agent_api.md Illustrates a complete agent workflow: reading a CSV, identifying study design, pre-flighting an estimator, running the estimation, summarizing results, and identifying missing robustness checks. ```python import statspai as sp import pandas as pd df = pd.read_csv("/path/to/dataset.csv") # 1. Identify the study design. design = sp.detect_design(df) # {'design': 'panel', 'confidence': 1.0, # 'identified': {'unit': 'firm_id', 'time': 'year'}, ...} # 2. Pre-flight a candidate estimator before paying for it. report = sp.preflight(df, 'did', y='sales', treat='treated', time='year') if report['verdict'] == 'FAIL': # The verdict carries structured failure info — agent can # decide whether to fix args, switch method, or stop. for c in report['checks']: if c['status'] == 'failed': print(f" blocked by {c['name']}: {c['message']}") raise SystemExit elif report['verdict'] == 'WARN': print("warnings present but proceeding") # 3. Run the estimator. If it raises a structured StatsPAIError, # the MCP layer surfaces error_kind + alternative_functions. result = sp.did(df, y='sales', treat='treated', time='year') # 4. One-line dashboard summary for logs / multi-result loops. print(result.brief()) # [Difference-in-Differences (2x2)] estimand=ATT est=0.412 # (se=0.087) 95% CI [0.241, 0.583] *** N=2,000 # 5. Reviewer checklist — which robustness checks are still # MISSING from the result's evidence base? audit_card = sp.audit(result) for c in audit_card['checks']: if c['status'] == 'missing' and c['importance'] == 'high': print(f" follow-up: {c['suggest_function']} ({c['name']})") # follow-up: sp.pretrends_test (parallel_trends) # follow-up: sp.honest_did (rambachan_roth) ``` -------------------------------- ### Release Process for v1.8.0 Source: https://github.com/brycewang-stanford/statspai/blob/main/benchmarks/hdfe/AUDIT.md Outlines the recommended steps for releasing version 1.8.0, including version bumping, tagging, and uploading to PyPI. This process is crucial for deploying the performance improvements. ```bash git tag v1.8.0 && git push --tags && twine upload dist/* ``` -------------------------------- ### Install Python Engines for Cross-Validation Source: https://github.com/brycewang-stanford/statspai/blob/main/docs/guides/cross_engine_validation.md Install in-process Python engines using pip. Ensure these packages are installed to leverage their cross-validation capabilities. ```bash pip install pyfixest linearmodels doubleml # in-process Python engines ``` -------------------------------- ### Install R Packages for Cross-Validation Source: https://github.com/brycewang-stanford/statspai/blob/main/docs/guides/cross_engine_validation.md Install necessary R packages for cross-validation. This involves installing R itself and then using the install.packages function within an R session. ```r # R cross-check: install R, then in R: install.packages(c("fixest","jsonlite")) ``` -------------------------------- ### End-to-End Econometric Workflow Source: https://github.com/brycewang-stanford/statspai/blob/main/docs/guides/data_mcp_ingestion.md This example demonstrates a complete workflow: ingesting World Bank data, detecting the econometric design, recommending an estimator, and performing cross-engine validation using StatsPAI. ```python import statspai as sp # 1. (the agent calls the World Bank MCP and gets `payload`) panel = sp.from_worldbank(payload, wide=True) # 2. Let StatsPAI read the shape and suggest an estimator. design = sp.detect_design(panel) rec = sp.recommend(panel, y="life_expectancy", design=design.design) # 3. Fit — and cross-validate the headline number across engines (see the # cross-engine validation guide). cv = sp.cross_validate( panel, "feols", formula="life_expectancy ~ gdp_pc | iso3 + year", treatment="gdp_pc", engines=["statspai", "pyfixest", "R::fixest"], ) print(cv.verdict) ``` -------------------------------- ### Build and Check Package Distribution Source: https://github.com/brycewang-stanford/statspai/blob/main/docs/joss_reviewer_guide.md Installs necessary build tools, creates a source distribution and wheel, and then checks the integrity of the distribution files. This verifies that the package is ready for distribution. ```bash python -m pip install build twine ``` ```bash python -m build ``` ```bash python -m twine check dist/* ``` -------------------------------- ### Install Noto CJK Font on Fedora/RHEL Source: https://github.com/brycewang-stanford/statspai/blob/main/StatsPAI_full_data_analysis_skill/SKILL.md Install the Noto CJK font package on Fedora or RHEL systems to resolve tofu character display issues in plots. This is a system-level font installation. ```bash sudo dnf install google-noto-sans-cjk-fonts ``` -------------------------------- ### Install Noto CJK Font on Debian/Ubuntu Source: https://github.com/brycewang-stanford/statspai/blob/main/StatsPAI_full_data_analysis_skill/SKILL.md Install the Noto CJK font package on Debian or Ubuntu systems to resolve tofu character display issues in plots. This is a system-level font installation. ```bash sudo apt install fonts-noto-cjk ``` -------------------------------- ### sp.dml API Mapping Examples Source: https://github.com/brycewang-stanford/statspai/blob/main/docs/guides/sp_dml_vs_doubleml.md Illustrates how to call sp.dml for different DoubleML models, showing the equivalent DoubleML classes and their parameters. ```python sp.dml(model='plr', ml_g=..., ml_m=...) ``` ```python sp.dml(model='irm', ml_g=..., ml_m=...) ``` ```python sp.dml(model='pliv', instrument=..., ml_g=..., ml_m=..., ml_r=...) ``` ```python sp.dml(model='iivm', instrument=..., ml_g=..., ml_m=..., ml_r=...) ``` -------------------------------- ### Compare All Synth Methods Source: https://github.com/brycewang-stanford/statspai/blob/main/docs/guides/synth.md Run and compare all available synthetic control methods at once. Use the plot method to visualize counterfactuals and summary_table to get ATT and RMSPE. The synth_recommend function helps auto-select the best method. ```python comp = sp.synth_compare(df, outcome='cigsale', unit='state', time='year', treated_unit='California', treatment_time=1989) comp.plot() # overlay all counterfactuals comp.summary_table() # ATT, pre-RMSPE, p-value per method best = sp.synth_recommend(comp) # auto-pick best by pre-fit + robustness ``` -------------------------------- ### Quick Start: Re-render Report Only Source: https://github.com/brycewang-stanford/statspai/blob/main/benchmarks/hdfe/README.md Re-render the benchmark report without re-running the benchmarks. Useful for updating the report after changes. ```bash python3 run_baseline.py --datasets small medium --report-only ``` -------------------------------- ### Exporting Full Session Bundle Source: https://github.com/brycewang-stanford/statspai/blob/main/StatsPAI_full_data_analysis_skill/SKILL.md Create a comprehensive replication appendix that includes summary statistics, balance tables, regression tables, and prose in a single file. ```APIDOC ## Exporting Full Session Bundle ### Description Creating a replication appendix that mixes summary statistics, balance tables, multiple regression tables, headings, and prose in a single file, equivalent to Stata 15 `collect`. ### API - `c = sp.collect("Paper title", template="aer")` - `c.add_heading("§1. Descriptives", level=...) - `c.add_summary(df, vars=..., stats=..., labels=...) - `c.add_balance(df, treatment=, variables=..., weights=..., test=...) - `c.add_regression(M1, M2, ..., title="Table 2", **regtable_kwargs) - `c.add_table(result) - `c.add_text("Notes ...")` - `c.save("paper.docx")` (auto-detect by extension; `.xlsx`/`.tex`/`.md`/`.html`/`.txt` all work) ### Hot kwargs for `add_regression` `template`, `coef_labels`, `model_labels`, `panel_labels`, `dep_var_labels`, `stats`, `stars`, `add_rows` ### Example Usage ```python c = sp.collect("My Replication Paper", template="qje") c.add_heading("§1. Descriptive Statistics", level=1) c.add_summary(df_descriptives, vars=["age", "income"]) c.add_heading("§2. Regression Analysis", level=1) c.add_regression(M1, M2, title="Table 2", template="qje", drop=["Intercept"]) c.add_text("Standard errors are in parentheses.") c.save("replication_appendix.docx") ``` ``` -------------------------------- ### Install Spatial Dependencies Source: https://github.com/brycewang-stanford/statspai/blob/main/plans/2026-04-15-sp-01-s1.1-spatial-core.md Add the 'spatial' extra to pyproject.toml to install necessary dependencies for spatial analysis. This includes geopandas, libpysal, shapely, and matplotlib. ```toml [project.optional-dependencies] spatial = ["geopandas>=0.14", "libpysal>=4.10", "shapely>=2.0", "matplotlib>=3.8"] ``` -------------------------------- ### Build Documentation Source: https://github.com/brycewang-stanford/statspai/blob/main/docs/joss_reviewer_guide.md Builds the project's documentation using MkDocs with strict checking enabled. This ensures the documentation is well-formed and error-free. ```bash python -m mkdocs build --strict ``` -------------------------------- ### Install StatsPAI Python Package (Full Skill) Source: https://github.com/brycewang-stanford/statspai/blob/main/StatsPAI_full_data_analysis_skill/README.md Installs the complete statspai package, including dependencies for fixest, plotting, neural networks, and text analysis. ```bash pip install "statspai[fixest,plotting,neural,text]" ``` -------------------------------- ### Metalearner Estimator Example Source: https://github.com/brycewang-stanford/statspai/blob/main/docs/guides/choosing_ml_causal_estimator.md Example of using the Metalearner estimator to estimate heterogeneous treatment effects (CATE). It reports the population ATE and provides per-unit CATEs. ```python q = sp.causal_question( treatment='trained', outcome='wage', design='metalearner', estimand='CATE', covariates=['age', 'edu', 'exp'], data=df, ) r = q.estimate(learner='dr') # default cate = r.underlying.model_info['cate'] # per-unit tau(x_i) ``` -------------------------------- ### Wall-clock Time Comparison (pre-fix vs post-fix) Source: https://github.com/brycewang-stanford/statspai/blob/main/benchmarks/hdfe/AUDIT.md Table comparing the end-to-end wall-clock time for 'boottest' before and after the audit fixes, showing significant performance gains. ```text | metric | pre-fix | post-fix | |-----------------------------------|------------:|-----------:| | `boottest` end-to-end | ~3 s¹ | **~0.48 s** | ``` -------------------------------- ### TMLE Estimator Example Source: https://github.com/brycewang-stanford/statspai/blob/main/docs/guides/choosing_ml_causal_estimator.md Example of using the Targeted Maximum Likelihood Estimator (TMLE). This estimator is doubly robust and semiparametrically efficient, suitable for binary outcomes. ```python q = sp.causal_question( treatment='trained', outcome='employed', # binary outcome design='tmle', covariates=['age', 'edu', 'exp'], data=df, ) r = q.estimate() ``` -------------------------------- ### DML Estimator Example Source: https://github.com/brycewang-stanford/statspai/blob/main/docs/guides/choosing_ml_causal_estimator.md Example of using the DML estimator for causal inference. This code automatically selects the appropriate sub-model based on the treatment and instrument variables. ```python import statspai as sp q = sp.causal_question( treatment='trained', outcome='wage', design='dml', covariates=['age', 'edu', 'exp', 'tenure', 'industry'], data=df, ) r = q.estimate() # auto-picks model='irm' print(r.summary()) ``` -------------------------------- ### Initialize and Analyze a Social Network Graph Source: https://github.com/brycewang-stanford/statspai/blob/main/docs/guides/social_network_analysis.md Demonstrates initializing a graph from a built-in dataset and performing basic network analyses like summary and centrality. ```python import statspai as sp g = sp.karate_club() # Zachary (1977), 34 nodes / 78 edges sp.network_summary(g) # structural summary sp.centrality(g, kind="all") # per-node centrality table sp.community_detection(g) # Louvain partition ``` -------------------------------- ### JAX Backend Raises Error When Unavailable Source: https://github.com/brycewang-stanford/statspai/blob/main/benchmarks/hdfe/PHASE7_VERIFY.md Tests that the JAX backend correctly raises a RuntimeError if JAX is not installed, providing an informative error message and installation hint. ```python test_jax_when_unavailable_raises ... SKIPPED (jax is installed locally) ```