# Example 1: Simulated data
gdata = data.frame(y = rgumbel(n = 1000, loc = 100, scale = exp(1)))
fit = vglm(y ~ 1, egumbel(perc = NULL), gdata, trace = TRUE)
coef(fit, matrix = TRUE)
Coef(fit)
head(fitted(fit))
with(gdata, mean(y))
# Example 2: Venice data
(fit = vglm(cbind(r1,r2,r3,r4,r5) ~ year, data = venice,
gumbel(R = 365, mpv = TRUE), trace = TRUE))
head(fitted(fit))
coef(fit, mat = TRUE)
vcov(summary(fit))
sqrt(diag(vcov(summary(fit)))) # Standard errors
# Example 3: Try a nonparametric fit ---------------------
# Use the entire data set, including missing values
y = as.matrix(venice[,paste("r",1:10,sep = "")])
fit1 = vgam(y ~ s(year, df = 3), gumbel(R = 365, mpv = TRUE),
data = venice, trace = TRUE, na.action = na.pass)
fit1@y[4:5,] # NAs used to pad the matrix
# Plot the component functions
par(mfrow = c(2,1), mar = c(5,4,.2,1)+0.1, xpd = TRUE)
plot(fit1, se = TRUE, lcol = "blue", scol = "green", lty = 1,
lwd = 2, slwd = 2, slty = "dashed")
# Quantile plot --- plots all the fitted values
par(mfrow = c(1,1), bty = "l", mar = c(4,4,.2,3)+0.1, xpd = TRUE, las = 1)
qtplot(fit1, mpv = TRUE, lcol = c(1,2,5), tcol = c(1,2,5), lwd = 2,
pcol = "blue", tadj = 0.1, ylab = "Sea level (cm)")
# Plot the 99 percentile only
par(mfrow = c(1,1), mar = c(3,4,.2,1)+0.1, xpd = TRUE)
year = venice[["year"]]
matplot(year, y, ylab = "Sea level (cm)", type = "n")
matpoints(year, y, pch = "*", col = "blue")
lines(year, fitted(fit1)[,"99%"], lwd = 2, col = "red")
# Check the 99 percentiles with a smoothing spline.
# Nb. (1-0.99) * 365 = 3.65 is approx. 4, meaning the 4th order
# statistic is approximately the 99 percentile.
par(mfrow = c(1,1), mar = c(3,4,2,1)+0.1, xpd = TRUE, lwd = 2)
plot(year, y[,4], ylab = "Sea level (cm)", type = "n",
main = "Red is 99 percentile, Green is a smoothing spline")
points(year, y[,4], pch = "4", col = "blue")
lines(year, fitted(fit1)[,"99%"], lty = 1, col = "red")
lines(smooth.spline(year, y[,4], df = 4), col = "darkgreen", lty = 2)
Run the code above in your browser using DataLab