tea_tasting.aggr
#
Module for working with aggregated statistics: count, mean, var, cov.
Aggregates(count_=None, mean_={}, var_={}, cov_={})
#
Bases: ReprMixin
Aggregated statistics.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
count_ |
int | None
|
Sample size (number of observations). |
None
|
mean_ |
dict[str, float | int]
|
Dictionary of sample means with variable names as keys. |
{}
|
var_ |
dict[str, float | int]
|
Dictionary of sample variances with variable names as keys. |
{}
|
cov_ |
dict[tuple[str, str], float | int]
|
Dictionary of sample covariances with pairs of variable names as keys. |
{}
|
Source code in src/tea_tasting/aggr.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
|
count()
#
Sample size (number of observations).
Returns:
Type | Description |
---|---|
int
|
Sample size (number of observations). |
Source code in src/tea_tasting/aggr.py
70 71 72 73 74 75 76 77 78 |
|
cov(left, right)
#
Sample covariance.
Assume the variable is a constant if the variable name is None
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
left |
str | None
|
First variable name. |
required |
right |
str | None
|
Second variable name. |
required |
Returns:
Type | Description |
---|---|
float | int
|
Sample covariance. |
Source code in src/tea_tasting/aggr.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
|
mean(name)
#
Sample mean.
Assume the variable is a constant 1
if the variable name is None
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str | None
|
Variable name. |
required |
Returns:
Type | Description |
---|---|
float | int
|
Sample mean. |
Source code in src/tea_tasting/aggr.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
|
ratio_cov(left_numer, left_denom, right_numer, right_denom)
#
Sample covariance of the ratios of variables using the Delta method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
left_numer |
str | None
|
First numerator variable name. |
required |
left_denom |
str | None
|
First denominator variable name. |
required |
right_numer |
str | None
|
Second numerator variable name. |
required |
right_denom |
str | None
|
Second denominator variable name. |
required |
Returns:
Type | Description |
---|---|
float | int
|
Sample covariance of the ratios of variables. |
Source code in src/tea_tasting/aggr.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
|
ratio_var(numer, denom)
#
Sample variance of the ratio of two variables using the Delta method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
numer |
str | None
|
Numerator variable name. |
required |
denom |
str | None
|
Denominator variable name. |
required |
Returns:
Type | Description |
---|---|
float | int
|
Sample variance of the ratio of two variables. |
Source code in src/tea_tasting/aggr.py
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 |
|
var(name)
#
Sample variance.
Assume the variable is a constant if the variable name is None
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str | None
|
Variable name. |
required |
Returns:
Type | Description |
---|---|
float | int
|
Sample variance. |
Source code in src/tea_tasting/aggr.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
|
with_zero_div()
#
Return aggregates that do not raise an error on division by zero.
Division by zero returns:
inf
if numerator is greater than0
,nan
if numerator is equal to or less than0
.
Source code in src/tea_tasting/aggr.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
|
read_aggregates(data, group_col, *, has_count, mean_cols, var_cols, cov_cols)
#
Extract aggregated statistics.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Table | IntoFrame
|
Granular data. |
required |
group_col |
str | None
|
Column name to group by before aggregation.
If |
required |
has_count |
bool
|
If |
required |
mean_cols |
Sequence[str]
|
Column names for calculation of sample means. |
required |
var_cols |
Sequence[str]
|
Column names for calculation of sample variances. |
required |
cov_cols |
Sequence[tuple[str, str]]
|
Pairs of column names for calculation of sample covariances. |
required |
Returns:
Type | Description |
---|---|
dict[Any, Aggregates] | Aggregates
|
Aggregated statistics. |
Source code in src/tea_tasting/aggr.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 |
|