# Simulated data from an exponential distribution (xi = 0)
threshold <- 0.5
gdata <- data.frame(y1 = threshold + rexp(n = 3000, rate = 2))
fit <- vglm(y1 ~ 1, gpd(threshold = threshold), gdata, trace = TRUE)
head(fitted(fit))
coef(fit, matrix = TRUE) # xi should be close to 0
Coef(fit)
summary(fit)
fit@extra$threshold # Note the threshold is stored here
# Check the 90 percentile
ii <- depvar(fit) < fitted(fit)[1, "90%"]
100 * table(ii) / sum(table(ii)) # Should be 90%
# Check the 95 percentile
ii <- depvar(fit) < fitted(fit)[1, "95%"]
100 * table(ii) / sum(table(ii)) # Should be 95%
plot(depvar(fit), col = "blue", las = 1,
main = "Fitted 90% and 95% quantiles")
matlines(1:length(depvar(fit)), fitted(fit), lty = 2:3, lwd = 2)
# Another example
gdata <- data.frame(x2 = runif(nn <- 2000))
threshold <- 0; xi <- exp(-0.8) - 0.5
gdata <- transform(gdata, y2 = rgpd(nn, scale = exp(1 + 0.1*x2), shape = xi))
fit <- vglm(y2 ~ x2, gpd(threshold), gdata, trace = TRUE)
coef(fit, matrix = TRUE)
# Nonparametric fits
gdata <- transform(gdata, yy = y2 + rnorm(nn, sd = 0.1))
# Not so recommended:
fit1 <- vgam(yy ~ s(x2), gpd(threshold), gdata, trace = TRUE)
par(mfrow = c(2,1))
plotvgam(fit1, se = TRUE, scol = "blue")
# More recommended:
fit2 <- vglm(yy ~ bs(x2), gpd(threshold), gdata, trace = TRUE)
plotvgam(fit2, se = TRUE, scol = "blue")
Run the code above in your browser using DataLab