| rw1 | R Documentation |
Constructs a first-order random walk model for spatial or temporal processes.
The RW1 model assumes that first-order differences \Delta W_i = W_i - W_{i-1}
are independent and identically distributed Gaussian variables.
rw1(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. |
cyclic |
logical, whether the mesh is circular. If TRUE, the first and last locations are treated as neighbors. Cannot be FALSE when constr = TRUE. |
constr |
logical, whether to enforce the sum-to-zero constraint
|
The RW1 model is defined by the precision matrix K that penalizes
first-order differences. The model has different structures depending on the
constraints:
**Non-cyclic, constrained (default)**: The first row of K enforces the
constraint \sum_{i=1}^n h_i W_i = 0, where h_i are the mesh weights.
**Non-cyclic, unconstrained**: The first element is fixed at 0 (W_1 = 0).
**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 always enforced.
The precision matrix is expanded to size (n+1) \times (n+1) to handle
the constraint properly.
An 'ngme_operator' object containing the precision matrix and related components for the RW1 model.
# Non-cyclic constrained RW1 (default)
rw1_default <- rw1(1:5)
print(rw1_default$K)
# Non-cyclic unconstrained RW1 (fixes first element to 0)
rw1_fixed <- rw1(1:5, constr = FALSE)
print(rw1_fixed$K)
# Cyclic RW1 (connects first and last locations)
rw1_cyclic <- rw1(1:5, cyclic = TRUE)
print(rw1_cyclic$K)
# Using with unequally spaced locations
locations <- c(0, 1, 3, 6, 10)
rw1_unequal <- rw1(locations)
print(rw1_unequal$K)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.