# NOT RUN {
## Generate synthetic data, quantiles
x <- as.matrix(seq(0.1, 1, length = 50))
loc <- x^2
scl <- x/2
shp <- seq(-0.1, 0.3, length = length(x))
set.seed(100)
y <- as.matrix(rgev(length(x), location = loc, scale = scl,
shape = shp))
q <- sapply(c(0.1, 0.5, 0.9), qgev, location = loc, scale = scl,
shape = shp)
# }
# NOT RUN {
## Fit ensemble of models with early stopping turned on
weights.on <- gevcdn.bag(x = x, y = y, iter.max = 100,
iter.step = 10, n.bootstrap = 10,
n.hidden = 2)
parms.on <- lapply(weights.on, gevcdn.evaluate, x = x)
## 10th, 50th, and 90th percentiles
q.10.on <- q.50.on <- q.90.on <- matrix(NA, ncol=length(parms.on),
nrow=nrow(x))
for(i in seq_along(parms.on)){
q.10.on[,i] <- qgev(p = 0.1,
location = parms.on[[i]][,"location"],
scale = parms.on[[i]][,"scale"],
shape = parms.on[[i]][,"shape"])
q.50.on[,i] <- qgev(p = 0.5,
location = parms.on[[i]][,"location"],
scale = parms.on[[i]][,"scale"],
shape = parms.on[[i]][,"shape"])
q.90.on[,i] <- qgev(p = 0.9,
location = parms.on[[i]][,"location"],
scale = parms.on[[i]][,"scale"],
shape = parms.on[[i]][,"shape"])
}
## Plot data and quantiles
matplot(cbind(y, q, rowMeans(q.10.on), rowMeans(q.50.on),
rowMeans(q.90.on)), type = c("b", rep("l", 6)),
lty = c(1, rep(c(1, 2, 1), 2)),
lwd = c(1, rep(c(3, 2, 3), 2)),
col = c("red", rep("orange", 3), rep("blue", 3)),
pch = 19, xlab = "x", ylab = "y",
main = "gevcdn.bag (early stopping on)")
# }
Run the code above in your browser using DataLab