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.7.0
#> - See our homepage: https://davidbolin.github.io/ngme2 for more details.
#>
#> Attaching package: 'ngme2'
#> The following object is masked from 'package:stats':
#>
#> ar
set.seed(16)
m1 <- f(rexp(5), model="rw1", noise = noise_normal())
m1$operator$K
#> 5 x 5 sparse Matrix of class "dgCMatrix"
#>
#> [1,] 0.02295832 0.06577409 0.1130829 0.730911 0.6606439
#> [2,] -1.00000000 1.00000000 . . .
#> [3,] . -1.00000000 1.0000000 . .
#> [4,] . . -1.0000000 1.000000 .
#> [5,] . . . -1.000000 1.0000000
m2 <- f(rnorm(6), model="rw2", cyclic = TRUE)
m2$operator$K
#> 7 x 7 sparse Matrix of class "dgCMatrix"
#>
#> [1,] . 0.02159833 0.6093765 0.6305594 0.0630014 0.3724705
#> [2,] 0.02159833 1.00000000 -2.0000000 1.0000000 . .
#> [3,] 0.60937647 . 1.0000000 -2.0000000 1.0000000 .
#> [4,] 0.63055937 . . 1.0000000 -2.0000000 1.0000000
#> [5,] 0.06300140 . . . 1.0000000 -2.0000000
#> [6,] 0.37247049 1.00000000 . . . 1.0000000
#> [7,] 0.35225032 -2.00000000 1.0000000 . . .
#>
#> [1,] 0.3522503
#> [2,] .
#> [3,] .
#> [4,] .
#> [5,] 1.0000000
#> [6,] -2.0000000
#> [7,] 1.0000000
Doing the simulation is simple, just pass the corresponding model
into simulate
function.
simulate(m1)
#> sim_1
#> 1 0.42732713
#> 2 0.13792977
#> 3 -0.01727820
#> 4 -0.05194693
#> 5 0.24731142