rw1: Random Walk Model of Order 1 (RW1)

View source: R/models.R

rw1R Documentation

Random Walk Model of Order 1 (RW1)

Description

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.

Usage

rw1(mesh = NULL, cyclic = FALSE, constr = TRUE)

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.

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.

Value

An 'ngme_operator' object containing the precision matrix and related components for the RW1 model.

Examples

# 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)

ngme2 documentation built on May 20, 2026, 9:10 a.m.