A minimal linear regression pipeline providing six functions for data inspection, type adjustment, listwise cleaning, OLS fitting, parameter export, and diagnostics.
Project description
C2REG1: A Structured Linear Regression Utility for Python
C2REG1 provides a clean and predictable workflow for linear regression analysis.
It is designed for analysts who prefer a transparent, step-wise approach for building statistical models, checking missing values, converting variable types, fitting OLS models, and generating compact diagnostic tables.
The package is intentionally minimal, without hidden transformations, and is suitable for teaching, research, and production-quality statistical reporting.
C2REG1 guides users through:
Dataset structure review
Variable type conversion
Missing value summary + listwise deletion
OLS model fitting
Compact model summary
Diagnostics table with CIs, t-tests, p-values
Each step is a simple, transparent function callable independently.
Main Functions
print_dataset_structure()
convert_variable_types()
mv_summary_and_listwise_deletion()
fit_ols()
specific_output()
summary_table()
🔧 Installation
Install from PyPI:
pip install C2REG1
📘 Function Reference: C2REG1 Linear Regression Workflow
C2REG1 provides a structured, six-step linear regression workflow. Each function is intentionally minimal, predictable, and works on standard pandas DataFrames.
1️⃣ print_dataset_structure(df, max_rows_preview=5) Purpose
Provides a compact structural summary of a dataset — similar to R’s str() or SAS contents.
Inputs Argument Type Description df DataFrame Raw dataset to inspect max_rows_preview int Number of rows to preview (default 5)
Output Prints column names, dtypes, non-null counts, and a small data preview.
2️⃣ convert_variable_types(df, conversions) Purpose
User-controlled conversion of selected variables into desired data types.
Inputs Argument Type Description df DataFrame Input DataFrame conversions dict Mapping of column names → target type ('float', 'int', 'category', 'str', 'bool')
Output Returns a modified DataFrame (copy) with updated types. Prints warnings for variables not present.
3️⃣ mv_summary_and_listwise_deletion(df, variables_to_consider=None) Purpose
Summarizes missing values and performs listwise deletion across selected variables.
Inputs Argument Type Description df DataFrame Data after type conversions variables_to_consider list or None Variables to check for missing values. If None, uses all columns. Outputs Returns df_clean — dataset after listwise deletion summary_dict — counts of missing values, rows removed, and sample deleted row indices Also prints a human-readable missing-value summary.
4️⃣ fit_ols(df, dependent, independents, add_intercept=True, NumDigits=6) Purpose
Fits an OLS regression using numeric variables and encoded categorical variables. Prints summaries, ANOVA, and parameter tables.
Inputs Argument Type Description df DataFrame Cleaned dataset dependent str Name of the dependent variable independents list List of predictors (numeric or categorical) add_intercept bool Adds an intercept column (default True) NumDigits int Rounding precision for printed output Outputs Returns: results — statsmodels OLS result object summary_stats — dict with ANOVA, coefficient table, RMSE, R², Adj-R², CV %, etc.
Also prints: OLS fit summary Coefficient table Manual ANOVA table
5️⃣ specific_output(results, dependent, model_label='Model1', NumDigits=6) Purpose
Creates a compact, a row containing coefficients and metadata.
Inputs Argument Type Description results OLS results Output of fit_ols() dependent str Dependent variable name model_label str Label for the model (default "Model1") NumDigits int Rounding precision for parameters Output
Returns a single-row DataFrame containing parameters, RMSE, and metadata (MODEL, TYPE, DEPVAR).
6️⃣ summary_table(results, alpha=0.05, NumDigits=6)
Purpose
Computes diagnostic statistics: standard errors, t-values, p-values, and CI bounds.
Inputs Argument Type Description results OLS results Model results from fit_ols alpha float Confidence level (default 0.05 → 95% CI) NumDigits int Rounding precision for printed diagnostics Output Returns a DataFrame with: estimate stderr t-statistic p-value lower/upper CI bounds Prints a rounded version of the diagnostics table.
🚀 Quick Example
import pandas as pd
import numpy as np
import C2REG1 as c2r1
# Sample dataset
df = pd.DataFrame({
"bweight": np.random.normal(3000, 600, size=200),
"matage": np.random.randint(18, 40, size=200),
"ht": np.random.choice(["yes", "no"], size=200),
"sex": np.random.choice(["male", "female"], size=200)
})
# Step 1: Inspect structure
c2r1.print_dataset_structure(df)
# Step 2: Adjust variable types
c2r1.df = convert_variable_types(df, {"ht": "category", "sex": "category"})
# Step 3: Missing-value summary & listwise deletion
# By default, all columns are considered if variables_to_consider is not provided
df_clean, mv_summary = c2r1.mv_summary_and_listwise_deletion(df)
# Or, optionally, specify a subset of variables
# df_clean, mv_summary = c2r1.mv_summary_and_listwise_deletion(df, ["bweight", "matage", "ht", "sex"])
# Step 4: Fit OLS model
results, stats = fit_ols(
df_clean,
dependent="bweight",
independents=["matage", "ht", "sex"],NumDigits=3
)
# Step 5: Export parameter estimates
outest_df = c2r1.specific_output(results, dependent="bweight",model_label="BW_Model1",NumDigits=4)
# Step 6: summary_table (stderr, t, p-value, CI)
diag_df = c2r1.summary_table(results, alpha=0.05,NumDigits=4)
📘 Notes
-
C2REG1 does not perform automatic transformations (e.g., log, squared, interaction terms). Users should create any derived variables manually in their DataFrame before fitting.
-
Categorical variables are automatically dummy-encoded during regression.
-
The output includes:
- ANOVA
- RMSE
- R² and Adjusted R²
- Coefficient table
- OUTEST-like export
- Diagnostic table with confidence intervals
📄 License
C2REG1 is open-source under the MIT License.
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 c2reg1-0.1.0.tar.gz.
File metadata
- Download URL: c2reg1-0.1.0.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f6c6a3813d3cf00cec9212c9b22cb7a09c680d7bf55e24aeeb5dc05a0c3037c0
|
|
| MD5 |
0650337ab80f6b0a8d10b517be3416fc
|
|
| BLAKE2b-256 |
c01f8dd7d0125873cd0f045af9e3f2ab5fc7c7da62d4a1b1d39cc6f787214d87
|
File details
Details for the file c2reg1-0.1.0-py3-none-any.whl.
File metadata
- Download URL: c2reg1-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5ee96546ab399b0c7e3bd9541785a36619fdbb5a8fd4965616e9a6b0831a4dfa
|
|
| MD5 |
a0570ea098ee558b5a5828de2e72347f
|
|
| BLAKE2b-256 |
f09e93b8111275628af7375167fefa2c703f7510eaa629e53591d629807b2db7
|