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