A package for misclassification error correction in regression using validation data
Project description
validation_correction
A Python package for measurement error correction in regression analysis using validation data.
Installation
pip install validation_correction
Usage
The package provides a simple interface for correcting measurement error in both linear and logistic regression using validation data. The correction is implemented using a bootstrap procedure that:
- Resamples the validation data to estimate misclassification probabilities
- Applies these probabilities to a bootstrap sample of the research data
- Repeats this process to obtain valid confidence intervals
Linear Regression with Mismeasured Predictor
import pandas as pd
from validation_correction import validation_correction
# Load your data
research_data = pd.read_csv("research_data.csv")
validation_data = pd.read_csv("validation_data.csv")
# Run corrected regression with bootstrap
# Format: y ~ w || x + z
# where x is the true variable and w is its mismeasured version
result = validation_correction.ols(
formula="y ~ w || x + z",
data=research_data,
val_data=validation_data,
bootstrap=True, # Bootstrap is required for correction
n_boots=1000 # Number of bootstrap iterations
)
# Run naive regression (no correction)
naive_result = validation_correction.ols(
formula="y ~ w + z",
data=research_data,
val_data=None
)
# Print results with bootstrap confidence intervals
print(result)
# Plot coefficient comparison
validation_correction.plot_coefficients(naive_result, result)
# Plot bootstrap distributions
validation_correction.plot_bootstrap_distributions()
Logistic Regression with Mismeasured Predictor
# Format: u||y ~ x + z
# where y is the true variable and u is its mismeasured version
result = validation_correction.logit(
formula="u||y ~ x + z",
data=research_data,
val_data=validation_data,
bootstrap=True
)
print(result)
Formula Specification
The package uses a special formula syntax to specify the relationship between true and mismeasured variables:
-
For mismeasured predictors:
- Format:
y ~ w || x + z - Where
xis the true variable andwis its mismeasured version - Additional covariates (
z) are measured without error
- Format:
-
For mismeasured outcomes (not yet implemented):
- Format:
u || y ~ x + z - Where
yis the true outcome anduis its mismeasured version - Predictors go on the right side of the
~
- Format:
-
For naive regression (no correction):
- Standard formula format:
y ~ w + z - No
||operator needed - Set
val_data=None
- Standard formula format:
Visualization
The package provides two types of visualizations:
-
Coefficient Comparison Plot:
validation_correction.plot_coefficients(naive_result, corrected_result)
- Shows point estimates and confidence intervals for both naive and corrected models
- Useful for comparing the magnitude and direction of bias
-
Bootstrap Distribution Plot:
validation_correction.plot_bootstrap_distributions()
- Shows the distribution of coefficient estimates from bootstrap samples
- Includes 95% confidence interval markers
- Must run regression with
bootstrap=Truefirst
Bootstrap confidence intervals:
- Uses percentile method (2.5th and 97.5th percentiles)
- Accessible via
result['[0.025]']andresult['[0.975]'] - Number of bootstrap iterations controlled by
n_bootsparameter - Bootstrap is required for measurement error correction
Data Requirements
- Main dataset (
data): Must contain all variables in the formula - Validation dataset (
val_data): Must contain both the true and mismeasured versions of the relevant variable - Both datasets should be pandas DataFrames
References
- Estimating and Correcting for Misclassification Error in Empirical Textual Research, by Paul Connell and Jonathan H. Choi available at:https://papers.ssrn.com/sol3/papers.cfm?abstract_id=4913179
License
This project is licensed under the MIT License - see the LICENSE file for details.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file validation_correction-0.1.0.tar.gz.
File metadata
- Download URL: validation_correction-0.1.0.tar.gz
- Upload date:
- Size: 10.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b3002a4391ce1bbdc76b992c82cc1b78e89efc08124e28136c73397beb0e0583
|
|
| MD5 |
4ca14b5d15648919e839b7fabf2dc301
|
|
| BLAKE2b-256 |
b254ecb664a934dae60bd8f5f3dbb77d673b2739be8567483c37f46987106834
|
File details
Details for the file validation_correction-0.1.0-py3-none-any.whl.
File metadata
- Download URL: validation_correction-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
38a06b1904448bdf9e3b152fb85ce605089ec19e4150c11b04ced75c288bdacf
|
|
| MD5 |
d431fdad5c51fb1e752c10d37d7c51f8
|
|
| BLAKE2b-256 |
4c4154d87dd36c5ede45e7019d55ad845460f0175b61d2da23bd0ec53ed03f7c
|