# R code developed by: # International Research Institute for Climate and Society # Columbia University in the City of New York, USA # Last update: Jully 3, 2013 # -------------------------------------------------------------------------------- # Dependancies : (see each function for further details) # NONE # -------------------------------------------------------------------------------- # Results : # -- A n * length(param_base) matrix of random parameters # -------------------------------------------------------------------------------- # Parameters : # -- n the number of sets of parameters to generate # -- param_min the vector of the minimum values of the parameters # -- param_max the vector of the maximum values of the parameters # -- Dist a key word to choose the type of distribution wanter for the random generation. Can be "Unif" (uniform distribution), "Norm95" (normal distribution with 95% chances of being in the right interval) or "Norm99" (normal distribution with 99% chances of being in the right interval) # -------------------------------------------------------------------------------- # Actions : # -- Select the key word # -- For each parameter, generate a random vector of size n following the specifications # -- Bind all the vectors together # -- Return the matrix X # -------------------------------------------------------------------------------- Random_Param <- function (n, param_min, param_max, Dist){ X <- NULL if (Dist=="Unif") { for (i in 1:length(param_min)) { mini <- param_min[i] maxi <- param_max[i] X <- cbind(X,matrix(runif(n,mini,maxi),nrow=n)) } }else if (Dist=="Norm95"){ for (i in 1:length(param_min)) { mini <- param_min[i] maxi <- param_max[i] moy<-(mini+maxi)/2 err<-(maxi-mini)/(2*2) All<-rnorm(n,moy,err); All[Allmaxi]<-maxi; # Put out-ranged values to maximum bound X <- cbind(X,matrix(All,nrow=n)) } }else if (Dist=="Norm99"){ for (i in 1:length(param_min)) { mini <- param_min[i] maxi <- param_max[i] moy<-(mini+maxi)/2 err<-(maxi-mini)/(2*3) All<-rnorm(n,moy,err); All[Allmaxi]<-maxi; # Put out-ranged values to maximum bound X <- cbind(X,matrix(All,nrow=n)) } } return(X) }