PopulationSpec#
- class pyfcirt.PopulationSpec(
- *,
- priors: Mapping[str, TensorVariable] | None = None,
- group: str | None = None,
- reference_group: str | int | None = None,
- regression_by_group: bool = False,
- theta_residual_scale: Literal['unit', 'group'] | None = None,
- theta_correlation: Literal['group', 'shared'] = 'group',
Define population grouping, identifying scales and priors for abilities.
Parameters#
group: str or NoneColumn name in person data. Provide one row per
person_idwith its group label.Noneuses one population.reference_group: str, int or NoneGroup with mean zero and residual trait SD fixed at one.
Noneselects the first group in prepared person order.regression_by_group: boolEstimate separate theta slopes by group. Default:
False.theta_residual_scale: {“unit”, “group”}"unit"fixes SDs to one."group"estimates eligible SDs outside the reference group. By default, a grouped population usesgroupand an ungrouped population usesunit.theta_correlation: {“group”, “shared”}"group"estimates a correlation matrix per group (default)."shared"estimates one matrix for all groups. This option is independent of residual SDs and group means. With no grouping, both options use one matrix.priors: mapping or NoneNative PyMC distributions for free roles. Defaults include
trait_correlationLKJ(1),population_meanNormal(0, 1) andpopulation_sdHalfNormal(1).
Returns#
- PopulationSpec
Population declaration for
Model.prepare(..., population=...). Group-level arrays use thepopulation_groupandtraitcoordinates. Withtheta_correlation="shared",trait_correlationhas dimensionstrait, trait_auxand groupedcovariancekeeps its group dimension. Covariates predict conditional means.
Examples#
Assign two groups by person ID before preparation.
import pandas as pd
import pyfcirt as fc
bundle = fc.load_example("simulated_mirt", model="DichotomousIRT", n_persons=4)
ids = bundle.data.responses.frame["person_id"].drop_duplicates().tolist()
people = pd.DataFrame({"person_id": ids, "site": ["A", "B", "A", "B"]})
population = fc.PopulationSpec(group="site", reference_group="A")
model = fc.Model().prepare(bundle.data, population=population, person_data=people)
print(model.prepared.coords["population_group"].tolist())
['A', 'B']