CoolFace
Apppublic

causalscience/Member_Rewards_Effect

sourceHugging Facemitupdated 1y agoView on Hugging Face
0likes
App README

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

  1. 1.Setup Tab:
  2. 2.Upload your data file (CSV or Excel)
  3. 3.Select the signup month to analyze
  4. 4.View basic statistics about your data
  1. 1.DoWhy Analysis Tab:
  2. 2.Choose an estimation method (propensity score matching, linear regression, etc.)
  3. 3.Select a refutation method (optional)
  4. 4.Run the analysis to see results and visualizations
  1. 1.Statsmodels Analysis Tab:
  2. 2.Run a simple OLS-based analysis
  3. 3.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 month
  • —signup_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:

user_idsignup_monthmonthspendtreatment
001507FALSE
002509FALSE
...............
111484TRUE

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:

  1. 1.Monthly transaction data for all users
  2. 2.Information on when users signed up for the rewards program (if they did)
  3. 3.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:

  1. 1.Naive Difference-in-Differences: Calculates simple pre/post differences between treatment and control groups.
  1. 1.DoWhy: Implements a formal causal inference framework using causal graphs and various estimation methods, including:
  2. 2.Propensity Score Matching
  3. 3.Linear Regression
  4. 4.Propensity Score Stratification
  5. 5.Propensity Score Weighting
  1. 1.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:

  1. 1.Creating a complete web application with Gradio
  2. 2.Implementing multiple analysis methods beyond the original example
  3. 3.Adding comprehensive data visualization
  4. 4.Building robust error handling and validation
  5. 5.Supporting different file formats
  6. 6.Organizing the code in a modular, maintainable structure

License

MIT