#Generate a pareto mixture sample of size n with a time varying parameter
theta <- function(t){
0.5+0.25*sin(2*pi*t)
}
n <- 4000
t <- 1:n/n
Theta <- theta(t)
Data <- NULL
set.seed(1240)
for(i in 1:n){
Data[i] <- rparetomix(1, a = 1/Theta[i], b = 1/Theta[i]+5, c = 0.75, precision = 10^(-5))
}
if (FALSE) #For computing time purpose
#choose the bandwidth by cross validation
Tgrid <- seq(0, 1, 0.1)#few points to improve the computing time
hgrid <- bandwidth.grid(0.01, 0.2, 20, type = "geometric")
hcv <- bandwidth.CV(Data, t, Tgrid, hgrid, TruncGauss.kernel,
kpar = c(sigma = 1), pcv = 0.99, CritVal = 3.6, plot = TRUE)
h.cv <- hcv$h.cv
#we modify the Tgrid to cover the data set
Tgrid <- seq(0, 1, 0.02)
hillTs <- hill.ts(Data, t, Tgrid, h = h.cv, TruncGauss.kernel, kpar = c(sigma = 1),
CritVal = 3.6, gridlen = 100, initprop = 1/10, r1 = 1/4, r2 = 1/20)
p <- c(0.999)
pred.quantile.ts <- predict(hillTs, newdata = p, type = "quantile")
true.quantile <- NULL
for(i in 1:n){
true.quantile[i] <- qparetomix(p, a = 1/Theta[i], b = 1/Theta[i]+5, c = 0.75)
}
plot(Tgrid, log(as.numeric(pred.quantile.ts$y)),
ylim = c(0, max(log(as.numeric(pred.quantile.ts$y)))), ylab = "log(0.999-quantiles)")
lines(t, log(true.quantile), col = "red")
lines(t, log(Data), col = "blue")
#comparison with other fixed bandwidths
plot(Tgrid, log(as.numeric(pred.quantile.ts$y)),
ylim = c(0, max(log(as.numeric(pred.quantile.ts$y)))), ylab = "log(0.999-quantiles)")
lines(t, log(true.quantile), col = "red")
hillTs <- hill.ts(Data, t, Tgrid, h = 0.1, TruncGauss.kernel, kpar = c(sigma = 1),
CritVal = 3.6, gridlen = 100,initprop = 1/10, r1 = 1/4, r2 = 1/20)
pred.quantile.ts <- predict(hillTs, p, type = "quantile")
lines(Tgrid, log(as.numeric(pred.quantile.ts$y)), col = "green")
hillTs <- hill.ts(Data, t, Tgrid, h = 0.3, TruncGauss.kernel, kpar = c(sigma = 1),
CritVal = 3.6, gridlen = 100, initprop = 1/10, r1 = 1/4, r2 = 1/20)
pred.quantile.ts <- predict(hillTs, p, type = "quantile")
lines(Tgrid, log(as.numeric(pred.quantile.ts$y)), col = "blue")
hillTs <- hill.ts(Data, t, Tgrid, h = 0.04, TruncGauss.kernel, kpar = c(sigma = 1),
CritVal = 3.6, gridlen = 100, initprop = 1/10, r1 = 1/4, r2 = 1/20)
pred.quantile.ts <- predict(hillTs ,p, type = "quantile")
lines(Tgrid, log(as.numeric(pred.quantile.ts$y)), col = "magenta")
Run the code above in your browser using DataLab