Specification_Curve
Project description
Specification Curve
Specification Curve is a Python package that performs specification curve analysis; it helps with the problem of the "garden of forking paths" (many defensible choices) when doing analysis by running many regressions and summarising the effects in an easy to digest chart.
Go to the full documentation for Specification Curve.
Quickstart
You can try out specification curve right now in Google Colab.
Here's an example of using Specification Curve.
# import specification curve
import specification_curve as specy
# Generate some fake data
# ------------------------
import numpy as np
import pandas as pd
# Set seed for random numbers
seed_for_prng = 78557
# prng=probabilistic random number generator
prng = np.random.default_rng(seed_for_prng)
n_samples = 400
# Number of dimensions
n_dim = 4
c_rnd_vars = prng.random(size=(n_dim, n_samples))
y_1 = (0.4*c_rnd_vars[0, :] - # THIS IS THE TRUE VALUE OF THE COEFFICIENT
0.2*c_rnd_vars[1, :] +
0.3*prng.standard_normal(n_samples))
# Next line causes y_2 ests to be much more noisy
y_2 = y_1 - 0.5*np.abs(prng.standard_normal(n_samples))
# Put data into dataframe
df = pd.DataFrame([y_1, y_2], ['y1', 'y2']).T
df["x_1"] = c_rnd_vars[0, :]
df["c_1"] = c_rnd_vars[1, :]
df["c_2"] = c_rnd_vars[2, :]
df["c_3"] = c_rnd_vars[3, :]
# Specification Curve Analysis
#-----------------------------
sc = specy.SpecificationCurve(
df,
y_endog=['y1', 'y2'],
x_exog="x_1",
controls=["c_1", "c_2", "c_3"])
sc.fit()
sc.plot()
Grey squares (black lines when there are many specifications) show whether a variable is included in a specification or not. Blue or red markers and error bars show whether the coefficient is positive and significant (at the 0.05 level) or red and significant, respectively.
Installation
You can install Specification Curve via pip:
$ pip install specification-curve
To install the development version from git, use:
$ pip install git+https://github.com/aeturrell/specification_curve.git
Citing Specification Curve
@misc{aeturrell_2022_7264033,
author = {Arthur Turrell},
title = {Specification Curve: v0.3.1},
month = oct,
year = 2022,
publisher = {Zenodo},
version = {v0.3.1},
doi = {10.5281/zenodo.7264033},
url = {https://doi.org/10.5281/zenodo.7264033}
}
Using Specification Curve in your paper? Let us know by raising an issue beginning with "citation".
License
Distributed under the terms of the MIT license.
Credits
The package is built with poetry, while the documentation is built with Jupyter Book. Tests are run with nox.
Similar Packages
In RStats, there is specr (which inspired many design choices in this package) and spec_chart. Some of the example data in this package is the same as in specr, but please note that results have not been cross-checked across packages.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file specification_curve-0.3.2.tar.gz
.
File metadata
- Download URL: specification_curve-0.3.2.tar.gz
- Upload date:
- Size: 42.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d170dd8b9fe38727431ef1598ef97f8ac672ec4d66ff90fe2745e74fc18f68a |
|
MD5 | 55c29112ee25de40620c9a48e2ba25f9 |
|
BLAKE2b-256 | 4fc45a526d61f39c4a16c3d07dbaaa721bcceb7cdd8151df78edcce07ef4c038 |
File details
Details for the file specification_curve-0.3.2-py3-none-any.whl
.
File metadata
- Download URL: specification_curve-0.3.2-py3-none-any.whl
- Upload date:
- Size: 39.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 127edcc4fe6eb2353ec00e31db31e3c9035790379f26acd7d4986d0d892af87b |
|
MD5 | 886e166c37a26d26c3f0168bbda65c56 |
|
BLAKE2b-256 | 308067b8898d430568545e0d77c6a249f0577290e8831e88a89d0d548af09cb0 |