A smart and lightweight toolkit for regression modeling, statistical summaries, and Excel annotations.
Project description
regmonkey
regmonkey is a lightweight Python package designed to streamline data analysis and regression modeling tasks. It simplifies tasks like descriptive statistics, dummy variable creation, regression model estimation, and exporting annotated Excel files.
Features
- 📊 Descriptive Statistics: Easily generate clean and rounded summary statistics from a DataFrame.
- 🧠 Smart Variable Parsing: Automatically interpret log transformations, polynomial terms, and interaction terms.
- 📦 Dummy Variable Creation: Quickly convert categorical variables into dummy/indicator variables.
- 📈 Regression Analysis: Run multiple linear regressions with support for log, power, and interaction terms, and export well-formatted result tables.
- 📄 Excel Footer Annotation: Add footnotes to Excel files automatically.
- 🌐 Multilingual Support: Specify variables in any supported language (English, Japanese, or Chinese) and control output language independently using the
langparameter for consistent formatting across all results.
Installation
pip install regmonkey
Functions
add_footer(file_path, value, sheet_name=None)
Adds a footer note to the last row of an Excel sheet.
Arguments:
file_path(str): Path to the Excel file.value(str): The content of the footer note.sheet_name(str, optional): Name of the sheet to modify. Defaults to the first sheet.
Example:
from regmonkey.stats import add_footer
add_footer("example.xlsx", "Note: Data is preliminary.", sheet_name="Sheet1")
get_dummies(df, columns)
Converts categorical variables into dummy/indicator variables.
Arguments:
df(DataFrame): The input DataFrame.columns(list of str): List of column names to convert.
Returns:
- A new DataFrame with dummy variables.
Example:
from regmonkey.stats import get_dummies
import pandas as pd
data = pd.DataFrame({"Year": ["2020", "2021", "2022"], "Value": [10, 20, 30]})
dummies = get_dummies(data, columns=["Year"])
print(dummies)
summary(df, var_list, round_digits=2, lang="ja")
Calculates descriptive statistics for the specified variables.
df: DataFrame containing the datavar_list: List of variable namesround_digits: Number of decimal places (default: 2)lang: Language code ("ja", "en", "zh") for output labels (default: "ja")
Note: By default (when lang is not specified), the output will be in Japanese.
Returns a DataFrame with the following statistics:
- N (Sample size)
- Mean
- Std. Dev. (Standard deviation)
- Min (Minimum value)
- Max (Maximum value)
Example:
# Default (Japanese labels)
summary_stats = summary(df, ["X1", "X2"])
# English labels
summary_stats = summary(df, ["X1", "X2"], lang="en")
# Japanese labels
summary_stats = summary(df, ["X1", "X2"], lang="ja")
# Chinese labels
summary_stats = summary(df, ["X1", "X2"], lang="zh")
regress(variables_dicts, df, decimal_places=2, lang="ja", cov_type="HC1")
Performs regression analysis with support for log, power, and interaction terms.
Arguments:
variables_dicts(list of dict): List of dictionaries specifying dependent and independent variables.- Multilingual Support: You can use different language keys for variables:
- Japanese:
{"被説明変数": "Y", "説明変数": ["X1", "X2"]} - English:
{"y": "Y", "X": ["X1", "X2"]} - Chinese:
{"被解释变量": "Y", "解释变量": ["X1", "X2"]}
- Japanese:
- Log terms: Use
log(X1)for the natural logarithm ofX1. - Power terms: Use
X2**2orX2**3for squared or cubed terms. - Dummy variables: For binary variables, use them directly (e.g.,
['Gender']). For categorical variables, preprocess the DataFrame usingget_dummies(e.g.,['Year_1990', 'Year_1995']). - Interaction terms: Use
X1:X2for the interaction betweenX1andX2, or combine transformations likeX1**2:log(X2).
- Multilingual Support: You can use different language keys for variables:
df(DataFrame): The input data.decimal_places(int): Number of decimal places for results.lang(str): Language code ("ja", "en", "zh") for output labels (default: "ja")cov_type(str): Type of standard error calculation (default: "HC1")- "HC1": White's standard errors with small sample correction
- "HC0": White's standard errors
- "HC2": MacKinnon's standard errors
- "HC3": Davidson-MacKinnon's standard errors
- "nonrobust": Conventional standard errors
Note: By default (when lang is not specified), the output will be in Japanese.
Returns:
- A tuple containing:
- Processed DataFrame.
- Descriptive statistics for used variables.
- Regression results table.
Example:
from regmonkey.stats import regression
import pandas as pd
# Sample data
data = pd.DataFrame({
"X1": [1, 2, 3],
"X2": [4, 5, 6],
"Y": [7, 8, 9],
"Category": ["A", "B", "A"]
})
# Preprocess categorical variables
data_with_dummies = pd.get_dummies(data, columns=["Category"])
# Define regression variables (Japanese)
variables_ja = [
{"被説明変数": "Y", "説明変数": ["X1", "X2", "log(X1)", "X2**2", "X1:X2"]}
]
# Define regression variables (English)
variables_en = [
{"y": "Y", "X": ["X1", "X2", "log(X1)", "X2**2", "X1:X2"]}
]
# Define regression variables (Chinese)
variables_zh = [
{"被解释变量": "Y", "解释变量": ["X1", "X2", "log(X1)", "X2**2", "X1:X2"]}
]
# Perform regression with default output (Japanese)
df_processed, summary_result, regression_result = regress(variables_ja, data_with_dummies)
# Perform regression with Japanese output
df_processed, summary_result, regression_result = regress(variables_ja, data_with_dummies, lang="ja")
# Perform regression with English output
df_processed, summary_result, regression_result = regress(variables_en, data_with_dummies, lang="en")
# Perform regression with Chinese output
df_processed, summary_result, regression_result = regress(variables_zh, data_with_dummies, lang="zh")
# Print results
print(regression_result)
In this example:
- The regression can be specified using any of the supported languages (Japanese, English, or Chinese).
- The output language is determined by the
langparameter, not by the input keys. log(X1)computes the natural logarithm ofX1.X2**2computes the square ofX2.X1:X2computes the interaction betweenX1andX2.- Dummy variables for
Categoryare automatically created usingget_dummies. - The output labels (e.g., "観測数"/"N"/"样本数") will match the language specified by the
langparameter.
Usage Example
import pandas as pd
from regmonkey.stats import get_dummies, regress, add_footer
# Load data
data = pd.DataFrame({
"X1": [1, 2, 3],
"X2": [4, 5, 6],
"Y": [7, 8, 9],
"Category": ["A", "B", "A"]
})
# Create dummy variables
data_with_dummies = get_dummies(data, columns=["Category"])
# Perform regression with log, power, and interaction terms (using English keys)
variables = [
{"y": "Y", "X": ["X1", "X2", "log(X1)", "X2**2", "X1:X2"]}
]
df_processed, summary_result, regression_result = regress(variables, data_with_dummies, lang="en")
# Save regression results to Excel and add a footer
regression_result.to_excel("regression_results.xlsx", index=False)
add_footer("regression_results.xlsx", "Note: Regression results include log, power, and interaction terms.")
# Save summary statistics to Excel and add a footer
summary_result.to_excel("summary_statistics.xlsx", index=False)
add_footer("summary_statistics.xlsx", "Note: Summary statistics for all variables used in the regression analysis.")
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
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 regmonkey-0.1.3.tar.gz.
File metadata
- Download URL: regmonkey-0.1.3.tar.gz
- Upload date:
- Size: 11.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6709e2d34aec98c9e57c1b01a647563294568518f7273b2def9226ef10d00c7c
|
|
| MD5 |
c15d3e85825281f51e67a0d5876c8650
|
|
| BLAKE2b-256 |
527737ce0c420cbe8dfa04583f3792c82491d18334f4371ef5b6ef6df818e375
|
File details
Details for the file regmonkey-0.1.3-py3-none-any.whl.
File metadata
- Download URL: regmonkey-0.1.3-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0bf3100de5e11564779ea9842c391ab579518cbfe0a257ae3a89f0541c46f119
|
|
| MD5 |
0b3ae6f9c87290bf570b60ddd918190c
|
|
| BLAKE2b-256 |
5d58468d769574f1b9dc7262d90630545d50c41dcc8fcdd3c54aaf197cf99208
|