| rw2 | R Documentation |
Constructs a second-order random walk model for spatial or temporal processes.
The RW2 model assumes that second-order differences
\Delta^2 W_i = W_i - 2W_{i-1} + W_{i-2} are independent and identically
distributed Gaussian variables.
rw2(mesh = NULL, cyclic = FALSE, constr = TRUE)
mesh |
numerical vector or inla.mesh.1d object, locations to build the mesh. For numerical vectors, assumes equally spaced locations. Must have at least 3 locations. |
cyclic |
logical, whether the mesh is circular. If TRUE, the first and last locations are treated as neighbors with second-order differences computed across the boundary. |
constr |
logical, whether to enforce the sum-to-zero constraint |
The RW2 model is defined by the precision matrix K that penalizes
second-order differences, making it smoother than RW1. The model enforces
constraints to ensure identifiability:
**Non-cyclic (default)**: The first two rows of K enforce constraints:
the first row implements \sum_{i=1}^n h_i W_i = 0 (sum-to-zero),
and the second row implements \sum_{i=1}^n h_i \cdot i \cdot W_i = 0
(removes linear trend). The remaining rows penalize second-order differences.
**Cyclic**: Treats the domain as circular, connecting the first and last locations
as neighbors. The constraint \sum_{i=1}^n h_i W_i = 0 is enforced.
The precision matrix is expanded to size (n+1) \times (n+1) to handle
the constraint and circular structure properly.
An 'ngme_operator' object containing the precision matrix and related components for the RW2 model.
# Non-cyclic RW2 with constraints (default)
rw2_default <- rw2(1:6)
print(rw2_default$K)
# Cyclic RW2 (connects first and last locations)
rw2_cyclic <- rw2(1:6, cyclic = TRUE)
print(rw2_cyclic$K)
# Using with unequally spaced locations
locations <- c(0, 1, 3, 6, 10, 15)
rw2_unequal <- rw2(locations)
print(rw2_unequal$K)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.