formulaic_contrasts.FactorMetadata#

class formulaic_contrasts.FactorMetadata(name, reduced_rank, custom_encoder, categories, kind, drop_field=None, column_names=None, colname_format=None)#

Dataclass to hold metadata related to a factor from a formula.

Attributes table#

base

The base category for this categorical factor.

colname_format

A formattable string that can be used to generate the column name in the design matrix, e.g. {name}[T.{field}].

column_names

The column names for this factor included in the design matrix.

drop_field

The category that is dropped.

name

The unambiguous factor name as specified in the formula.

reduced_rank

Whether a column will be dropped because it is redundant

custom_encoder

Whether or not a custom encoder (e.g. C(...)) was used.

categories

The unique categories in this factor (after applying drop_rows)

kind

Type of the factor

Methods table#

Attributes#

FactorMetadata.base#

The base category for this categorical factor.

This is derived from drop_field (for default encoding) or by comparing the column names in the design matrix with all categories (for custom encoding, e.g. C(...)).

FactorMetadata.colname_format: str | None = None#

A formattable string that can be used to generate the column name in the design matrix, e.g. {name}[T.{field}]

FactorMetadata.column_names: Sequence[str] | None = None#

The column names for this factor included in the design matrix.

This may be the same as categories if the default encoder is used, or categories without the base level if a custom encoder (e.g. C(...)) is used.

FactorMetadata.drop_field: str | None = None#

The category that is dropped.

Note that
  • this may also be populated if reduced_rank = False

  • this is only populated when no encoder was used (e.g. ~ donor but NOT ~ C(donor).

FactorMetadata.name: str#

The unambiguous factor name as specified in the formula. E.g. donor, or C(donor, contr.treatment(base="A"))

FactorMetadata.reduced_rank: bool#

Whether a column will be dropped because it is redundant

FactorMetadata.custom_encoder: bool#

Whether or not a custom encoder (e.g. C(...)) was used.

FactorMetadata.categories: Sequence[str]#

The unique categories in this factor (after applying drop_rows)

FactorMetadata.kind: Kind#

Type of the factor

Methods#