This page runs small versions of the examples from the repository notebooks. The original notebooks use larger data to demonstrate scale; these examples use compact synthetic tables so the documentation renders quickly while still showing real estimator output.
Setup
Show code
import osimport tempfileimport duckdbimport numpy as npimport pandas as pdimport duckreg.estimators as estimators_modulefrom duckreg.estimators import ( DuckDML, DuckDoubleDemeaning, DuckLogisticRegression, DuckMultinomialLogisticRegression, DuckMundlak, DuckMundlakEventStudy, DuckPoissonMultinomialRegression, DuckPoissonRegression, DuckRegression,)from duckreg.regularized import DuckRidgepd.set_option("display.precision", 4)rng = np.random.default_rng(2026)tmpdir = tempfile.mkdtemp(prefix="duckreg_docs_")# Keep bootstrap examples readable in rendered docs.estimators_module.tqdm =lambda iterable, *args, **kwargs: iterabledef write_table(db_path, table_name, df): conn = duckdb.connect(db_path) conn.register("df", df) conn.execute(f"CREATE OR REPLACE TABLE {table_name} AS SELECT * FROM df") conn.close()
This is the core DuckRegression workflow from notebooks/introduction.ipynb: fit on compressed covariate cells, then compute analytic HC1-style standard errors.
Show code
m = DuckRegression( db_name=linear_db, table_name="data", formula="Y ~ D + f1 + f2", cluster_col="", n_bootstraps=0, seed=42,)m.fit()m.fit_vcov()results = m.summary()pd.DataFrame( {"point_estimate": results["point_estimate"],"standard_error": results["standard_error"], }, index=["Intercept", "D", "f1", "f2"],)
point_estimate
standard_error
Intercept
0.9488
0.0340
D
2.0143
0.0257
f1
0.1240
0.0025
f2
-0.0765
0.0056
The compressed table is much smaller than the raw table because the regressors are discrete.