causalscience/Member_Rewards_Effect
Membership Rewards Program Causal Analysis
This application analyzes the causal effect of a membership rewards program on customer spending using multiple methodologies. It provides a user-friendly interface for uploading data, configuring analysis parameters, and visualizing results.
Features
- Multiple Analysis Methods:
- Naive difference-in-differences estimation
- DoWhy causal inference with various estimation techniques
- Statsmodels OLS regression with pre-treatment controls
- Interactive Visualizations:
- Pre vs Post Treatment Spending scatter plots
- Average Monthly Spending time series
- Causal graph visualization (DoWhy method)
- Flexible Data Handling:
- Support for CSV and Excel file formats
- Robust error handling and validation
- Detailed statistics about treatment and control groups
How to Use
- Setup Tab:
- Upload your data file (CSV or Excel)
- Select the signup month to analyze
- View basic statistics about your data
- DoWhy Analysis Tab:
- Choose an estimation method (propensity score matching, linear regression, etc.)
- Select a refutation method (optional)
- Run the analysis to see results and visualizations
- Statsmodels Analysis Tab:
- Run a simple OLS-based analysis
- Compare results with the DoWhy approach
Data Format Requirements
Your dataset should be structured in a panel format (one row per user per month) and include the following columns:
user_id: Unique identifier for each customer (numeric)month: Time period, representing months (1-12)spend: Amount spent by the customer in a given monthsignup_month: The month when the user signed up for the rewards program (0 for users who never signed up)treatment: Boolean (TRUE/FALSE) or binary (1/0) indicator of whether the user is in the treatment group
Example data format:
Scenario Context
This application is designed for scenarios similar to analyzing a membership rewards program introduced at a specific time (e.g., January 2019). The outcome variable of interest is typically spending after the program introduction. The dataset should contain:
- Monthly transaction data for all users
- Information on when users signed up for the rewards program (if they did)
- A clear treatment indicator
The analysis assumes that unobserved confounding does not significantly impact the results. This is suitable for A/B tests or natural experiments where the treatment assignment mechanism is well understood.
Methodology
This application implements three approaches to causal inference:
- Naive Difference-in-Differences: Calculates simple pre/post differences between treatment and control groups.
- DoWhy: Implements a formal causal inference framework using causal graphs and various estimation methods, including:
- Propensity Score Matching
- Linear Regression
- Propensity Score Stratification
- Propensity Score Weighting
- Statsmodels OLS: Uses a regression approach controlling for pre-treatment spending to estimate the treatment effect.
Dependencies
- pandas
- numpy
- matplotlib
- seaborn
- gradio
- statsmodels
- dowhy
- PIL
Background
This project expands on the example from the DoWhy library by:
- Creating a complete web application with Gradio
- Implementing multiple analysis methods beyond the original example
- Adding comprehensive data visualization
- Building robust error handling and validation
- Supporting different file formats
- Organizing the code in a modular, maintainable structure
License
MIT
