| vcmm | R Documentation |
The main user-facing fit function. Builds the B-spline design and
penalty for one or more varying coefficients in t, computes
the aggregated sufficient statistics, and fits the model using either
the one-step CSL estimator (default) or the iterative SS estimator.
vcmm(
y,
X,
Z,
t,
method = c("auto", "csl", "ss"),
re_cov = c("diag", "kronecker", "separable"),
n_groups = NULL,
q_left = NULL,
Sigma_left_init = NULL,
Sigma_right_init = NULL,
Sigma_2x2_init = NULL,
Sigma_spatial_init = NULL,
Sigma_q_init = NULL,
Omega_G_init = NULL,
n_basis = NULL,
degree = 3L,
lambda = 1,
control = vcmm_control(),
normalize_t = TRUE,
...
)
y |
Numeric response vector of length |
X |
Numeric |
Z |
Numeric |
t |
Numeric vector of length |
method |
Character: |
re_cov |
Character: |
n_groups |
Integer |
q_left |
Integer. The left (within) dimension of the Kronecker
factor. For |
Sigma_left_init |
Optional |
Sigma_right_init |
Optional |
Sigma_2x2_init |
Legacy alias for |
Sigma_spatial_init |
Legacy alias for |
Sigma_q_init |
Alias for |
Omega_G_init |
Alias for |
n_basis |
Integer or |
degree |
Integer. B-spline degree (default 3 = cubic). |
lambda |
Non-negative numeric. Smoothing parameter (default 1). |
control |
A |
normalize_t |
Logical. If |
... |
Further arguments passed to |
Model. For observations i = 1, \ldots, n the fitted
model is
y_i
= \beta_0(t_i) + \sum_{k=1}^{K} x_{ik}\, \beta_k(t_i)
+ z_i^\top \alpha + \varepsilon_i,
where each \beta_k(t) is a cubic B-spline with n_basis
basis functions and a second-order difference penalty, and
\alpha \sim N(0, \Sigma_\alpha) with structure chosen by
re_cov.
Method selection. The default is method = "auto",
which picks "csl" when N \cdot q > 10^5 or q > 50
and "ss" otherwise.
Random-effects covariance. Three structures:
re_cov = "diag": \alpha \sim N(0,
\sigma_\alpha^2 I_q).
re_cov = "kronecker": \alpha \sim N(0,
\Sigma_{\mathrm{left}} \otimes \Sigma_{\mathrm{right}}) with
\Sigma_{\mathrm{left}} of size q_left x q_left
(default q_left = 2; OD-style with origin / destination
blocks). User-facing names Sigma_2x2_init,
Sigma_spatial_init are accepted as aliases.
re_cov = "separable": \alpha \sim N(0,
\Sigma_q \otimes \Omega_G) with Sigma_q of size
q_left x q_left (required, no default) and Omega_G
of size G \times G. User-facing names Sigma_q_init,
Omega_G_init are accepted as aliases for
Sigma_left_init, Sigma_right_init.
Column-stacking convention. For re_cov = "kronecker"
or "separable", the random-effects vector is
\alpha = \mathrm{vec}_{\mathrm{col}}(M) where
M \in \mathbb R^{G \times q_{\mathrm{left}}}, i.e.\
alpha[(k - 1) * G + g] = M[g, k]. The Z matrix must be
constructed so that Z %*% alpha gives the correct random-effect
contribution. ncol(Z) must equal q_left * n_groups.
Identifiability of the right component. The right-side
covariance (Sigma_spatial / Omega_G) is not separately
identifiable from a single \hat\alpha, so it is held fixed at
the user-supplied initial value (default I_G). Supply a
parametric kernel via Sigma_right_init (e.g., exp(-D /
phi) for OD; AR(1) for separable). The left-side covariance
(Sigma_2x2 / Sigma_q) is updated every iteration via the
EM-style estimator (Theorem 1 M_\eta rule) when
control$update_variance = TRUE.
Choosing re_cov. The three modes specify the
assumed covariance structure of the random-effects vector
\alpha; they do not constrain what Z's
entries look like. The distribution of Z (binary
indicators, continuous values, mixed) does not enter this choice
— only the structure of \alpha does. Pick by data shape:
"diag": independent random effects, one per group
or subject, no assumed cross-group dependence. Simplest case.
Use when each group contributes a single offset and groups
are exchangeable.
"kronecker": origin-destination flow data. Every
row of Z activates one origin indicator and one
destination indicator, so ncol(Z) = 2 * G where
G is the number of regions. The 2x2 left block
captures origin/destination dependence; the G \times G
right block captures spatial dependence between regions.
"separable": each group carries multiple
correlated random effects (q_left > 2) — for
example a random intercept plus a random slope per region.
Use when the per-group random-effect dimension exceeds 2.
A vcmm_fit object as returned by fit_ss() or
fit_csl(), augmented with design (basis metadata) and
re_cov. When re_cov is "kronecker" or
"separable", re_cov_state contains the canonical
fields Sigma_left, Sigma_right, plus legacy aliases
Sigma_2x2/Sigma_spatial (when q_left = 2) or
Sigma_q/Omega_G (for separable).
Jalili, L. and Lin, L.-H. (2025). Scalable and Communication-Efficient Varying Coefficient Mixed-Effects Models.
set.seed(1)
n <- 500
t <- runif(n)
x <- runif(n)
Z <- matrix(rnorm(n * 3), n, 3)
alpha_true <- rnorm(3, sd = 0.5)
y <- 2 + sin(2 * pi * t) * x +
as.vector(Z %*% alpha_true) + rnorm(n, sd = 0.5)
fit <- vcmm(y, X = x, Z = Z, t = t,
control = vcmm_control(sigma_eps = 0.5, sigma_alpha = 0.5))
fit
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.