# NOT RUN {
set.seed(2988)
serie <- rand.GEV(120, xi=40, alfa=20, k=-0.4)
serie100 <- serie[1:100]
serie100[serie100 < 250] <- NA
serie20 <- serie[101:120]
serie <- c(serie100, serie20)
plot(serie, type="h", ylim=c(0, 600), xlab="",
ylab="Annual flood peaks [m3/s]", lwd=3)
abline(h=0)
points(serie100, col=2)
# }
# NOT RUN {
# Using only sistematic data
only_sist <- BayesianMCMC (xcont=serie20, nbpas=5000, nbchaines=3, varparameters0=c(70, 20, 0.5),
confint=c(0.05, 0.95), dist="GEV")
plot(only_sist, which=c(1:3), ask=TRUE, ylim=c(1,600))
only_sist <- BayesianMCMCcont(only_sist)
plot(only_sist, which=c(1:3), ask=TRUE, ylim=c(1,600))
only_sist <- BayesianMCMCcont(only_sist)
plot(only_sist, which=c(1:3), ask=TRUE, ylim=c(1,600))
# Adding the information that the threshold 250 m3/s was exceeded
# 3 times in the past 100 years
with_hist_thresh <- BayesianMCMC (xcont=serie20, infhist=rep(250,3),
nbans=100, seuil=250,
nbpas=5000, nbchaines=3,
confint=c(0.05, 0.95), dist="GEV")
plot(with_hist_thresh, which=c(1:3), ask=TRUE, ylim=c(1,600))
# Assuming that the 3 historical events are known with high uncertainty
with_hist_limits <- BayesianMCMC (xcont=serie20,
infhist=c(320,320,250),
suphist=c(360,400,270),
nbans=100, seuil=250,
nbpas=5000, nbchaines=3,
confint=c(0.05, 0.95), dist="GEV")
plot(with_hist_limits, which=c(1:3), ask=TRUE, ylim=c(1,600))
# Assuming that the 3 historical events are perfectly known
with_hist_known <- BayesianMCMC (xcont=serie20, xhist=serie100[!is.na(serie100)],
nbans=100, seuil=250,
nbpas=5000, nbchaines=3,
confint=c(0.05, 0.95), dist="GEV")
plot(with_hist_known, which=c(1:3), ask=TRUE, ylim=c(1,600))
# Perception threshold without available information on floods
without_info <- BayesianMCMC (xcont=serie20, xhist=-1,
nbans=100, seuil=2400,
nbpas=5000, nbchaines=3,
confint=c(0.05, 0.95), dist="GEV")
plot(without_info, which=c(1:3), ask=TRUE, ylim=c(1,600))
# Using one reasonable a-priori distribution
fNORM3 <- function (x) {
# x = vector of values
# mu = vector of means
mu = c(44, 26, -0.40)
# CM = covariance matrix
CM = matrix(c(13, 7.8, -0.055,
7.8, 15, -0.42,
-0.055, -0.42, 0.056), nrow=3, ncol=3)
CMm1 <- solve(CM)
term2 <- exp(-((x - mu) %*% CMm1 %*% (x - mu))/2)
term1 <- 1/(2*pi)^(3/2)/sqrt(det(CM))
term1*term2
}
with_hist_known2 <- BayesianMCMC (xcont=serie20, xhist=serie100[!is.na(serie100)],
nbans=100, seuil=250,
nbpas=5000, nbchaines=3, apriori=fNORM3,
confint=c(0.05, 0.95), dist="GEV")
plot(with_hist_known2, 5)
plot(with_hist_known2, 4)
plot(with_hist_known, 4)
plot(with_hist_known)
plot(with_hist_known2)
# Using one non-reasonable a-priori distribution
fNORM3 <- function (x) {
# x = vector of values
# mu = vector of means
mu = c(30, 50, -0.10)
# CM = covariance matrix
CM = matrix(c(13, 7.8, -0.055,
7.8, 15, -0.42,
-0.055, -0.42, 0.056), nrow=3, ncol=3)
CMm1 <- solve(CM)
term2 <- exp(-((x - mu) %*% CMm1 %*% (x - mu))/2)
term2
}
with_hist_known3 <- BayesianMCMC (xcont=serie20, xhist=serie100[!is.na(serie100)],
nbans=100, seuil=250,
nbpas=5000, nbchaines=3, apriori=fNORM3,
confint=c(0.05, 0.95), dist="GEV")
plot(with_hist_known3, 5)
plot(with_hist_known3, 4)
plot(with_hist_known, 4)
plot(with_hist_known)
plot(with_hist_known3)
# }
# NOT RUN {
# }
# NOT RUN {
# Assuming that the historical events are perfectly known and there are 4 different thresholds
# The data file is presenting this way:
# xhist nbans seuil
# 6000 55 6000
# 7400 28 7250
# 6350 8 3050
# 4000 0 3050
# 4550 0 3050
# 3950 0 3050
# 7550 58 2400
# 4650 0 2400
# 3950 0 2400
## Warning: nbans and seuil should have the same length as xhist.
# So when a threshold is exceeded several times, replicate it as many times it is exceeded
# and part the number of years of exceedance into the number of times of exceedance
# (the way you part the nbans vector is not important, what is important is that you have
# length(nbans)=length(xhist) and the total of years for one same threshold equals the number
# of years covered by the perception threshold)
xhist_thres <- c(6000, 7400, 6350, 4000, 4550, 3950, 7550, 4650, 3950)
seuil_thres <- c(6000, 7250, rep(3050, 4), rep(2400, 3))
nbans_thres <- c(55, 28, 8, 0, 0, 0, 58, 0, 0)
# The threshold at 6000 has been exceeded for 55 years, the one at 7250 for 28 years,
# the one at 3050 for 8 years and the one at 2400 for 58 years
with_hist_known_several_thresholds <- BayesianMCMC (xcont=serie20,
xhist=xhist_thres,
nbans=nbans_thres, seuil=seuil_thres,
nbpas=5000, nbchaines=3,
confint=c(0.05, 0.95), dist="GEV",
varparameters0=c(NA, NA, 0.5))
plot(with_hist_known_several_thresholds, which=c(1:3), ask=TRUE)
## REGIONAL:
# Regional analysis, assuming that the 3 historical events are perfectly known and
# there are 2 perception thresholds
regional_with_hist_known <- BayesianMCMCreg (xcont=serie20,
scont=c(rep(507,9),rep(2240,11)),
xhist=serie100[!is.na(serie100)],
shist=c(495, 495, 87),
nbans=c(100, 0, 50), seuil=c(312, 312, 221),
nbpas=5000, nbchaines=3,
confint=c(0.05, 0.95), dist="GEV",
varparameters0=c(NA, NA, NA, 0.5))
plot(regional_with_hist_known, which=1:3, ask=TRUE, ylim=c(1,600))
surf=c(571, 2240)
plotBayesianMCMCreg_surf(regional_with_hist_known, surf)
# }
Run the code above in your browser using DataCamp Workspace