Skip to main content
logo

PySiMMMulator

CodeFactor PyPI Downloads

PySiMMMulator is an open source Python framework for simulation of Marketing data for use in testing Marketing Mix Models (MMMs). While this package contains a full pipeline for data generation (configurable via YAML) it can also be utilized in parts to generate select portions of MMM input data (e.g. campaign/channel spend).

Originally predicated on adapting the R-package siMMMulator for python. PySiMMMulator has retained core function parallels to the functions of siMMMulator but has since expanded capabilities to support a far broader array of MMM inputs and utilities (e.g. geographic distribution, modular adstock/saturation).

Installation

Accessable via PyPI

pip install pysimmmulator

Usage

PySiMMMulator's simulator can either be run on a step-by-step basis, or can be run single-shot by passing a config file.

Run via config

Run using this method, you'll be returned a SimulationResult object containing both a dataframe for MMM input as well as the "True ROI" values for each of your channels, and associated metadata. These true values are critical to validating your MMM model.

from pysimmmulator import load_config, Simulate

cfg = load_config(config_path="./my_config.yaml")
simmm = Simulate()
result = simmm.run_with_config(config=cfg)

# Access results
mmm_input_df = result.df
channel_roi = result.channel_roi

Run via CLI

A configuration file is required as input for this and should be passed as seen below. An output path can also be passed via -o, however when not passed the current working directory will be used.

pysimmm -i example_config.yaml -o .

Run by stages

Alternatively you may run each of the stages independently, which allows for easier debugging and in-run adjustments. Due to the stateless architecture, each stage returns its results which are then passed to the next stage.

from pysimmmulator import load_config, Simulate, define_basic_params, create_all_parameters

cfg = load_config("./my_config.yaml")
params = create_all_parameters(cfg)
simmm = Simulate(params["basic_params"])

baseline_df = simmm.simulate_baseline(params["baseline_params"])
spend_df = simmm.simulate_ad_spend(baseline_sales_df=baseline_df, params=params["ad_spend_params"])
spend_df = simmm.simulate_media(spend_df=spend_df, params=params["media_params"])
spend_df = simmm.simulate_cvr(spend_df=spend_df, params=params["cvr_params"])
mmm_df = simmm.simulate_decay_returns(spend_df=spend_df, params=params["adstock_params"])
mmm_df = simmm.calculate_conversions(mmm_df=mmm_df)
mmm_df = simmm.consolidate_dataframe(mmm_df=mmm_df, baseline_sales_df=baseline_df)
channel_roi = simmm.calculate_channel_roi(mmm_df=mmm_df)
final_df = simmm.finalize_output(mmm_df=mmm_df, params=params["output_params"])

Exogenous Factors

PySiMMMulator supports the inclusion of external shocks, holidays, and promotions. These can be specified as either multipliers or additive impacts within the baseline_params block.

baseline_params:
  ...
  exogenous_factors:
    - name: "Black Friday"
      dates: ["2023-11-24"]
      impact: 3.5
      type: "multiplier"
    - name: "Christmas Peak"
      start_date: "2023-12-20"
      end_date: "2023-12-24"
      impact: 2.0
      type: "multiplier"

Automated Sensitivity Analysis (Monte Carlo)

The Multisim class enables Monte Carlo simulations by allowing you to define uncertainty ranges for any configuration parameter. This helps researchers understand how sensitive an MMM is to data volatility.

from pysimmmulator import Multisim, load_config

base_cfg = load_config("my_config.yaml")
sensitivity_config = {
    "baseline_params": {
        "error_std": [20.0, 150.0]  # sample noise level for each run
    }
}

msim = Multisim(random_seed=42)
msim.run(config=base_cfg, runs=100, sensitivity_config=sensitivity_config)

# results is a list of SimulationResult objects
results = msim.get_data

Geographic distribution

Marketing Mix Models may use geographic grain data for the purposes of budget allocation or during the calibration phase. PySiMMMulator provides Geos to facilitate the generation of randomized geographies as well as a distribution function to allocate synthetic data across the geographies.

Study simulation

Study and BatchStudy are also provided to simplify the simulated outcomes of marketing studies, which are an important component of MMM calibration.

Within this framework study results are drawn from a normal distribution about the true value of a channel's effectiveness (defaulted to ROI within this package). Both Study and BatchStudy provide the ability to pass bias and standard deviation parameters for stationary and non-stationary distributions—allowing users to replicate a diverse set of real-world measurement difficulties.

Development

Setting up a dev environment

python3 -m venv venv
source venv/bin/activate
pip install -e '.[dev]'

Metadata

Release files for pysimmmulator 0.6.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pysimmmulator 0.6.2
File Size Uploaded
pysimmmulator-0.6.2.tar.gz 36.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pysimmmulator 0.6.2
File Interpreter ABI Platform
pysimmmulator-0.6.2-py3-none-any.whl Python 3 none any Details

Total release size: 62.0 kB

Release files / pysimmmulator-0.6.2.tar.gz

Download URL pysimmmulator-0.6.2.tar.gz
Size 36.3 kB
Tags Source
SHA-256 checksum
How to use checksums
70fd73007c5bc37573725233502adde69b8f298e59656baf2b6df760fcb33679
BLAKE2b-256 checksum
How to use checksums
f4d538a75e196854bd0b458eca6c21aef0c0b13761cd9411188d3c69f4b7b564
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / pysimmmulator-0.6.2-py3-none-any.whl

Download URL pysimmmulator-0.6.2-py3-none-any.whl
Size 25.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
75314f76dd4c9d43bbf584d5fc69b311ee954438eb4a3c2b8884d17fafc0c59b
BLAKE2b-256 checksum
How to use checksums
fbc0b532dfc85dc85f4c5ac4502d83c4f1df9fb0b9fad9888329584376becb16
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

0.6.2 This release

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.4

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page