cleverly.bases.Modifiers#
- class cleverly.bases.Modifiers(columns: Sequence[str], domains: Mapping[str, tuple[float, float]] | tuple[tuple[str, tuple[float, float]], ...] = (), levels: Mapping[str, Sequence[Any]] | tuple[tuple[str, tuple[Any, ...]], ...] = (), outside: Literal['refuse', 'clip'] = 'refuse')[source]#
The modifier columns, with the domain or the level set each one is declared on.
A continuous modifier may carry a domain
(low, high), which a basis that reads a domain needs and which the rows are checked against. A categorical modifier carries its declared levels, in the order anIndicatorsbasis reports them; the first level is the reference. No column has both.outsidesays what happens to a row whose continuous modifier lies outside its domain, or whose categorical modifier holds an undeclared level."refuse"raises."clip"maps a continuous value to the nearest end of its domain, a known fixed transform, so the working model is then a function of the clipped modifier; an undeclared level still raises."clip"needs a domain for every continuous modifier.The schema checks rows against what it declares. It does not know the adjustment set:
cleverly.ConditionalContrastchecks that each modifier is an adjustment column.- Parameters:
- columnssequence
ofstr The modifier columns, in the order a basis reads them.
- domains
mappingofstrto(float,float),optional The declared domain of a continuous modifier.
- levels
mappingofstrtosequence,optional The declared levels of a categorical modifier, reference level first.
- outside{“refuse”, “clip”}
What a continuous value outside its domain does.
- columnssequence
See also
cleverly.ConditionalContrastThe estimand that declares the modifiers.
LinearA basis that needs no domain.
Examples
>>> from cleverly.bases import Modifiers >>> modifiers = Modifiers(["age", "sex"], domains={"age": (18, 90)}, levels={"sex": ("f", "m")}) >>> modifiers.domain("age"), modifiers.levels_of("sex") ((18.0, 90.0), ('f', 'm')) >>> modifiers.continuous ('age',)
Methods#
- Modifiers.domain(column: str) tuple[float, float] | None[source]#
The declared domain of
column, orNone.
- Modifiers.levels_of(column: str) tuple[Any, ...] | None[source]#
The declared levels of
column, orNone.
- Modifiers.values(frame: Any, columns: Sequence[str] | None = None) dict[str, ndarray][source]#
Read and check the modifier columns of
frame.A continuous modifier comes back as floats, clipped under
outside="clip"; a categorical one as its raw values, each checked against the declared levels.- Parameters:
- Returns:
- Raises:
DataErrorIf a column is missing, a continuous value is not a finite number, a value lies outside its domain under
outside="refuse", or a categorical value is not a declared level.
Attributes#
- Modifiers.categorical#
The modifiers with a declared level set, in column order.
- Modifiers.continuous#
The modifiers with no declared level set, in column order.