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
count()
#
Sample size (number of observations).
Raises:
Type | Description |
---|---|
RuntimeError
|
Count is |
Returns:
Type | Description |
---|---|
int
|
Sample size (number of observations). |
Source code in src/tea_tasting/aggr.py
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
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
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
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
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
with_zero_div()
#
Return aggregates that do not raise an error on division by zero.
Division by zero returns
nan
if numerator is equal to0
,inf
if numerator is greater than0
,-inf
if numerator is less than0
.
Source code in src/tea_tasting/aggr.py
read_aggregates(data, group_col, *, has_count, mean_cols, var_cols, cov_cols)
#
Extract aggregated statistics from an Ibis Table or a Pandas DataFrame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Table | DataFrame
|
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 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 |
|