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.
Arguments
- 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 \(\sum_{i=1}^n h_i W_i = 0\). If FALSE, fixes the first element \(W_1 = 0\). Must be TRUE for cyclic models.
Value
An `ngme_operator` object containing the precision matrix and related components for the RW1 model.
Details
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.
Examples
# Non-cyclic constrained RW1 (default)
rw1_default <- rw1(1:5)
print(rw1_default$K)
#> 5 x 5 sparse Matrix of class "dgCMatrix"
#>
#> [1,] 0.5 1 1 1 0.5
#> [2,] -1.0 1 . . .
#> [3,] . -1 1 . .
#> [4,] . . -1 1 .
#> [5,] . . . -1 1.0
# Non-cyclic unconstrained RW1 (fixes first element to 0)
rw1_fixed <- rw1(1:5, constr = FALSE)
print(rw1_fixed$K)
#> 5 x 5 sparse Matrix of class "dgCMatrix"
#>
#> [1,] 1 . . . .
#> [2,] -1 1 . . .
#> [3,] . -1 1 . .
#> [4,] . . -1 1 .
#> [5,] . . . -1 1
# Cyclic RW1 (connects first and last locations)
rw1_cyclic <- rw1(1:5, cyclic = TRUE)
print(rw1_cyclic$K)
#> 6 x 6 sparse Matrix of class "dgCMatrix"
#>
#> [1,] . 0.5 1 1 1 0.5
#> [2,] 1 1.0 -1 . . .
#> [3,] 1 . 1 -1 . .
#> [4,] 1 . . 1 -1 .
#> [5,] 1 . . . 1 -1.0
#> [6,] 1 -1.0 . . . 1.0
# Using with unequally spaced locations
locations <- c(0, 1, 3, 6, 10)
rw1_unequal <- rw1(locations)
print(rw1_unequal$K)
#> 5 x 5 sparse Matrix of class "dgCMatrix"
#>
#> [1,] 0.5 1.5 2.5 3.5 2
#> [2,] -1.0 1.0 . . .
#> [3,] . -1.0 1.0 . .
#> [4,] . . -1.0 1.0 .
#> [5,] . . . -1.0 1
