Skip to content
Submodule
causalis.shared.srm

srm

Submodule causalis.shared.srm with no child pages and 12 documented members.

Classes

Jump directly into the documented classes for this page.

1 items

Functions

Jump directly into the documented functions for this page.

1 items

Data

Jump directly into the documented data for this page.

2 items
data
causalis.shared.srm.Number

Number

Value: None

None

Canonical target

causalis.shared.srm.Number

Link to this symbol
class
causalis.shared.srm.SRMResult

SRMResult

Result of a Sample Ratio Mismatch (SRM) check.

Attributes

chi2float

The calculated chi-square statistic.

p_valuefloat

The p-value of the test, rounded to 5 decimals.

expecteddict[Hashable, float]

Expected counts for each variant.

observeddict[Hashable, int]

Observed counts for each variant.

alphafloat

Significance level used for the check.

is_srmbool

True if an SRM was detected (chi-square p-value < alpha), False otherwise.

warningstr or None

Warning message if the test assumptions might be violated (e.g., small expected counts).

Canonical target

causalis.shared.srm.SRMResult

Sections

Attributes
Link to this symbol
attribute
causalis.shared.srm.SRMResult.chi2

chi2

Value: None

None

Canonical target

causalis.shared.srm.SRMResult.chi2

Link to this symbol
attribute
causalis.shared.srm.SRMResult.p_value

p_value

Value: None

None

Canonical target

causalis.shared.srm.SRMResult.p_value

Link to this symbol
attribute
causalis.shared.srm.SRMResult.expected

expected

Value: None

None

Canonical target

causalis.shared.srm.SRMResult.expected

Link to this symbol
attribute
causalis.shared.srm.SRMResult.observed

observed

Value: None

None

Canonical target

causalis.shared.srm.SRMResult.observed

Link to this symbol
attribute
causalis.shared.srm.SRMResult.alpha

alpha

Value: None

None

Canonical target

causalis.shared.srm.SRMResult.alpha

Link to this symbol
attribute
causalis.shared.srm.SRMResult.is_srm

is_srm

Value: None

None

Canonical target

causalis.shared.srm.SRMResult.is_srm

Link to this symbol
attribute
causalis.shared.srm.SRMResult.warning

warning

Value: None

None

Canonical target

causalis.shared.srm.SRMResult.warning

Link to this symbol
method
causalis.shared.srm.SRMResult.__repr__

__repr__

Canonical target

causalis.shared.srm.SRMResult.__repr__

Link to this symbol
function
causalis.shared.srm.check_srm

check_srm

Check Sample Ratio Mismatch (SRM) for an RCT via a chi-square goodness-of-fit test.

Parameters

assignmentsIterable[Hashable] or pandas.Series or CausalData or Mapping[Hashable, Number]

Observed variant assignments. If iterable or Series, elements are labels per unit (user_id, session_id, etc.). If CausalData is provided, the treatment column is used. If a mapping is provided, it is treated as {variant: observed_count} with non-negative integer counts.

target_allocationdict[Hashable, Number]

Mapping {variant: p} describing intended allocation as probabilities.

alphafloat, default 1e-3

Significance level. Use strict values like 1e-3 or 1e-4 in production.

min_expectedfloat, default 5.0

If any expected count < min_expected, a warning is attached.

strict_variantsbool, default True

- True: fail if observed variants differ from target keys. - False: drop unknown variants and test only on declared ones.

Returns

SRMResult

The result of the SRM check.

Raises

ValueError

If inputs are invalid or empty. ImportError If scipy is required but not installed.

Notes

  • Target allocation probabilities must sum to 1 within numerical tolerance.

  • is_srm is computed using the unrounded p-value; the returned p_value is rounded to 5 decimals.

  • Missing assignments are dropped and reported via warning.

  • Requires SciPy for p-value computation.

Examples

Canonical target

causalis.shared.srm.check_srm

Sections

ParametersReturnsRaisesNotesExamples
Link to this symbol
data
causalis.shared.srm.__all__

__all__

Value: ['SRMResult', 'check_srm']

[‘SRMResult’, ‘check_srm’]

Canonical target

causalis.shared.srm.__all__

Link to this symbol