# Simulated data from an exponential distribution (xi=0)
threshold = 0.5
y = threshold + rexp(n=3000, rate=2)
fit = vglm(y ~ 1, gpd(threshold=threshold), trace=TRUE)
fitted(fit)[1:5,]
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
i = fit@y < fitted(fit)[1,"90%"]
100*table(i)/sum(table(i)) # Should be 90%
# Check the 95 percentile
i = fit@y < fitted(fit)[1,"95%"]
100*table(i)/sum(table(i)) # Should be 95%
plot(fit@y, col="blue", las=1, main="Fitted 90% and 95% quantiles")
matlines(1:length(fit@y), fitted(fit), lty=2:3, lwd=2)
# Another example
nn = 2000; threshold = 0; x = runif(nn)
xi = exp(-0.8)-0.5
y = rgpd(nn, scale=exp(1+0.2*x), shape=xi)
fit = vglm(y ~ x, gpd(threshold), trace=TRUE)
coef(fit, matrix=TRUE)
# Nonparametric fits
yy = y + rnorm(nn, sd=0.1)
fit1 = vgam(yy ~ s(x), gpd(threshold), trace=TRUE) # Not so recommended
par(mfrow=c(2,1))
plot(fit1, se=TRUE, scol="blue")
fit2 = vglm(yy ~ bs(x), gpd(threshold), trace=TRUE) # More recommended
plotvgam(fit2, se=TRUE, scol="blue")
Run the code above in your browser using DataLab