API reference¶
Everything documented here is importable directly from the setqca namespace.
Estimators¶
setqca.models ¶
High-level csQCA and fsQCA estimators.
Direction
module-attribute
¶
Directional expectation: "+" present, "-" absent, "0" no expectation.
FSQCA
dataclass
¶
FSQCA(
consistency: float = 0.8,
pri: float = 0.0,
frequency: int = 1,
exclusion_consistency: float | None = None,
max_solutions: int = 256,
directional_expectations: dict[str, Direction] = dict(),
)
Fuzzy-set Qualitative Comparative Analysis estimator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
consistency
|
float
|
Inclusion cutoff on sufficiency consistency for truth-table rows. |
0.8
|
pri
|
float
|
Minimum PRI for a row to be coded sufficient. |
0.0
|
frequency
|
int
|
Minimum number of cases for a row to count as observed. |
1
|
exclusion_consistency
|
float
|
Consistency below which a row is coded |
None
|
max_solutions
|
int
|
Upper bound on the number of tied minimal covers returned. |
256
|
directional_expectations
|
dict of str to Direction
|
Theoretical expectations enabling the intermediate solution. Empty by
default, which skips intermediate minimisation. Accepts the enum, the
QCA symbols |
dict()
|
Notes
All three solution families use an exact classical Quine-McCluskey engine. Intermediate solutions follow Ragin and Sonnett (2005): the parsimonious solution's simplifying assumptions are split into easy and difficult counterfactuals, and only the easy ones are admitted.
fit ¶
fit(
data: DataFrame,
*,
outcome: str,
conditions: list[str] | tuple[str, ...],
case_id: str | None = None,
) -> QCAResult
Fit fsQCA to already calibrated condition and outcome memberships.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
Calibrated memberships in |
required |
outcome
|
str
|
Name of the outcome column. |
required |
conditions
|
list of str or tuple of str
|
Names of the condition columns. |
required |
case_id
|
str
|
Column holding case labels. Defaults to the frame index. |
None
|
Returns:
| Type | Description |
|---|---|
QCAResult
|
Truth table plus conservative, parsimonious and — when directional expectations are supplied — intermediate solutions. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no truth-table row is sufficient under the chosen thresholds. |
Source code in src/setqca/models.py
CSQCA
dataclass
¶
CSQCA(
consistency: float = 1.0,
pri: float = 0.0,
frequency: int = 1,
exclusion_consistency: float | None = None,
max_solutions: int = 256,
directional_expectations: dict[str, Direction] = dict(),
)
Bases: FSQCA
Crisp-set QCA with strict 0/1 input validation.
Identical to :class:FSQCA except that every condition and the outcome
must already be calibrated to binary membership, and the default inclusion
cutoff is perfect consistency.
fit ¶
fit(
data: DataFrame,
*,
outcome: str,
conditions: list[str] | tuple[str, ...],
case_id: str | None = None,
) -> QCAResult
Fit csQCA after verifying that every input column is crisp.
Raises:
| Type | Description |
|---|---|
ValueError
|
If any condition or the outcome contains values other than 0 or 1. |
Source code in src/setqca/models.py
Results¶
setqca.results ¶
Structured QCA result objects.
SolutionKind
module-attribute
¶
Name of a solution family: "conservative", "parsimonious" or "intermediate".
FittedSolution
dataclass
¶
FittedSolution(
boolean: BooleanSolution,
fit: SufficiencyFit,
term_fits: tuple[SufficiencyFit, ...],
)
A Boolean solution together with its fuzzy empirical fit.
expression ¶
QCAResult
dataclass
¶
QCAResult(
method: str,
outcome: str,
conditions: tuple[str, ...],
truth_table: TruthTable,
conservative: tuple[FittedSolution, ...],
parsimonious: tuple[FittedSolution, ...],
intermediate: tuple[FittedSolution, ...] | None,
intermediate_experimental: bool,
counterfactuals: CounterfactualAnalysis | None = None,
)
Complete fitted QCA result for one outcome.
solutions ¶
solutions(kind: SolutionKind) -> tuple[FittedSolution, ...]
Return the fitted solutions of one family.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kind
|
str
|
One of |
required |
Returns:
| Type | Description |
|---|---|
tuple of FittedSolution
|
Empty when the requested family was not computed. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/setqca/results.py
summary_frame ¶
summary_frame(
solution: SolutionKind = "conservative",
) -> DataFrame
Return one row per minimal solution of the requested family.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solution
|
str
|
Solution family to summarise. |
"conservative"
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Columns |
Source code in src/setqca/results.py
fit_boolean_solution ¶
fit_boolean_solution(
solution: BooleanSolution,
*,
data: DataFrame,
outcome: str,
conditions: tuple[str, ...],
) -> FittedSolution
Evaluate a Boolean solution as a fuzzy set over the original cases.
Each prime implicant becomes a conjunction under the minimum t-norm and the solution as a whole becomes their disjunction under the maximum s-norm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solution
|
BooleanSolution
|
Minimal cover produced by the Boolean minimiser. |
required |
data
|
DataFrame
|
Calibrated case-level data. |
required |
outcome
|
str
|
Name of the outcome column. |
required |
conditions
|
tuple of str
|
Condition names in minterm order. |
required |
Returns:
| Type | Description |
|---|---|
FittedSolution
|
The solution with overall and term-level parameters of fit. |
Source code in src/setqca/results.py
Parameters of fit¶
setqca.metrics ¶
Set-theoretic parameters of fit for QCA.
SufficiencyFit
dataclass
¶
Parameters of fit for a sufficiency relation X <= Y.
NecessityFit
dataclass
¶
Parameters of fit for a necessity relation Y <= X.
sufficiency ¶
sufficiency(
cause: ArrayLike, outcome: ArrayLike
) -> SufficiencyFit
Calculate fuzzy-set sufficiency consistency, coverage and PRI.
PRI follows the implementation used by the R QCA package: inconsistency
that simultaneously supports the outcome and its negation is removed from
numerator and denominator.
Source code in src/setqca/metrics.py
necessity ¶
necessity(
cause: ArrayLike, outcome: ArrayLike
) -> NecessityFit
Calculate fuzzy-set necessity consistency, coverage and RoN.
Source code in src/setqca/metrics.py
Set expressions¶
setqca.sets ¶
Typed set expressions for calibrated QCA conditions.
SetExpression ¶
Bases: ABC
Abstract fuzzy-set expression over calibrated conditions.
Expressions compose with the standard Python operators & (intersection,
minimum t-norm), | (union, maximum s-norm) and ~ (negation).
evaluate
abstractmethod
¶
Evaluate membership of the expression for every case.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
Frame of calibrated condition memberships. |
required |
Returns:
| Type | Description |
|---|---|
FloatArray
|
Membership of each case in the expression. |
Source code in src/setqca/sets.py
Condition
dataclass
¶
Bases: SetExpression
Named calibrated condition drawn from a column of the data.
evaluate ¶
Return the calibrated membership column for this condition.
Source code in src/setqca/sets.py
Negation
dataclass
¶
Negation(operand: SetExpression)
Intersection
dataclass
¶
Intersection(operands: tuple[SetExpression, ...])
Bases: SetExpression
Fuzzy conjunction using the minimum t-norm.
evaluate ¶
Return the elementwise minimum across all operands.
Source code in src/setqca/sets.py
Union
dataclass
¶
Union(operands: tuple[SetExpression, ...])
Bases: SetExpression
Fuzzy disjunction using the maximum s-norm.
evaluate ¶
Return the elementwise maximum across all operands.