Difference between revisions of "GLUE analysis"

From SourceWiki
Jump to navigation Jump to search
m
 
(15 intermediate revisions by the same user not shown)
Line 2: Line 2:
 
[[Category:Hydrology in R]]
 
[[Category:Hydrology in R]]
  
This is an example of R code to perform a Generalised Likelihood Uncertainty Estimation (GLUE) on a hydrological model. In the example we use topmodel (implimented as topmodel()). Other models can be used as long as they are implemented as an R function.
+
Since I am now at Imperial College London, this page has moved and can now be found on [http://wiki.r-project.org/rwiki/doku.php?id=guides:tutorials:hydrological_data_analysis the wiki page of the R-project].
 
 
We need to install and load library Hmisc for the wgt.quantile() function. See ?wgt.quantile for details.
 
 
 
  library(Hmisc)
 
 
 
Sampling parameter sets from a prior distribution. This example uses the uniform distribution (runif()) sample a parameter set from a prior parameter distribution this example uses the uniform distribution which can be sampled with
 
Runif and scales linearly to the appropriate range using scaling factors a and b
 
 
 
  parameter1 <- a1 + runif(1)*b1
 
  parameter2 <- a2 + runif(1)*b2
 
  ...
 
 
 
  param.set <- c(parameter1,parameter2,...)
 
 
 
Run the model for the calibration period with the generated parameter set to obtain the simulated discharge
 
 
 
  Qsim <- topmodel(param.set,rain,ET0,topidxclasses,...)
 
 
 
Calculate the likelihood of this parameter set using the simulated and observed discharge. The choice of the likelihood function is up to the user, but the Nash - Sutcliffe efficiency is given here as an example:
 
 
 
  eff <- 1 - sum((Qobs - Qsim)^2) / sum((Qobs-mean(Qobs))^2)
 
 
 
NOTE: calculation of the Nash-Sutcliffe efficiency is also implimented in NSeff().
 
 
 
Decide whether the parameter set is behavioural or not and retain the parameter set if behavioural
 
 
 
NOTE: this decision is again subjective. For a more scientifically sound determination of the behavioural limit, see Beven (2006). Here we will use an efficiency of 0.6 as a threshold.
 
The efficiency, parameter set and simulated discharge of a behavioural run are stored in resp. the objects total.eff, total.param.set and total.qsim
 
 
 
  if(eff > 0.6) {
 
      total.eff <- eff
 
      total.param.set <- param.set
 
  }
 
 
 
The above procedure should be repeated until enough behavioural runs are obtained (e.g. using a while()-loop)
 
 
 
Behavioural runs can be added as rows to the total matrices:
 
 
 
  total.eff <- c(total.eff,eff)
 
  total.param.set <- cbind(total.param.set,param.set)
 
 
 
In the next section it is assumed that each column of total.param.set contains a behavioural parameter set and that the corresponding efficiency is found at the same location in the total.eff vector
 
 
 
Rerun the model for the prediction period, using each of the behavioural parameter sets. The simulated discharges are stored in the columns of a matrix called predicted.qsim
 
 
 
  predicted.qsim <- model(total.param.set[,1], rain, ...)
 
 
 
  for(i in 2:dim(param.set)[2]) {
 
      qsim <- model(total.param.set[,i], rain, ...)
 
      predicted.qsim <- cbind(predicted.obs,qobs)
 
  }
 
 
 
Normalise the efficiencies so that they sum up to 1:
 
 
 
  eff <- eff - 0.6
 
  eff <- eff/sum(eff)
 
 
 
Define a quantile for the prediction bounds. Here we take the 0.05 and 0.95 quantiles resulting in 90% prediction limits.
 
 
 
  lower <- 0.05
 
  upper <- 0.95
 
 
 
Create the objects in which we will store the prediction limits:
 
 
 
  Ulimit <- 0
 
  Llimit <- 0
 
 
 
Now we calculate the quantiles for each timestep (this can also be done with apply() function)
 
 
 
  for(i in 1:dim(predicted.qsim)[1]) {
 
      Llimit[i] <- wtd.quantile(predicted.qsim[i,],weights = eff, probs = L, normwt=T)
 
      Ulimit[i] <- wtd.quantile(predicted.qsim[i,],weights = eff, probs = U, normwt=T)
 
  }
 
 
 
If everything went well, the final prediciton limits are in Llimit and Ulimit.
 
 
 
===Final notes===
 
 
 
* If topmodel is used, some loops can be avoided because topmodel() can work on entire parameter set matrices. It can also return the Nash-Sutcliffe efficiency directly (see the topmodel page)
 
* The procedure can be very memory intensive because all simulated discharges for all parameter sets are stored in memory (the matrix predicted.qsim). If the model can give output per timestep, the above procedure can be repeated for each timestep separately to reduce memory usage
 
 
 
===References===
 
 
 
* Beven, K., and Binley, A. The future of distributed models: Model calibration and uncertainty prediction. Hydrological Processes 6 (1992), 279-298.
 
* Beven, K. A manifesto for the equifinality thesis. Journal of Hydrology 320 (2006), 18-36.
 

Latest revision as of 18:13, 12 August 2009


Since I am now at Imperial College London, this page has moved and can now be found on the wiki page of the R-project.