Open
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #2300 +/- ##
==========================================
- Coverage 93.18% 93.15% -0.03%
==========================================
Files 79 79
Lines 12472 12526 +54
==========================================
+ Hits 11622 11669 +47
- Misses 850 857 +7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
- Remove _EvaluatorContext and _build_evaluator (shared variable swapping) - Restore inline evaluator compilation in compute_incremental_contribution - Simplify _validate_input to date-only validation - Add compare_coords guard at __init__ time Made-with: Cursor
…nd plot_interactive.roas() Made-with: Cursor
Made-with: Cursor
Made-with: Cursor
Contributor
Author
|
@cursoragent review |
Contributor
Author
|
@juanitorduz @ricardoV94 this is ready to review |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR addresses three areas:
Incrementality.summaryandplot_interactivelayers (default remains"elementwise"for backward compatibility).period_start/period_end→start_date/end_date,get_roas→get_elementwise_roas).Problem 1: No validation for filtered/aggregated idata in Incrementality
Users could pass pre-aggregated (e.g.
aggregate_dims) or improperly filtered (scalarfilter_dims) idata toIncrementality, resulting in incorrect results or cryptic errors. The adstock model graph expects the original per-dimension-value parameters, so these transformations are incompatible with counterfactual evaluation.Approach:
MMMIDataWrapper.compare_coords— compares coordinate values between the wrapper's idata and the fitted PyMC model for each custom dimension (excludingdate), returning(in_model_not_idata, in_idata_not_model)dicts.Incrementality.__init__validation — on construction, callscompare_coordsand raisesValueErrorif the idata contains unknown coordinate labels (aggregated dims) or is missing a dimension entirely (scalar filter that dropped the dim). Provides actionable guidance in the error message.Problem 2:
summary.roas()andplot_interactive.roas()only support naive element-wise ROASsummary.roas()andplot_interactive.roas()used simple contribution/spend division, which does not account for adstock carryover. This gives misleading ROAS values, especially for channels with long carryover windows. Users now have the option to compute true incremental ROAS viamethod="incremental".Approach:
data.get_roas→data.get_elementwise_roasrename — the oldget_roas()is deprecated with aFutureWarningpointing users toget_elementwise_roas()orsummary.roas(method="incremental").summary.roas(method=...)parameter — addsmethod("elementwise"default,"incremental"opt-in),include_carryover,num_samples,random_state,start_date, andend_dateparameters. Whenmethod="incremental", delegates toIncrementality.contribution_over_spend; when"elementwise", uses the data wrapper directly. Validates that incremental-only parameters aren't used withmethod="elementwise".plot_interactive.roas(method=...)parameter — passes the same parameters through tosummary.roas().Refactoring & API cleanup
period_start/period_end→start_date/end_date— renamed across theIncrementalityAPI (public methods, internal helpers, docstrings, and the example inmultidimensional.py).MMMSummaryFactory.roas()andMMMPlotlyFactory.roas()receivedstart_date/end_dateas new parameters (they had no date parameters before).Incrementality.__init__now acceptsdataparameter — accepts eitheridataordata(mutually exclusive). Passing a pre-builtMMMIDataWrapperavoids redundant re-wrapping and enables passing data directly fromsummary.roas().conftest.pyfix —mock_fitnow calls_set_xarray_datasochannel_datahas concrete shape matching realmmm.fit()behavior.Related Issue
Examples
Element-wise ROAS (default)
Incremental ROAS (opt-in)
Known Limitations
method="incremental"does not supportfilter_dimsoraggregate_dimson the datapassed to
roas(). TheIncrementalityclass validates that idata coordinates matchthe fitted model exactly, so pre-filtered or pre-aggregated data will raise
ValueError.