Conditional effects¶
prediction_grid specifies
effect coordinates and explicit conditioning or empirical-reference rows.
BayesianFit.conditional_effects evaluates that grid through one existing
posterior prediction request. PredictionGrid.result also accepts retained
predictions from another checked prediction procedure, with explicit
chain/draw/row axes and provenance.
ConditionalEffects.draws retains joint point dependence. Conditional grids
have (chain, draw, point, condition, *event) axes; empirical grids reduce the
reference rows within each draw and have (chain, draw, point, *event) axes.
summary and analysis delegate to the common posterior diagnostics. Neither
creates convergence statistics for variational or independent prior draws.
The guide explains conditioning,
empirical weights, grouping policies, and allocation limits.
conditional
¶
Bounded prediction grids and draw-wise conditional or empirical effects.
GridValue
¶
A scalar predictor coordinate, preserving category and integer carriers.
PredictionGrid
didactic-model
¶
PredictionGrid(*, columns: tuple[str, ...], rows: tuple[tuple[GridValue, ...], ...], axes: tuple[str, ...], points: tuple[tuple[GridValue, ...], ...], num_conditions: int, marginalize: bool = False, weights: tuple[float, ...] = ())
Bases: ValueModel
Explicit predictor rows with a bounded Cartesian effect layout.
| PARAMETER | DESCRIPTION |
|---|---|
columns
|
Predictor columns in generated-row order.
TYPE:
|
rows
|
Immutable scalar rows, ordered by effect point then conditioning row.
TYPE:
|
axes
|
Varied predictor names in Cartesian-product order.
TYPE:
|
points
|
The varied predictor coordinates at each effect point.
TYPE:
|
num_conditions
|
Explicit conditioning or empirical-reference row count per point.
TYPE:
|
marginalize
|
Reduce reference rows within each joint posterior draw when true. False retains a separate effect for every conditioning row.
TYPE:
|
weights
|
Normalized empirical-reference weights; empty for conditional effects.
TYPE:
|
Notes
Construct with prediction_grid, which checks the allocation bound before
generating the Cartesian product. It never substitutes means or reference
categories implicitly. Prediction retains the fitted model's own checks.
to_frame
¶
Build an independent dataframe for the existing prediction interface.
| RETURNS | DESCRIPTION |
|---|---|
IntoDataFrame
|
Pandas rows in the checked effect-point/conditioning order. |
Notes
This optional adapter requires pandas, as provided by the formula
frontend's dependencies. Core source workflows use to_mapping.
Source code in src/quivers/diagnostics/conditional.py
to_mapping
¶
to_mapping() -> dict[str, tuple[GridValue, ...]]
Expose predictor columns without a dataframe dependency.
| RETURNS | DESCRIPTION |
|---|---|
dict[str, tuple[GridValue, ...]]
|
Independent column tuples in the checked generated-row order. |
Source code in src/quivers/diagnostics/conditional.py
result
¶
result(predictions: Tensor, *, kind: Literal['mcmc', 'variational', 'prior'], method: Literal['epred', 'linpred', 'predict'] = 'epred', labels: tuple[int | str, ...] = ()) -> ConditionalEffects
Retain joint predictions, reducing reference rows before summaries.
| PARAMETER | DESCRIPTION |
|---|---|
predictions
|
One joint prediction request with chain, draw, row, and event axes.
TYPE:
|
kind
|
Actual draw provenance; a variational layout axis is not a chain.
TYPE:
|
method
|
Expected responses, linear predictors, or sampled responses.
TYPE:
|
labels
|
Optional final response-component labels, in native output order.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ConditionalEffects
|
Draws on point/condition/event axes, or point/event axes after empirical marginalization. Cross-point dependence is retained. |
| RAISES | DESCRIPTION |
|---|---|
(ValueError, TypeError)
|
If prediction rows or sample axes disagree with this grid, or a numeric empirical reduction contains invalid values. |
Source code in src/quivers/diagnostics/conditional.py
ConditionalEffects
didactic-model
¶
ConditionalEffects(*, grid: PredictionGrid = field(opaque=True, extras=OPAQUE_BY_VALUE), draws: Tensor = field(opaque=True, extras=OPAQUE_BY_IDENTITY), kind: Literal['mcmc', 'variational', 'prior'], method: Literal['epred', 'linpred', 'predict'] = 'epred', labels: tuple[int | str, ...] = ())
Bases: ValueModel
Joint posterior predictions over an explicit conditioning experiment.
| PARAMETER | DESCRIPTION |
|---|---|
grid
|
Point labels, explicit reference rows, and reduction policy.
TYPE:
|
draws
|
Chain/draw/point/condition/event axes, with the condition axis removed only for explicit empirical marginalization. Storage is held by identity.
TYPE:
|
kind
|
Actual draw provenance, forwarded to existing posterior diagnostics.
TYPE:
|
method
|
Response expectations, linear predictors, or response replications.
TYPE:
|
labels
|
Optional native response labels; category probabilities retain all labels.
TYPE:
|
analysis
¶
analysis() -> PosteriorAnalysis
Reuse joint uncertainty, covariance, and checked contrast diagnostics.
| RETURNS | DESCRIPTION |
|---|---|
PosteriorAnalysis
|
Existing diagnostics over the retained effect tensor, under the
site name |
| RAISES | DESCRIPTION |
|---|---|
(ValueError, TypeError)
|
If draws cannot be represented as real empirical samples. |
Source code in src/quivers/diagnostics/conditional.py
summary
¶
summary(*, probs: Sequence[float] = (0.05, 0.5, 0.95)) -> PosteriorSummary
Summarize retained effects through the common posterior diagnostics.
| PARAMETER | DESCRIPTION |
|---|---|
probs
|
Interior quantile probabilities, retaining their requested order.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
PosteriorSummary
|
Draw-wise uncertainty on point/condition/event coordinates. |
| RAISES | DESCRIPTION |
|---|---|
(ValueError, TypeError)
|
If sample axes, carriers, or requested probabilities are invalid. |
Source code in src/quivers/diagnostics/conditional.py
prediction_grid
¶
prediction_grid(axes: Mapping[str, Sequence[GridValue]], *, conditions: Mapping[str, Sequence[GridValue]] | IntoDataFrame, marginalize: bool = False, weights: Sequence[float] | None = None, max_rows: int = 10000) -> PredictionGrid
Cross explicit effect coordinates with bounded conditioning rows.
| PARAMETER | DESCRIPTION |
|---|---|
axes
|
Nonempty varied predictor values; insertion order defines point order.
TYPE:
|
conditions
|
Explicit conditioning rows, or an empirical reference population. Varied columns are replaced at every effect point. Other columns, including groups, offsets, trial counts, and auxiliaries, are retained. A mapping needs only core dependencies; an empty mapping specifies one empty conditioning row. Dataframes use the optional data adapter while retaining their selected backend, without requiring pandas.
TYPE:
|
marginalize
|
Average reference-row predictions within each posterior draw. False conditions separately on each supplied row and never averages them.
TYPE:
|
weights
|
Optional finite nonnegative reference-population weights, normalized only for empirical averaging. These are not likelihood weights.
TYPE:
|
max_rows
|
Positive upper bound on points times reference rows, checked before Cartesian allocation. Larger requests require an explicit larger budget.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
PredictionGrid
|
Immutable scalar rows and their exact reduction/layout contract. |
| RAISES | DESCRIPTION |
|---|---|
(ValueError, TypeError)
|
If names, values, weights, dimensions, or allocation budgets are invalid. |
Source code in src/quivers/diagnostics/conditional.py
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 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 | |