Model.fit#
- Model.fit(
- *,
- draws: int = 1000,
- tune: int = 1000,
- chains: int | None = None,
- target_accept: float = 0.8,
- nuts_sampler: str | None = 'blackjax',
- random_seed=None,
- var_names: Sequence[str] | None = None,
- retain_calibration: bool = False,
- overwrite: bool = False,
- **sample_kwargs,
Fit a prepared measurement model using PyMC’s native sampler.
Parameters#
draws: intRetained draws per chain. Default: 1000.
tune: intWarmup iterations per chain. Default: 1000.
chains: int or NoneNumber of chains.
Nonedelegates to PyMC.target_accept: floatTarget NUTS acceptance. Default: 0.8.
nuts_sampler: str or NoneDefault:
"blackjax". Select another installed sampler such as"pymc","numpyro"or"nutpie", orNonefor native selection.random_seed: int, compatible native seed or NoneSampling seed passed to PyMC.
var_names: sequence of str or NoneNative variables to save.
Noneretains final parameters and omits names ending in_raw. Retain the variables needed by later analyses.retain_calibration: boolDefault:
False. Save the native shared calibration draws needed for the first posterior-scoring round. This retains the calibration sources alongside the ordinary posterior outputs or the suppliedvar_names.overwrite: boolReplace current samples and their derived results. Default:
False.sample_kwargsAdditional PyMC sampling options.
idata_kwargs={"log_likelihood": True}saves ordinary response factors. Uselog_likelihood()for marginal TIRTRank probabilities.
Returns#
- xarray.DataTree
The fit, also accessible through
model.idata.posterioruseschainanddrawplus each variable’s parameter axes.sample_statscontains available sampling diagnostics.
Notes#
BlackJAX and NumPyro default to parallel CPU chains and vectorized GPU chains.
Explicit native options override these choices. PyFCIRT defaults
compute_convergence_checks to False. Check R-hat, effective sample size
and divergences with ArviZ after fitting.
Examples#
This fit uses 120 respondents and returns scores for six traits.
import pyfcirt as fc
bundle = fc.load_example(
"hexaco_fc3",
model="TIRT",
n_persons=120,
random_seed=42,
)
model = fc.Model()
model.add_fc(
bundle.data.design,
bundle.data.responses.frame,
format="block_long",
response_format="mole",
model="TIRT",
)
model.prepare()
idata = model.fit(draws=1200, tune=1800, chains=4, random_seed=43)
print({axis: idata.posterior.sizes[axis] for axis in ("chain", "draw", "person", "trait")})
{'chain': 4, 'draw': 1200, 'person': 120, 'trait': 6}