tea_tasting.metrics.proportion
#
Metrics for the analysis of proportions.
SampleRatio(ratio=1, *, method='auto', correction=True)
#
Bases: MetricBaseAggregated[SampleRatioResult]
Metric for sample ratio mismatch check.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ratio |
float | int | dict[Any, float | int]
|
Expected ratio of the number of observations in the treatment relative to the control. |
1
|
method |
Literal['auto', 'binom', 'norm']
|
Statistical test used for calculation of p-value. |
'auto'
|
correction |
bool
|
If |
True
|
Examples:
import tea_tasting as tt
experiment = tt.Experiment(
sample_ratio=tt.SampleRatio(),
)
data = tt.make_users_data(seed=42)
result = experiment.analyze(data)
print(result.to_string(("control", "treatment", "pvalue")))
#> metric control treatment pvalue
#> sample_ratio 2023 1977 0.477
Different expected ratio:
import tea_tasting as tt
experiment = tt.Experiment(
sample_ratio=tt.SampleRatio(0.5),
)
data = tt.make_users_data(seed=42)
result = experiment.analyze(data)
print(result.to_string(("control", "treatment", "pvalue")))
#> metric control treatment pvalue
#> sample_ratio 2023 1977 3.26e-103
Source code in src/tea_tasting/metrics/proportion.py
aggr_cols: AggrCols
property
#
Columns to be aggregated for a metric analysis.
analyze(data, control, treatment, variant=None)
#
Perform a sample ratio mismatch check.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
DataFrame | Table | dict[Any, Aggregates]
|
Experimental data. |
required |
control |
Any
|
Control variant. |
required |
treatment |
Any
|
Treatment variant. |
required |
variant |
str | None
|
Variant column name. |
None
|
Returns:
Type | Description |
---|---|
SampleRatioResult
|
Analysis result. |
Source code in src/tea_tasting/metrics/proportion.py
analyze_aggregates(control, treatment)
#
Stub method for compatibility with the base class.
SampleRatioResult
#
Bases: NamedTuple
Result of the sample ratio mismatch check.
Attributes:
Name | Type | Description |
---|---|---|
control |
float
|
Number of observations in control. |
treatment |
float
|
Number of observations in treatment. |
pvalue |
float
|
P-value |