The hardware and bandwidth for this mirror is donated by dogado GmbH, the Webhosting and Full Service-Cloud Provider. Check out our Wordpress Tutorial. If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]dogado.de.
Empirical Bayes subject-wise fitting
This document demonstrates ctEmpiricalBayesFit() for a simple univariate continuous time process. The data contain 50 subjects, each with 80 equally spaced observations. The generating model varies across subjects in:
T0MEANS: subject-specific initial latent level
DRIFT: subject-specific autoregressive continuous time drift
ggplot(dat[dat$id <=4, ], aes(time, Y, group = id, colour =factor(id))) +geom_line(linewidth = .35) +theme_bw()+labs(colour ="subject")
Specify the fitted model
The same model object is used for the empirical Bayes and random-effects workflows. Random effects are requested on the four generating parameters. The empirical Bayes function internally removes those random effects for the per-subject fits, because each subject fit contains only one subject.
ctEmpiricalBayesFit() uses two subject-wise passes by default. First, it fits the model once per subject using the model prior. The raw estimates from these first-pass fits define the marginal empirical Bayes prior. Second, it rewrites the single-subject model transforms so raw normal(0, 1) parameters imply that empirical location and scale, then fits every subject again. The final $fits element contains the final EB-prior fits; $initialfits contains the model-prior fits, and $passfits contains every pass.
The transform adjustment is on the unconstrained raw scale. If the original model transforms a raw parameter q to the model parameter θ as
θ = f(q),
then the EB-adjusted model uses a new local raw parameter z ∼ N(0, 1) and sets
θ = f(μq + σqz),
where μq and σq are the empirical mean and standard deviation of the subject-level raw estimates. For example, a positive parameter with log1p_exp(param) becomes log1p_exp(mu + sigma * param).
If Npasses > 2, each later pass maps the local EB raw estimates back to the original raw scale before recomputing μq and σq. This gives an iterated marginal EB prior, but it still does not encode the empirical covariance among raw parameters.
By default, the EB prior construction is robust to extreme first-pass raw estimates: raw values are winsorized using quantile and MAD bounds, then the prior location and scale are computed with the median and MAD. This protects the second pass from a single subject fit with a very unusual optimum. Set ebRobust = FALSE, or adjust ebOutlierQuantiles, ebOutlierMAD, and ebWinsorize, if you want different behavior.
For optimized fits, the first pass uses optimcontrol$estonly = TRUE, because only point estimates are needed to build the EB prior. The stochastic optimizer is disabled by default for both passes; pass optimcontrol = list(stochastic = TRUE) if you want to override this.
The summary is on the transformed parameter scale, matching the scale users usually inspect in summary(ctFit(...)). The EB covariance is summarized for inspection, but it is not encoded in the adjusted model. eb_fit$adjustedmodel is the random-effect-free single-subject model used for the final pass, with transforms based on marginal EB means and standard deviations only. The full subject fits and raw estimate matrices remain on eb_fit; summary(eb_fit) only returns compact summaries.
The empirical Bayes subject estimates below are separate per-subject estimates from the second pass, using the empirical prior learned from the first pass. The random-effects estimates are posterior subject parameters from the hierarchical fit.
The first EB pass uses the model prior separately for each subject. The final EB pass uses the empirical marginal raw prior estimated from the preceding pass. This comparison isolates the effect of the EB prior update before adding the random-effects model to the comparison.
There are two distinct correlation targets. The population raw random-effects correlation is on the pre-transformation scale, so it should be compared with the generating raw parameter correlations and with raw estimates. Subject-level parameter correlations are on the actual transformed parameter scale, so they should be compared with correlations among the generated truth values.
Correlation and RMSE answer different questions. Correlation is mostly about whether subjects are ranked correctly, while RMSE also penalizes bias and miscalibrated spread. The EB fits can therefore show better correlation if the empirical prior stabilizes noisy individual estimates, but worse RMSE if the subject estimates are shifted or overshrunk relative to the generating values. The random-effects fit can have lower RMSE because it estimates the population distribution and covariance jointly with the subject deviations.
These binaries (installable software) and packages are in development. They may not be fully stable and should be used with caution. We make no claims about them. Health stats visible at Monitor.