Skip to main content

A minimal linear regression pipeline providing six functions for data inspection, type adjustment, listwise cleaning, OLS fitting, parameter export, and diagnostics.

Project description

📘 README.md (End-User Version — Clean & Professional)

C2REGbase: A Structured Linear Regression Utility for Python

C2REGbase provides a clean and predictable workflow for linear regression analysis, inspired by the structured output of SAS/PROC REG.

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.

C2REGbase guides users through:

Dataset structure review

Variable type conversion

Missing value summary + listwise deletion

OLS model fitting (with SAS-like ANOVA and parameter output)

OUTEST-like 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 C2REGbase


📘 Function Reference: C2REGbase Linear Regression Workflow

C2REGbase provides a structured, six-step linear regression workflow inspired by SAS/PROC REG style output. 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, sig_digits=6) Purpose

Fits an OLS regression using numeric variables and encoded categorical variables. Prints SAS-style 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) sig_digits 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', sig_digits=6) Purpose

Creates a compact, SAS OUTEST-like 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") sig_digits 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, sig_digits=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) sig_digits 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 C2REGbase


# 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
print_dataset_structure(df)

# Step 2: Adjust variable types
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 = mv_summary_and_listwise_deletion(df)

# Or, optionally, specify a subset of variables
# df_clean, mv_summary = 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"],sig_digits=3
)

# Step 5: Export parameter estimates 
outest_df = specific_output(results, dependent="bweight",model_label="BW_Model1",sig_digits=4)

# Step 6: summary_table (stderr, t, p-value, CI) 
diag_df = summary_table(results, alpha=0.05,sig_digits=4)

📘 Notes

  • C2REGbase 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

C2REGbase is open-source under the MIT License.


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

c2regbase-0.1.2.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

c2regbase-0.1.2-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file c2regbase-0.1.2.tar.gz.

File metadata

  • Download URL: c2regbase-0.1.2.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for c2regbase-0.1.2.tar.gz
Algorithm Hash digest
SHA256 c17460af404c563bf492ee426d29c1ef5787d958ccbbb189e35f1dee1cd17d25
MD5 92755bb8338ffe5df5fd2f76b6a05637
BLAKE2b-256 af20d8a816d724650016abe4269f598f04222225add8cf65e6cd82f86e845133

See more details on using hashes here.

File details

Details for the file c2regbase-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: c2regbase-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for c2regbase-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6adbcd13e9620d46d8e03abc1b170c59ca9a4bb482c3a75dea41c6f4b2d8470a
MD5 9fae02cf0733498bc7ca28d2c9bc5a34
BLAKE2b-256 7cd0b30f737808e999536e21255de4e70360b4fa1aa50f9beb5a41e36bde3187

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page