In this vignette, we will briefly introduce the random walk model in
ngme2
.
In ngme2
, we currently support random walk model of the
first-order and the second order.
Remeber in ngme2
, all the models has the same form:
where
is the operator matrix,
is the random noise (maybe non-Gaussian),
is the random vector we want to model.
The first-order random walk is constructed assuming independent increments given data (use as location, sorted) of length :
When follows the NIG distribution:
When follows the normal distribution:
where , .
The operator matrix of dimension is
We also provide the special case of circular random walk, which the 1st element and n-th element is connected. In the circular RW(1) case, the operator matrix of dimension is
Similarily, the second-order random walk is constructed assuming the second order difference is independent:
When follows the NIG distribution:
When follows the normal distribution:
where , .
The operator matrix of dimension is
In the circular RW(2) case, the operator matrix of dimension is
Use the f(model = "rw1")
or
f(model = "rw2")
(in formula) to specify a random walk
model.
library(ngme2)
#> This is ngme2 of version 0.6.0
#> - See our homepage: https://davidbolin.github.io/ngme2 for more details.
set.seed(16)
m1 <- f(rexp(5), model="rw1", noise = noise_normal())
m1$operator$K
#> 5 x 5 sparse Matrix of class "dgCMatrix"
#>
#> [1,] 1 . . . .
#> [2,] -1 1 . . .
#> [3,] . -1 1 . .
#> [4,] . . -1 1 .
#> [5,] . . . -1 1
m2 <- f(rnorm(6), model="rw2", cyclic = TRUE)
m2$operator$K
#> 6 x 6 sparse Matrix of class "dgCMatrix"
#>
#> [1,] 1 -2 1 . . .
#> [2,] . 1 -2 1 . .
#> [3,] . . 1 -2 1 .
#> [4,] . . . 1 -2 1
#> [5,] 1 . . . 1 -2
#> [6,] -2 1 . . . 1
Doing the simulation is simple, just pass the corresponding model
into simulate
function.
simulate(m1)
#> sim_1
#> 1 -0.37366877
#> 2 -0.45827890
#> 3 -1.61594885
#> 4 -0.78243995
#> 5 -0.02372775