Fits one ctsem model per subject using the model prior, estimates the empirical marginal distribution of the raw parameters, then fits each subject again using the resulting empirical Bayes prior.
Usage
ctEmpiricalBayesFit(
datalong,
model,
subjects = "all",
priors = TRUE,
optimize = TRUE,
cores = getOption("mc.cores", 2L),
subjectFitArgs = list(),
Npasses = 2,
ebUse = c("rawest", "rawposterior"),
ebRobust = TRUE,
ebOutlierMAD = 6,
ebOutlierQuantiles = c(0.025, 0.975),
ebWinsorize = TRUE,
minsd = 1e-06,
verbose = 0,
progress = TRUE,
...
)Arguments
- datalong
Long format data containing multiple subjects.
- model
Model object from
ctModel. Time independent predictors are not supported. A random-effect-free copy of this model is used for the per-subject fits.- subjects
Vector of subject identifiers to fit, or
'all'.- priors
Logical. Passed to
ctFit; defaults toTRUE.- optimize
Logical. Passed to
ctFit; defaults toTRUE.- cores
Number of subjects to fit in parallel. Each individual subject-level
ctFitcall uses one core.- subjectFitArgs
Named list of additional arguments passed to each
ctFitcall. For optimized fits,optimcontrol$stochasticdefaults toFALSEfor all EB passes unless supplied here or in.... First-pass fits forceoptimcontrol$estonly=TRUE.- Npasses
Total number of subject-wise fitting passes. The default
2fits once with the model prior, builds a marginal empirical Bayes prior, then fits once with that prior. Values above2repeatedly map the previous pass estimates back to the original raw scale, rebuild the marginal EB prior, and refit.- ebUse
'rawest'to build the empirical Bayes prior from first pass point estimates, or'rawposterior'to pool raw posterior samples.- ebRobust
Logical. If TRUE, the empirical Bayes prior is built from robust raw summaries after outlier handling.
- ebOutlierMAD
Positive numeric. Raw values farther than this many MAD-scaled deviations from the median are treated as outliers. Use
InforNULLto disable this rule.- ebOutlierQuantiles
Length two numeric vector of lower and upper quantiles used to bound first-pass raw values, or
NULLto disable.- ebWinsorize
Logical. If TRUE, outlying first-pass raw values are clamped to the outlier bounds before computing the EB prior. If FALSE, they are set to missing for EB prior construction.
- minsd
Lower bound used for empirical raw SDs before model adjustment.
- verbose
Integer from 0 to 2. Passed to
ctFit.- progress
Logical. If TRUE, report the current EB fitting stage and overwrite a single console line with the subject fitting percentage.
- ...
Additional arguments passed to each
ctFitcall.
Value
Object of class ctEmpiricalBayesFit, containing the subject
fit lists and metadata. $initialfits contains the first-pass model
prior fits, $fits contains the final empirical Bayes prior fits, and
$passfits contains every pass. Use summary() to compute final
transformed-parameter means, SDs, covariances, correlations, and outlier
diagnostics.
Details
Works with either backend='stan' or backend='julia', passed via
subjectFitArgs or ...; every per-subject ctFit
call uses the same backend. ebUse='rawposterior' needs each subject
fit to carry posterior draws (the default for both backends' optimised fits,
unless optimcontrol$estonly=TRUE), or a sampled fit
(optimize=FALSE, or for backend='julia' a Laplace fit passed
through ctFitUncertainty with uncertainty = 'sample').