Simulate datasets from a fitted model, refit the model on each simulated dataset, and compare simulated log-likelihood values to the original fit.
Usage
goodness_of_fit(object, nsim, seed = NULL, fit_args = list())Arguments
- object
Output of
lifelihood().- nsim
Number of simulated datasets to generate and refit.
- seed
Optional integer seed for reproducibility.
- fit_args
Named list of additional arguments passed to
lifelihood()when refitting each simulated dataset. By default, refits usen_fit = 1,MCMC = 0, andse.fit = FALSEfor speed.- keep_fits
Whether to store fitted objects for each successful simulation. Default is
FALSE.
Value
A lifelihoodGOF object (list) with:
original_loglik: log-likelihood of the original fitsimulated_loglik: numeric vector of simulated/refitted log-likelihoodsn_success: number of successful refitsn_failed: number of failed refitsp_lower_or_equal: proportion of simulated log-likelihoods lower than or equal to the original valueerrors: per-simulation error messages (if any)fits: optional list of fitted objects (only ifkeep_fits = TRUE)