chi_ppp#
- pyfcirt.chi_ppp(
- model,
- *,
- predictions=None,
- blocks=None,
- items=None,
- groupby='overall',
- draws=None,
- random_seed=None,
- save_discrepancy=False,
- store=True,
- progressbar=True,
Compare observed and replicated Pearson discrepancies at matched posterior states.
Parameters#
model: ModelFitted MCMC model with observed categorical responses.
predictions: xarray.DataTree or NoneExisting replicas from this fit. If omitted and
draws=None, stored replicas are reused when available.blocks,items: sequence or NoneLimit the check by block or item ID.
groupby: str"overall"(default),"person","block","item","measurement"or"pair". Use pair grouping for direct pair factors.draws: int or NoneNumber of states for fresh replicas. Cannot be supplied with
predictions.random_seed: int or NoneSeed for fresh predictions.
save_discrepancy: boolWhen storing results, also save per-observation log discrepancies. Default:
False.store: boolSave results on the model. Default:
True.progressbar: boolDisplay progress. Default:
True.
Returns#
- xarray.Dataset
PPPis the posterior predictive probability of the replicated discrepancy being at least as large as the observed one.PPP_mcseestimates Monte Carlo uncertainty for ordered states when available.n_obscounts factors.D_obs,D_repandD_diffkeep thechainanddrawaxes and any chosen grouping dimension.
Notes#
Use stored replicas only with their original fit. Continuous Beta ratings need a continuous predictive check. Extreme PPP values suggest the selected discrepancy exposes a mismatch.
Examples#
Use a fitted Model. The output below comes from the HEXACO TIRT example.
Check the three pairs in B1 separately. Each row reports the predictive check and the number of observed responses for that pair.
check = model.chi_ppp(
blocks=["B1"],
groupby="pair",
draws=64,
random_seed=45,
store=False,
progressbar=False,
)
columns = ["statement_1", "statement_2", "n_obs", "PPP"]
print(check[["PPP", "n_obs"]].to_dataframe()[columns].round(2).to_string(index=False))
statement_1 statement_2 n_obs PPP
i1 i2 120 0.53
i1 i3 120 0.22
i2 i3 120 0.27