# libraries
library(simts)
library(gmwmx)
= 0.45
phase = 2.5
amplitude = 15
sigma2_wn = 10
sigma2_powerlaw = 0.4
d = 0
bias = 5/365.25
trend = amplitude*cos(phase)
cosU = amplitude*sin(phase) sinU
Let us consider a period of 5 year with daily observations:
= 5*365 n
Using functions implemented in simts
, we generate
realizations from the sum of a White noise and PowerLaw process.
Note that the functions that enable to generate stochastic models
that include Power Law process, Matèrn process or Fractional Gaussian
noise are (for now) only available from the development version of the
package simts
that can be easily installed with:
install.packages("devtools")
::install_github("SMAC-Group/simts") devtools
= WN(sigma2 = sigma2_wn) + PLP(sigma2 = sigma2_powerlaw, d = d) model_i
# define time at which there are jumps
= c(600, 1200)
jump_vec = c(20, 30)
jump_height
# define myseed
=123 myseed
We generate residuals from the stochastic model
# generate residuals
= simts::gen_gts(model = model_i, n= n) eps
Using function create_A_matrix()
, we encode the
intercept, a deterministic vector (trend) and sinusoidal signals in a
matrix \(\boldsymbol{A}\) in order to
compute the deterministic component of the signal in a linear fashion.
Similarly, we define the vector of fixed coefficients denoted by \(\boldsymbol{x}_0\) in the paper.
# add trend and sin
= gmwmx::create_A_matrix(t_nogap = 1:length(eps), n_seasonal = 1, jumps = NULL)
A
# define beta
= c(bias, trend, cosU, sinU)
x_0
# create time series
= A %*% x_0 deterministic_signal
We can graphically represent the functional and stochastic component of the model as follows
plot(deterministic_signal, type="l")
plot(eps)
We can add location shifts (jumps) in the signal as such:
# add trend, gaps and sin
= gmwmx::create_A_matrix(t_nogap = 1:length(eps), n_seasonal = 1, jumps = jump_vec)
A
# define beta
= c(bias, trend, cosU, sinU, jump_height)
x_0
# create time series
= A %*% x_0 deterministic_signal
plot(deterministic_signal, type="l")
plot(eps)
We can then define and plot the generated time series
= deterministic_signal + eps
yy plot(yy)
We define a gnssts
object.
# save signal in temp
= create.gnssts(t = 1:length(yy), y = yy, jumps = jump_vec) gnssts_obj
class(gnssts_obj)
#> [1] "gnssts"
We can save a gnssts
object as a .mom
file
with the function write.gnssts()
write.gnssts(gnssts_obj, filename = "simulated_data.mom")
The saved .mom
file will have the following
structure:
# sampling period 1.000000
# offset 100.000000
# offset 200.000000
1 9.89397119231205
2 8.52434609242207
3 9.32563441388655
4 13.4598690226589
5 8.21468271071893
6 -1.62924569468478
7 17.8036063408026
8 7.13794134326489
9 5.34700832531847
= gmwmx::estimate_gmwmx(x = gnssts_obj,
fit_gmwmx model_string = "wn+powerlaw",
n_seasonal = 1,
theta_0 = c(0.1, 0.1, 0.1),
k_iter = 1)
fit_gmwmx#> GNSS time series model
#>
#> * Model: wn + powerlaw
#>
#> * Functional parameters:
#> bias : +0.778520
#> trend : +0.015804
#> A*cos(U) : +2.366464
#> A*sin(U) : +1.958204
#> jump : +20.061620
#> jump : +30.596085
#>
#> * Stochastic parameters:
#> wn_sigma2 : +11.80775096
#> powerlaw_sigma2 : +11.93347935
#> powerlaw_d : +0.34017417
#>
#> * Estimation time: 0.14 s
plot(fit_gmwmx)
= gmwmx::estimate_gmwmx(x = gnssts_obj,
fit_gmwmx_2 model_string = "wn+powerlaw",
n_seasonal = 1,
theta_0 = c(0.1, 0.1, 0.1),
k_iter = 2)
fit_gmwmx_2#> GNSS time series model
#>
#> * Model: wn + powerlaw
#>
#> * Functional parameters:
#> bias : +0.891683
#> trend : +0.016483
#> A*cos(U) : +2.438139
#> A*sin(U) : +2.043069
#> jump : +19.550541
#> jump : +30.869573
#>
#> * Stochastic parameters:
#> wn_sigma2 : +11.96947053
#> powerlaw_sigma2 : +11.75061286
#> powerlaw_d : +0.34298983
#>
#> * Estimation time: 0.39 s
plot(fit_gmwmx_2)
= gmwmx::estimate_hector(x = gnssts_obj,
fit_mle_hector model_string = "wn+powerlaw",
n_seasonal = 1
)
fit_mle_hector#> GNSS time series model
#>
#> * Model: wn + powerlaw
#>
#> * Functional parameters:
#> bias : -0.889000 +/- 1.5900000000
#> trend : +0.015639 +/- 0.0019873265
#> A*cos(U) : +2.542700 +/- 0.4870740000
#> A*sin(U) : +0.966218 +/- 0.4826000000
#> jump : +18.008400 +/- 1.5199300000
#> jump : +30.626100 +/- 1.5310600000
#>
#> * Stochastic parameters:
#> wn_sigma2 : +9.10561714
#> powerlaw_sigma2 : +17.73165228
#> powerlaw_d : +0.29703100
#>
#> * Estimation time: 20.17 s
plot(fit_mle_hector)