View source: R/fit_st_nested.R
| fit_st_nested | R Documentation |
Fits y ~ X beta + u_spatial[s] + v_temporal[t] with a spatial field –
areal (icar / bym2 / car_proper) or continuous (hsgp / nngp) –
and a temporal field (rw1 / rw2 / ar1), integrating the spatial
hyperparameter(s), temporal precision, and (for ar1) the temporal
autocorrelation over a hyperparameter grid via the
cpp_nested_laplace_st_* kernels. The fixed-effect posterior is the
grid-marginalised mixture; the spatial and temporal field posterior means are
the grid-weighted latent modes.
fit_st_nested(
y,
X,
spatial_idx,
adjacency,
temporal_idx,
n_times,
spatial_type = c("icar", "bym2", "car_proper", "hsgp", "nngp"),
temporal_type = c("ar1", "rw1", "rw2"),
family = "binomial",
n_trials = NULL,
phi = 1,
cyclic = FALSE,
re_idx = NULL,
n_re_groups = 0L,
sigma_re = 1,
hyperprior = c("proper", "flat"),
control = list(),
coords = NULL,
nn = 10L,
cov_type = 2L,
hsgp_m = 6L,
hsgp_c = 1.5
)
## S3 method for class 'tulpa_st_nested'
print(x, ...)
y |
Response vector. |
X |
Fixed-effects design matrix ( |
spatial_idx |
Integer per-observation spatial-unit index (1-based).
For |
adjacency |
Spatial adjacency (a symmetric 0/1 matrix or |
temporal_idx |
Integer per-observation time index (1-based). |
n_times |
Number of distinct time points. |
spatial_type |
|
temporal_type |
|
family |
Response family (see |
n_trials |
Binomial denominators, or |
phi |
Dispersion passed to the family, held fixed. One convention at
every door: for Defaulted, it conditions at 1 and says so with a warning, since for a
family that reads a dispersion that is a modelling choice rather than a
neutral value. |
cyclic |
Logical; wrap the temporal field (seasonal). Default |
re_idx, n_re_groups, sigma_re |
Optional single iid random-intercept term
alongside the fields (conditioned on |
hyperprior |
The prior an outer hyperparameter axis carries when the
call states no density for it, |
control |
A list of numerical / grid knobs: For The A grid knob PINS the axes it shapes, and a pin always wins – but
pinning is decided by value, not by presence: a knob
set to the engine's own default, or marked with |
coords |
Coordinate matrix for a continuous spatial field, required
when |
nn |
Number of nearest neighbours per location, |
cov_type |
Integer NNGP covariance code ( |
hsgp_m, hsgp_c |
Hilbert-space GP basis size (per dimension, default 6)
and boundary factor (default 1.5), |
x |
A |
... |
Ignored. |
A tulpa_fit (subclass tulpa_nested_laplace) carrying the
fixed-effect posterior (draws via the grid mixture), spatial_effects,
temporal_effects, log_marginal, weights, theta_grid over
(tau_spatial, tau_temporal, rho) for an areal spatial field or
(sigma2, lengthscale, tau_temporal, rho) / (sigma2, phi_gp, tau_temporal, rho) for "hsgp" / "nngp", and family / n_trials /
phi (the
R-level convention), which is what fitted(), residuals(),
posterior_predict() and simulate() read the response family from.
Also carries pareto_k_regime
("spread" / "collapsed_interior" / "collapsed_edge", see
tulpa_nested_laplace_joint()'s return docs for the definition) and
outer_grid_placement ("fixed" or "auto_recentered") plus, on a
"fixed" placement, outer_grid_recenter_declined
("grid_knobs_overridden" / "grid_not_collapsed" /
"no_usable_curvature" / "refit_failed" / "sd_ceiling_unresolved" /
"sd_floor_unresolved"). A recentred fit also carries
outer_grid_pinned_axes, the axes whose knobs were pinned and whose
nodes were therefore kept, and outer_grid_recenter_sd_clamp /
_sd_raw / _sd_used – per moved axis, which mode-SD bound the
placement hit, the SD the stencil measured, and the SD the axis was laid
from. A bound-decline is PER AXIS here: the axes the
mode-find did resolve are still re-placed, and
outer_grid_recenter_sd_declined names the ones that kept their incoming
nodes and on which bound, so a partially re-placed grid is not read as a
fully re-placed one. With every free axis declined the pass reports the
grid as the fixed one it still is.
tulpa() (front door), tulpa_nested_laplace() (single field).
set.seed(1)
n_s <- 16L; n_t <- 8L; N <- 400L
adj <- matrix(0, n_s, n_s)
for (i in 1:(n_s - 1)) adj[i, i + 1] <- adj[i + 1, i] <- 1
s <- sample(n_s, N, TRUE); tt <- sample(n_t, N, TRUE)
us <- as.numeric(scale(cumsum(rnorm(n_s)))); vt <- as.numeric(scale(cumsum(rnorm(n_t))))
x <- rnorm(N)
y <- rbinom(N, 1, plogis(0.2 + 0.5 * x + 0.7 * us[s] + 0.6 * vt[tt]))
fit <- fit_st_nested(y, cbind(1, x), s, adj, tt, n_t, family = "binomial")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.