# 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:
#>
#> * Functional parameters:
#> bias : +0.77852038
#> trend : +0.01580355
#> A*cos(U) : +2.36646389
#> A*sin(U) : +1.95820353
#> jump : +20.06161977
#> jump : +30.59608513
#>
#> * Stochastc parameters:
#> wn_sigma2 : +12.23377791
#> powerlaw_sigma2 : +11.45841384
#> powerlaw_d : +0.34904886
#>
#> * Estimation time: 0.06 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:
#>
#> * Functional parameters:
#> bias : +0.88713871
#> trend : +0.01649642
#> A*cos(U) : +2.43946695
#> A*sin(U) : +2.04648501
#> jump : +19.53675553
#> jump : +30.89067705
#>
#> * Stochastc parameters:
#> wn_sigma2 : +12.30793555
#> powerlaw_sigma2 : +11.37269314
#> powerlaw_d : +0.35012119
#>
#> * Estimation time: 6.73 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:
#>
#> * Functional parameters:
#> bias : -0.88900000 +/- 1.590
#> trend : +0.01563893 +/- 0.002
#> A*cos(U) : +2.54270000 +/- 0.487
#> A*sin(U) : +0.96621800 +/- 0.483
#> jump : +18.00840000 +/- 1.520
#> jump : +30.62610000 +/- 1.531
#>
#> * Stochastc parameters:
#> wn_sigma2 : +9.10561714
#> powerlaw_sigma2 : +17.73165228
#> powerlaw_d : +0.29703100
#>
#> * Estimation time: 20.17 s
plot(fit_mle_hector)