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(("metric", "control", "treatment", "pvalue")))
metric control treatment pvalue
sample_ratio 2023 1977 0.477
Different expected ratio:
>>> experiment = tt.Experiment(
... sample_ratio=tt.SampleRatio(0.5),
... )
>>> data = tt.make_users_data(seed=42)
>>> result = experiment.analyze(data)
>>> print(result.to_string(("metric", "control", "treatment", "pvalue")))
metric control treatment pvalue
sample_ratio 2023 1977 3.26e-103
Source code in src/tea_tasting/metrics/proportion.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
|
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 |
IntoFrame | 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
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
|
analyze_aggregates(control, treatment)
#
Stub method for compatibility with the base class.
Source code in src/tea_tasting/metrics/proportion.py
164 165 166 167 168 169 170 |
|
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 |