
Posterior fitted values for an stLMM fit
fitted.stLMM.RdComputes posterior fitted values for the original data used to fit an
stLMM model. These fitted values include all model components that were
fit: formula offsets, fixed effects, explicit grouped random effects, and
saved or recovered structured latent process effects. Binomial fitted values default to
posterior fitted probabilities, and negative-binomial fitted values default to
posterior fitted mean counts.
Arguments
- object
An object returned by
stLMMorrecover.- summary
Logical; if
TRUE, return posterior mean fitted values. IfFALSE, return the posterior fitted-value sample matrix.- sub_sample
List with optional
startandthinentries used to subset posterior draws. For models with structured process terms, this subsets the saved or recovered latent-process draw indices inobject$recover_iter.- scale
For
family = "binomial", return fitted probabilities on the"response"scale or the linear predictor on the"link"scale. Forfamily = "negative_binomial", return fitted mean counts on the"response"scale or the log mean on the"link"scale. For Gaussian models these scales are identical.- ...
Currently unused.
Value
If summary = TRUE, a numeric vector of posterior mean fitted values for
the original fitted data rows, including rows whose response was missing at fit
time. If summary = FALSE, a matrix with posterior draws in rows and
original data rows in columns. The matrix has a draw_index
attribute giving the original MCMC iteration indices used and, for
summary = FALSE Polya-Gamma fits, a scale attribute.
Details
This method does not predict at new locations. For models with structured
process terms, fitted values require saved or recovered latent process samples.
For Polya-Gamma process models, stLMM() saves in-chain process draws by
default as save_process = list(start = 1, thin = 1) and
recover() subsets them. For Gaussian process models, call
recover() on the fitted object to make those samples available.
Examples
set.seed(1)
dat <- data.frame(
y = rnorm(8),
x = rnorm(8),
time = seq_len(8)
)
fit <- stLMM(
y ~ x + ar1(time),
data = dat,
n_samples = 8,
priors = list(
resid = list(tau_sq = ig(2, 1)),
ar1_1 = list(sigma_sq = ig(2, 1), phi = uniform(-0.8, 0.8))
),
warmup = FALSE,
verbose = FALSE
)
rec <- recover(fit)
mu_hat <- fitted(rec)
mu_draws <- fitted(rec, summary = FALSE)