# 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) # -- File "CDatasets2012.csv" containing the climatic data # -------------------------------------------------------------------------------- # Results : # -- Plot the selected squared SRC contained in matrix AS with time # -------------------------------------------------------------------------------- # Parameters : # -- AS a matrix containing all the SRC indices # -- p the total number of parameters of the model # -- names the names of the parameters of the model to be plotted (from one to p) # -- xlim, ylim the bounds of the plot # -------------------------------------------------------------------------------- # Actions : # -- Load the data # -- Compute time and bounds # -- Compute the squared SRC with their confidence intervals for the parameters selected # -- Plot them # -------------------------------------------------------------------------------- plotAllSquared<-function(AS,p,names,xlim,ylim) { Temp <- as.matrix(read.csv('/Users/paulb/Documents/Data/Kenya/CDatasets2012.csv',header = FALSE,sep = ";")) # We load this to be abble to name the x axis # Parameters of the Plot t<-nrow(AS)/p NPr<-length(names) #xlim<-c(1,t) #ylim<-c(0,0.1) Leg<-NULL; # Bounds of the plot plot.new() plot.window(xlim, ylim) axis(1, at=seq(1,t+1,by=t/200), labels=Temp[seq(1,t+1,by=t/200),1])#Un trait tout les 30 axis(2, las=1, at=0.1*0:10) box() for (i in 1:NPr){ # Select the lines corresponding to one parameter ASsub<-subset(AS, !regexpr(names[i],row.names(AS))==-1) # Find the values of the SRC and square them Values<-ASsub$original-ASsub$bias ValuesSq<-Values^2 #Find the correct squred c.i. interval SubN<-ncol(ASsub); Min<-ASsub$"min. c.i." Max<-ASsub$"max. c.i." MinSq<-NULL MaxSq<-NULL for (j in 1:t) { a<-Min[j]; b<-Max[j]; if ((a<0) & (b<0)) { MinSq<-c(MinSq,b*b) MaxSq<-c(MaxSq,a*a) } else if ((a<0) & (b>0)) { MinSq<-c(MinSq,0) MaxSq<-c(MaxSq,max(a*a,b*b)) } else { MinSq<-c(MinSq,a*a) MaxSq<-c(MaxSq,b*b) } } # Define the colors of the lines cols<-rainbow(2, s = 0.5, v = 0.8, start = i/p, end = i/p+5*i/(10*p), alpha = 1) Leg<-c(Leg,cols[1]) # Plot the values and the c. i. lines(ValuesSq, type="o", col=cols[1], pch=i) lines(MinSq, type="o", col=cols[2],pch=i) lines(MaxSq, type="o", col=cols[2],pch=i) #polygon(c(1:t,rev(1:t)),c(Min,rev(Max)),col=cols[3]) } # Legend and labels title(main=paste("SRC squared variation in time for WCT"), col.main="red", font.main=4) title(xlab="Time", col.lab=rgb(0,0.5,0)) title(ylab=paste("SRC squared"), col.lab=rgb(0,0.5,0)) legend("topright", names, cex=0.8, col=Leg, pch=1:NPr, horiz=TRUE); }