# 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
# generate model
= c(1, 7.5, 10, 15, 20)*365
N
# consider 2 year of data
= N[1]
n = WN(sigma2 = sigma2_wn)
model_i
# define time at which there are jumps
= c(100, 200)
jump_vec = c(10, 20)
jump_height
# define myseed
=123
myseed
# set seed
set.seed(myseed)
# generate residuals
= simts::gen_gts(model = model_i, n= n)
eps
# add trend, gaps and sin
= gmwmx::create_A_matrix(1:length(eps), jump_vec, n_seasonal = 1)
A
# define beta
= c(bias, trend, jump_height, cosU, sinU)
x_0
# create time series
= A %*% x_0 + eps yy
We plot the generated time series
plot(yy)
We add extreme values in the signal
= 30
n_outliers set.seed(123)
=sample(150:350, size = n_outliers)
id_outliers= rnorm(n = n_outliers, mean = max(yy)+10, sd = 5)
val_outliers = val_outliers yy[id_outliers]
We plot the corrupted time series
plot(yy)
We create a gnssts
object
# save signal in temp
= create.gnssts(t = 1:length(yy), y = yy, jumps = jump_vec) gnssts_obj
We remove extreme values from the signal using
removeoutliers
function of Hector
available by
calling remove_outliers_hector()
= remove_outliers_hector(x=gnssts_obj, n_seasonal = 1) clean_yy
We can compare the original and the signal with detected extreme values removed from the signal:
par(mfrow=c(1,2))
plot(yy)
plot(clean_yy$t, clean_yy$y, type = "l", xlab="Time", ylab = "Observation")