##########################################################################
# SYNTHETIC SCENARIOS
##########################################################################
# create nS=3 fictive climate scenarios with 2 GCMs and 2 RCMs, for a period of nY=20 years
n=20
t=1:n/n
# GCM effects (sums to 0 for each t)
effGCM1 = t*2
effGCM2 = t*-2
# RCM effects (sums to 0 for each t)
effRCM1 = t*1
effRCM2 = t*-1
# These climate scenarios are a sum of effects and a random gaussian noise
scenGCM1RCM1 = effGCM1 + effRCM1 + rnorm(n=n,sd=0.5)
scenGCM1RCM2 = effGCM1 + effRCM2 + rnorm(n=n,sd=0.5)
scenGCM2RCM1 = effGCM2 + effRCM1 + rnorm(n=n,sd=0.5)
Y.synth = rbind(scenGCM1RCM1,scenGCM1RCM2,scenGCM2RCM1)
# Here, scenAvail indicates that the first scenario is obtained with the combination of the
# GCM "GCM1" and RCM "RCM1", the second scenario is obtained with the combination of
# the GCM "GCM1" and RCM "RCM2" and the third scenario is obtained with the combination
# of the GCM "GCM2" and RCM "RCM1".
scenAvail.synth = data.frame(GCM=c('GCM1','GCM1','GCM2'),RCM=c('RCM1','RCM2','RCM1'))
##########################################################################
# RUN QUALYPSO
##########################################################################
# call main QUALYPSO function: two arguments are mandatory:
# - Y: Climate projections for nS scenarios and nY time steps. if Y is a matrix nS x nY, we
# run QUALYPSO nY times, for each time step. If Y is an array nG x nS x nY, for nG grid points,
# we run QUALYPSO nG times, for each grid point, for one time step specified using the argument
# iFut
# - scenAvail: matrix or data.frame of available combinations nS x nEff. The number of
# characteristics nEff corresponds to the number of main effects that will be included in the
# ANOVA model. In the following example, we have nEff=2 main effects corresponding to the GCMs
# and RCMs.
# Many options can be specified in the argument "listOption". When ANOVAmethod=="QUALYPSO"
# a Bayesian inference is performed. Here, we change the default values for nBurn and nKeep
# in order to speed up computation time for this small example. However, it must be noticed
# that convergence and sampling of the posterior distributions often require higher values
# for these two arguments.
listOption = list(nBurn=100,nKeep=100,ANOVAmethod="QUALYPSO",quantilePosterior=c(0.025,0.5,0.975))
# run QUALYPSO
QUALYPSO.synth = QUALYPSO(Y=Y.synth, scenAvail=scenAvail.synth, X=2001:2020, listOption=listOption)
##########################################################################
# SOME PLOTS
##########################################################################
# plot grand mean
plotQUALYPSOgrandmean(QUALYPSO.synth,xlab="Years")
# plot main GCM effects
plotQUALYPSOeffect(QUALYPSO.synth,nameEff="GCM",xlab="Years")
# plot main RCM effects
plotQUALYPSOeffect(QUALYPSO.synth,nameEff="RCM",xlab="Years")
# plot fraction of total variance for the differences sources of uncertainty
plotQUALYPSOTotalVarianceDecomposition(QUALYPSO.synth,xlab="Years")
# plot mean prediction and total variance with the differences sources of uncertainty
plotQUALYPSOMeanChangeAndUncertainties(QUALYPSO.synth,xlab="Years")
#____________________________________________________________
# EXAMPLE OF QUALYPSO WHEN THE PREDICTOR IS TIME
#____________________________________________________________
# list of options
listOption = list(typeChangeVariable='abs')
# call QUALYPSO
QUALYPSO.time = QUALYPSO(Y=Y,scenAvail=scenAvail,X=X_time_vec,
Xfut=Xfut_time,listOption=listOption)
# grand mean effect
plotQUALYPSOgrandmean(QUALYPSO.time,xlab="Years")
# main GCM effects
plotQUALYPSOeffect(QUALYPSO.time,nameEff="GCM",xlab="Years")
# main RCM effects
plotQUALYPSOeffect(QUALYPSO.time,nameEff="RCM",xlab="Years")
# mean change and associated uncertainties
plotQUALYPSOMeanChangeAndUncertainties(QUALYPSO.time,xlab="Years")
# variance decomposition
plotQUALYPSOTotalVarianceDecomposition(QUALYPSO.time,xlab="Years")
#____________________________________________________________
# EXAMPLE OF QUALYPSO WHEN THE PREDICTOR IS THE GLOBAL TEMPERATURE
#____________________________________________________________
# list of options
listOption = list(typeChangeVariable='abs')
# call QUALYPSO
QUALYPSO.globaltas = QUALYPSO(Y=Y,scenAvail=scenAvail,X=X_globaltas,
Xfut=Xfut_globaltas,listOption=listOption)
# grand mean effect
plotQUALYPSOgrandmean(QUALYPSO.globaltas,xlab="Global warming (Celsius)")
# main GCM effects
plotQUALYPSOeffect(QUALYPSO.globaltas,nameEff="GCM",xlab="Global warming (Celsius)")
# main RCM effects
plotQUALYPSOeffect(QUALYPSO.globaltas,nameEff="RCM",xlab="Global warming (Celsius)")
# mean change and associated uncertainties
plotQUALYPSOMeanChangeAndUncertainties(QUALYPSO.globaltas,xlab="Global warming (Celsius)")
# variance decomposition
plotQUALYPSOTotalVarianceDecomposition(QUALYPSO.globaltas,xlab="Global warming (Celsius)")
Run the code above in your browser using DataLab