Project

General

Profile

« Previous | Next » 

Revision c9e2af49

Added by Benoit Parmentier over 12 years ago

GAM LST, major modifications to create GAM+Kriging code, task #364

View differences:

climate/research/oregon/interpolation/GAM_LST_reg.R
1 1
####################Interpolation of Tmax for 10 dates.#####################
2
#This script interpolates station values for the Oregon case study. This program loads the station data from a shapefile
3
#and perform 8 regressions using the general additive model (GAM). Note that this program:
4
#1)assumes that the shapefile in the current working 
2
#This script interpolates station values for the Oregon case study using a two stage regression.
3
#This program loads the station data from a shape file and perform 8 regressions using general additive model (GAM) followed by kriging on the residuals.
4
#It uses LST monthly averages as input variables.
5
#Note that this program:
6
#1)assumes that the shape file is in the current working 
5 7
#2)extract relevant variables from raster images before performing the regressions. 
6
#This scripts predicts tmas xsing GAM and LST derived from MOD11A1.
8
#This scripts predicts tmax using ing GAM and LST derived from MOD11A1.
7 9
#Interactions terms are also included and assessed using the RMSE from validation dataset.
8 10
#There are 10 dates used for the GAM interpolation. The dates must be provided as a textfile.
9
#Script created by Benoit Parmentier on April 4, 2012. 
11
#Script created by Benoit Parmentier on May 6, 2012. 
10 12

  
11 13
###Loading r library and packages                                                      # loading the raster package
12 14
library(gtools)                                                                        # loading ...
......
14 16
library(sp)
15 17
library(spdep)
16 18
library(rgdal)
19
library(gstat)
17 20

  
18 21
###Parameters and arguments
19 22

  
20 23
infile1<-"ghcn_or_tmax_b_04142012_OR83M.shp"
21
path<-"/data/computer/parmentier/Data/IPLANT_project/data_Oregon_stations"
22
#path<-"H:/Data/IPLANT_project/data_Oregon_stations"
24
#path<-"/data/computer/parmentier/Data/IPLANT_project/data_Oregon_stations"
25
path<-"H:/Data/IPLANT_project/data_Oregon_stations"
23 26
setwd(path) 
24
infile2<-"dates_interpolation_03052012.txt"                                          #List of 10 dates for the regression
25
infile2<-"list_365_dates_04212012.txt"
27
infile2<-"dates_interpolation_03052012_2dates_test.txt"                                          #List of 10 dates for the regression
26 28
prop<-0.3                                                                            #Proportion of testing retained for validation   
27
out_prefix<-"_05012012_mod8_LST"
29
out_prefix<-"_05062012_Kr_LST"
28 30
infile3<-"LST_dates_var_names.txt"
29 31
infile4<-"models_interpolation_04032012b.txt"
30 32

  
......
34 36
filename<-sub(".shp","",infile1)              #Removing the extension from file.
35 37
ghcn<-readOGR(".", filename)                  #reading shapefile 
36 38

  
37
proj4string(ghcn) #This retrieves the coordinate system for the SDF
38
CRS_ghcn<-proj4string(ghcn) #this can be assigned to mean_LST!!!
39
CRS<-proj4string(ghcn)
40

  
41
mean_LST<- readGDAL("mean_day244_rescaled.rst")  #This reads the whole raster in memory and provide a grid for kriging
42
proj4string(mean_LST)<-CRS #Assigning coordinates information
43

  
39 44

  
40 45
ghcn = transform(ghcn,Northness = cos(ASPECT)) #Adding a variable to the dataframe
41 46
ghcn = transform(ghcn,Eastness = sin(ASPECT))  #adding variable to the dataframe.
......
47 52
LST_dates <-readLines(paste(path,"/",infile3, sep=""))
48 53
models <-readLines(paste(path,"/",infile4, sep=""))
49 54

  
50
results <- matrix(1,length(dates),15)            #This is a matrix containing the diagnostic measures from the GAM models.
55
results <- matrix(1,length(dates),14)            #This is a matrix containing the diagnostic measures from the GAM models.
51 56

  
52
results_AIC<- matrix(1,length(dates),length(models)+3)  
53
results_GCV<- matrix(1,length(dates),length(models)+3)
54
results_DEV<- matrix(1,length(dates),length(models)+3)
55
results_RMSE<- matrix(1,length(dates),length(models)+3)
56
cor_LST_LC1<-matrix(1,length(dates),1)      #correlation LST-LC1
57
cor_LST_LC3<-matrix(1,length(dates),1)      #correlation LST-LC3
58
cor_LST_tmax<-matrix(1,length(dates),1)    #correlation LST-tmax
57
results_AIC<- matrix(1,length(dates),length(models)+2)  
58
results_GCV<- matrix(1,length(dates),length(models)+2)
59
results_DEV<- matrix(1,length(dates),length(models)+2)
60
results_RMSE<- matrix(1,length(dates),length(models)+2)
61
results_RMSE_kr<- matrix(1,length(dates),length(models)+2)
62
cor_LST_LC1<-matrix(1,10,1)      #correlation LST-LC1
63
cor_LST_LC3<-matrix(1,10,1)      #correlation LST-LC3
64
cor_LST_tmax<-matrix(1,10,1)    #correlation LST-tmax
59 65
#Screening for bad values
60 66

  
61 67
ghcn_all<-ghcn
62 68
ghcn_test<-subset(ghcn,ghcn$tmax>-150 & ghcn$tmax<400)
63 69
ghcn_test2<-subset(ghcn_test,ghcn_test$ELEV_SRTM>0)
64 70
ghcn<-ghcn_test2
71
#coords<- ghcn[,c('x_OR83M','y_OR83M')]
65 72

  
66 73
month_var<-c("mm_01","mm_02","mm_03","mm_04","mm_05","mm_06","mm_07","mm_08","mm_09", "mm_10", "mm_11", "mm_12")
67 74
ghcn.subsets <-lapply(dates, function(d) subset(ghcn, date==d)) #this creates a list of 10 subsets data
......
94 101
  ####Regression part 2: GAM models
95 102

  
96 103
  mod1<- gam(tmax~ s(lat) + s (lon) + s (ELEV_SRTM), data=data_s)
97
  #mod2<- gam(tmax~ s(lat,lon,ELEV_SRTM), data=data_s)
98
  mod2<- gam(tmax~ s(lat,lon) + s(ELEV_SRTM), data=data_s)
104
  mod2<- gam(tmax~ s(lat,lon,ELEV_SRTM), data=data_s)
99 105
  mod3<- gam(tmax~ s(lat) + s (lon) + s (ELEV_SRTM) +  s (Northness)+ s (Eastness) + s(DISTOC), data=data_s)
100 106
  mod4<- gam(tmax~ s(lat) + s (lon) + s(ELEV_SRTM) + s(Northness) + s (Eastness) + s(DISTOC) + s(LST), data=data_s)
101 107
  mod5<- gam(tmax~ s(lat,lon) +s(ELEV_SRTM) + s(Northness,Eastness) + s(DISTOC) + s(LST), data=data_s)
102 108
  mod6<- gam(tmax~ s(lat,lon) +s(ELEV_SRTM) + s(Northness,Eastness) + s(DISTOC) + s(LST,LC1), data=data_s)
103 109
  mod7<- gam(tmax~ s(lat,lon) +s(ELEV_SRTM) + s(Northness,Eastness) + s(DISTOC) + s(LST,LC3), data=data_s)
104
  mod8<- gam(tmax~ s(lat,lon) +s(ELEV_SRTM) + s(Northness,Eastness) + s(DISTOC) + s(LST) + s(LC1), data=data_s)
105 110
  
106 111
  ####Regression part 3: Calculating and storing diagnostic measures
112
  
107 113
  results_AIC[i,1]<- dates[i]  #storing the interpolation dates in the first column
108 114
  results_AIC[i,2]<- ns        #number of stations used in the training stage
109 115
  results_AIC[i,3]<- AIC (mod1)
......
113 119
  results_AIC[i,7]<- AIC (mod5)
114 120
  results_AIC[i,8]<- AIC (mod6)
115 121
  results_AIC[i,9]<- AIC (mod7)
116
  results_AIC[i,10]<- AIC (mod8)
117 122
  
118 123
  results_GCV[i,1]<- dates[i]  #storing the interpolation dates in the first column
119 124
  results_GCV[i,2]<- ns        #number of stations used in the training stage
......
124 129
  results_GCV[i,7]<- mod5$gcv.ubre
125 130
  results_GCV[i,8]<- mod6$gcv.ubre
126 131
  results_GCV[i,9]<- mod7$gcv.ubre
127
  results_GCV[i,10]<- mod7$gcv.ubre
128 132
  
129 133
  results_DEV[i,1]<- dates[i]  #storing the interpolation dates in the first column
130 134
  results_DEV[i,2]<- ns        #number of stations used in the training stage
......
135 139
  results_DEV[i,7]<- mod5$deviance
136 140
  results_DEV[i,8]<- mod6$deviance
137 141
  results_DEV[i,9]<- mod7$deviance
138
  results_DEV[i,10]<- mod8$deviance
139 142
  
140 143
  #####VALIDATION: Prediction checking the results using the testing data########
141 144
 
145
  #Automate this using a data frame of size??
142 146
  y_mod1<- predict(mod1, newdata=data_v, se.fit = TRUE) #Using the coeff to predict new values.
143 147
  y_mod2<- predict(mod2, newdata=data_v, se.fit = TRUE)            
144 148
  y_mod3<- predict(mod3, newdata=data_v, se.fit = TRUE) 
......
146 150
  y_mod5<- predict(mod5, newdata=data_v, se.fit = TRUE) 
147 151
  y_mod6<- predict(mod6, newdata=data_v, se.fit = TRUE)
148 152
  y_mod7<- predict(mod7, newdata=data_v, se.fit = TRUE)
149
  y_mod8<- predict(mod8, newdata=data_v, se.fit = TRUE)
150 153
  
151 154
  res_mod1<- data_v$tmax - y_mod1$fit #Residuals for GMA model that resembles the ANUSPLIN interpolation
152 155
  res_mod2<- data_v$tmax - y_mod2$fit   #Residuals for GAM model that resembles the PRISM interpolation                               
......
155 158
  res_mod5<- data_v$tmax - y_mod5$fit
156 159
  res_mod6<- data_v$tmax - y_mod6$fit
157 160
  res_mod7<- data_v$tmax - y_mod7$fit
158
  res_mod8<- data_v$tmax - y_mod8$fit
159 161
  
160 162
  RMSE_mod1 <- sqrt(sum(res_mod1^2)/nv)          
161 163
  RMSE_mod2 <- sqrt(sum(res_mod2^2)/nv)
......
164 166
  RMSE_mod5 <- sqrt(sum(res_mod5^2)/nv)
165 167
  RMSE_mod6 <- sqrt(sum(res_mod6^2)/nv)
166 168
  RMSE_mod7 <- sqrt(sum(res_mod7^2)/nv)
167
  RMSE_mod8 <- sqrt(sum(res_mod8^2)/nv)
168 169

  
169 170
  results_RMSE[i,1]<- dates[i]  #storing the interpolation dates in the first column
170 171
  results_RMSE[i,2]<- ns        #number of stations used in the training stage
......
175 176
  results_RMSE[i,7]<- RMSE_mod5
176 177
  results_RMSE[i,8]<- RMSE_mod6
177 178
  results_RMSE[i,9]<- RMSE_mod7
178
  results_RMSE[i,10]<- RMSE_mod8
179 179
  
180
  #Saving dataset in dataframes
181
  data_name<-paste("ghcn_v_",dates[[i]],sep="")
180
  #Saving dataset in dataframes: residuals from RMSE
181
  
182
#   data_v$mod1<-y_mod1$fit
183
#   data_v$mod2<-y_mod2$fit
184
#   data_v$mod3<-y_mod3$fit
185
#   data_v$mod4<-y_mod4$fit
186
#   data_v$mod5<-y_mod5$fit
187
#   data_v$mod6<-y_mod6$fit
188
#   data_v$mod7<-y_mod7$fit
189
#   
190
#   data_s$mod1<-mod1$fit
191
#   data_s$mod2<-mod2$fit
192
#   data_s$mod3<-mod3$fit
193
#   data_s$mod4<-mod4$fit
194
#   data_s$mod5<-mod5$fit
195
#   data_s$mod6<-mod6$fit
196
#   data_s$mod7<-mod7$fit
197
#   
198
  data_v$res_mod1<-as.numeric(res_mod1)
199
  data_v$res_mod2<-as.numeric(res_mod2)
200
  data_v$res_mod3<-as.numeric(res_mod3)
201
  data_v$res_mod4<-as.numeric(res_mod4)
202
  data_v$res_mod5<-as.numeric(res_mod5)
203
  data_v$res_mod6<-as.numeric(res_mod6)
204
  data_v$res_mod7<-as.numeric(res_mod7)
205
  
206
  data_s$res_mod1<-as.numeric(mod1$residuals)
207
  data_s$res_mod2<-as.numeric(mod2$residuals)
208
  data_s$res_mod3<-as.numeric(mod3$residuals)
209
  data_s$res_mod4<-as.numeric(mod4$residuals)
210
  data_s$res_mod5<-as.numeric(mod5$residuals)
211
  data_s$res_mod6<-as.numeric(mod6$residuals)
212
  data_s$res_mod7<-as.numeric(mod7$residuals)
213
  
214
  ###BEFORE Kringing the data object must be transformed to SDF
215
  
216
  coords<- data_v[,c('x_OR83M','y_OR83M')]
217
  coordinates(data_v)<-coords
218
  proj4string(data_v)<-CRS  #Need to assign coordinates...
219
  coords<- data_s[,c('x_OR83M','y_OR83M')]
220
  coordinates(data_s)<-coords
221
  proj4string(data_s)<-CRS  #Need to assign coordinates..
222
  
223
  #Kriging residuals!!
224

  
225
  for (j in 1:length(models)){
226
    name<-paste("res_mod",j,sep="")
227
    data_s$residuals<-data_s[[name]]
228
    X11()
229
    hscat(residuals~1,data_s,(0:9)*20000) # 9 lag classes with 20,000m width
230
    v<-variogram(residuals~1, data_s)
231
    plot(v)
232
    v.fit<-fit.variogram(v,vgm(1,"Sph", 150000,1))
233
    res_krige<-krige(residuals~1, data_s,mean_LST, v.fit)#mean_LST provides the data grid/raster image for the kriging locations.
234
  
235
    # Kriging visualization of Residuals fit over space
236
  
237
    #spplot.vcov(co_kriged_surf)                           #Visualizing the covariance structure
238
  
239
    res_krig1_s <- overlay(res_krige,data_s)             #This overlays the kriged surface tmax and the location of weather stations
240
    res_krig1_v <- overlay(res_krige,data_v)             #This overlays the kriged surface tmax and the location of weather stations
241
  
242
    name2<-paste("pred_kr_mod",j,sep="")
243
    #Adding the results back into the original dataframes.
244
    data_s[[name2]]<-res_krig1_s$var1.pred
245
    data_v[[name2]]<-res_krig1_v$var1.pred  
246
  
247
    #Calculate RMSE and then krig the residuals....!
248
  
249
    res_mod_kr_s<- data_s$tmax - data_s[[name2]]           #Residuals from kriging.
250
    res_mod_kr_v<- data_v$tmax - data_v[[name2]]           #Residuals from cokriging.
251
  
252
    RMSE_mod_kr_s <- sqrt(sum(res_mod_kr_s^2,na.rm=TRUE)/(nv-sum(is.na(res_mod_kr_s))))                  #RMSE from kriged surface.
253
    RMSE_mod_kr_v <- sqrt(sum(res_mod_kr_v^2,na.rm=TRUE)/(nv-sum(is.na(res_mod_kr_v))))                  #RMSE from co-kriged surface.
254
    #(nv-sum(is.na(res_mod2)))
255
    #Writing out results
256
  
257
    results_RMSE_kr[i,1]<- dates[i]  #storing the interpolation dates in the first column
258
    results_RMSE_kr[i,2]<- ns        #number of stations used in the training stage
259
    results_RMSE_kr[i,j+2]<- RMSE_mod_kr_v
260
    #results_RMSE_kr[i,3]<- res_mod_kr_v
261
    name3<-paste("res_kr_mod",j,sep="")
262
    data_s[[name3]]<-res_mod_kr_s
263
    data_v[[name3]]<-res_mod_kr_v #Writing residuals from kriging
264
    }
265
  data_name<-paste("ghcn_v_",out_prefix,"_",dates[[i]],sep="")
182 266
  assign(data_name,data_v)
183
  data_name<-paste("ghcn_s_",dates[[i]],sep="")
184
  assign(data_name,data_s)
185
  #ghcn_v<-ls(pattern="ghcn_v_")
267
  write.table(data_v, file= paste(path,"/",data_name,".txt",sep=""), sep=" ")
268
  #write out a new shapefile (including .prj component)
269
  outfile<-sub(".shp","",data_name)   #Removing extension if it is present
270
  writeOGR(data_v,".", outfile, driver ="ESRI Shapefile")
186 271
  
187

  
188
  cor_LST_LC1[i]<-cor(ghcn.subsets[[i]]$LST,ghcn.subsets[[i]]$LC1)
189
  cor_LST_LC3[i]<-cor(ghcn.subsets[[i]]$LST,ghcn.subsets[[i]]$LC3)
272
  data_name<-paste("ghcn_s_",out_prefix,"_",dates[[i]],sep="")
273
  assign(data_name,data_s)
274
  write.table(data_s, file= paste(path,"/",data_name,".txt",sep=""), sep=" ")
275
  outfile<-sub(".shp","",data_name)   #Removing extension if it is present
276
  writeOGR(data_s,".", outfile, driver ="ESRI Shapefile")
190 277
  
191
  #end of the for loop #1
278
  # end of the for loop #1
192 279
  }
193 280

  
194 281
## Plotting and saving diagnostic measures
195 282

  
196 283
results_RMSEnum <-results_RMSE
197 284
results_AICnum <-results_AIC
198
mode(results_RMSEnum)<- "numeric"
199
mode(results_AICnum)<- "numeric"
200
# Make it numeric first
201
# Now turn it into a data.frame...
285
mode(results_RMSEnum)<- "numeric"         # Make it numeric first
286
mode(results_AICnum)<- "numeric"          # Now turn it into a data.frame...
202 287

  
203 288
results_table_RMSE<-as.data.frame(results_RMSEnum)
204 289
results_table_AIC<-as.data.frame(results_AICnum)
205
colnames(results_table_RMSE)<-c("dates","ns","mod1", "mod2","mod3", "mod4", "mod5", "mod6", "mod7", "mod8")
206
colnames(results_table_AIC)<-c("dates","ns","mod1", "mod2","mod3", "mod4", "mod5", "mod6", "mod7", "mod8")
290
colnames(results_table_RMSE)<-c("dates","ns","mod1", "mod2","mod3", "mod4", "mod5", "mod6", "mod7")
291
colnames(results_table_AIC)<-c("dates","ns","mod1", "mod2","mod3", "mod4", "mod5", "mod6", "mod7")
207 292

  
293
results_RMSE_kr_num <-results_RMSE_kr
294
mode(results_RMSE_kr_num)<- "numeric"         # Make it numeric first
295
results_table_RMSE_kr<-as.data.frame(results_RMSE_kr_num)
296
colnames(results_table_RMSE_kr)<-c("dates","ns","mod1k", "mod2k","mod3k", "mod4k", "mod5k", "mod6k", "mod7k")
208 297
#results_table_RMSE
298

  
209 299
write.table(results_table_RMSE, file= paste(path,"/","results_GAM_Assessment",out_prefix,".txt",sep=""), sep=",")
210 300
write.table(results_table_AIC, file= paste(path,"/","results_GAM_Assessment",out_prefix,".txt",sep=""),sep=",", append=TRUE)
301
write.table(results_table_RMSE_kr, file= paste(path,"/","results_GAM_Assessment_kr",out_prefix,".txt",sep=""), sep=",")
211 302

  
212
###Analysing the results from the 365 days run: Summarize by month
213

  
214
for(i in 1:nrow(results_table_RMSE)){
215
  date<-results_table_RMSE$dates[i]
216
  date<-strptime(date, "%Y%m%d")
217
  results_table_RMSE$month[i]<-as.integer(strftime(date, "%m"))
218
}
219

  
220
average<-aggregate(cbind(mod1,mod2,mod3,mod4,mod5,mod6,mod7,mod8)~month,data=results_table_RMSE,mean, na.rm=TRUE)
221
average<-aggregate(cbind(mod1,mod2,mod3,mod4,mod5,mod6,mod7,mod8)~month,data=results_table_RMSE, FUN=mean)
222
#average on all the data.frame
223
averaget<-aggregate(results_table_RMSE, by=list(results_table_RMSE$month),FUN=mean, na.rm=TRUE)
224
#mediant<-aggregate(results_table_RMSE, by=list(results_table_RMSE$month),FUN=median, na.rm=TRUE)
225
#average_lowt<-aggregate(results_table_RMSE, by=list(results_table_RMSE$month), FUN=function(v) t.test(v)$conf.int[1])
226
#average_up<-aggregate(cbind(mod1,mod2,mod3,mod4,mod5,mod6,mod7,mod8)~month,data=results_table_RMSE, function(v) t.test(v)$conf.int[2])
227

  
228
median<-aggregate(cbind(mod1,mod2,mod3,mod4,mod5,mod6,mod7,mod8)~month,data=results_table_RMSE, median, na.rm=TRUE)
229
average_low<-aggregate(cbind(mod1,mod2,mod3,mod4,mod5,mod6,mod7,mod8)~month,data=results_table_RMSE, function(v) t.test(v)$conf.int[1])
230
average_up<-aggregate(cbind(mod1,mod2,mod3,mod4,mod5,mod6,mod7,mod8)~month,data=results_table_RMSE, function(v) t.test(v)$conf.int[2])
303
##Visualization of results##
231 304

  
232
mod<-names(averaget)
233
mod<-mod[4:11]
234
#Saving graphic plots
235
for(i in 1:length(mod)){
236
  X11(width=14,height=10)
237
  name<-mod[i]
238
  barplot2(average[[name]],plot.ci=TRUE, ci.l=average_low[[name]], ci.u=average_up[[name]],main="Mean RMSE per month", names.arg=c("Jan", "Feb", "Mar", "Apr", "May", "Jun","Jul", "Aug", "Sep","Oct", "Nov", "Dec"),ylim=c(20,30),ylab="RMSE in tenth deg C",xlab=name)
239
  #title(paste("Sampling RMSE for mod",i,sep=""))
240
  savePlot(paste("barplot_results_RMSE_month_",name,out_prefix,".png", sep=""), type="png")
241
  dev.off() 
242
}
243

  
244

  
245
for(i in 1:length(mod)){
246
  X11(width=14,height=10)
247
  name<-mod[i]
248
  barplot2(average[[name]],plot.ci=TRUE, ci.l=average_low[[name]], ci.u=average_up[[name]],main=paste(" Mean RMSE per month ",name, sep=""), names.arg=c("Jan", "Feb", "Mar", "Apr", "May", "Jun","Jul", "Aug", "Sep","Oct", "Nov", "Dec"),ylim=c(20,30),ylab="RMSE in tenth deg C",xlab=name)
249
  #title(paste("Sampling RMSE for mod",i,sep=""))
250
  savePlot(paste("barplot_results_RMSE_month_",name,out_prefix,".png", sep=""), type="png")
251
  dev.off() 
252

  
253
  X11(width=14,height=10)
254
  name<-mod[i]
255
  hist(results_table_RMSE[[name]],breaks=15, main=paste(" Histogram RMSE_",name, sep=""),xlab=paste("RMSE ",name, sep=""))
256
  savePlot(paste("Hist_results_RMSE_365_",name,out_prefix,".png", sep=""), type="png")
257
  dev.off()
305
for(i in 1:length(dates)){
306
  X11()
307
  RMSE_kr<-results_table_RMSE_kr[i,]
308
  RMSE_ga<-results_table_RMSE[i,]
258 309
  
259
}
260

  
261
for(i in 1:length(mod)){
262
  X11(width=14,height=10)
263
  name<-mod[i]
264
  hist(results_table_RMSE[[name]],breaks=15, main=paste(" Histogram RMSE_",name, sep=""),xlab=paste("RMSE ",name, sep=""))
265
  savePlot(paste("Hist_results_RMSE_365_",name,out_prefix,".png", sep=""), type="png")
266
  dev.off()
267
}
268

  
269
r<-(results_table_RMSE[,3:10]) #selecting only the columns related to models...
270

  
271
mean_r<-mean(r)
272
median_r<-sapply(r, median)
273
sd_r<-sapply(r, sd)
274

  
275
barplot(mean_r,ylim=c(23,26),ylab="RMSE in tenth deg C")
276
barplot(median_r,ylim=c(23,26),ylab="RMSE in tenth deg C",add=TRUE,inside=FALSE,beside=TRUE) # put both on the same plot
277
barplot(sd_r,ylim=c(6,8),ylab="RMSE in tenth deg C") # put both on the same plot
278

  
279
height<-rbind(mean_r,median_r)
280
barplot(height,ylim=c(23,26),ylab="RMSE in tenth deg C",beside=TRUE,legend=rownames(height))
281
barplot(height,ylim=c(23,26),ylab="RMSE in tenth deg C",beside=TRUE, col=c("darkblue","red"),legend=rownames(height)) # put both on the same plot
310
  RMSE_kr<-RMSE_kr[,1:length(models)+2]
311
  RMSE_ga<-RMSE_ga[,1:length(models)+2]
312
  colnames(RMSE_kr)<-names(RMSE_ga)
313
  height<-rbind(RMSE_ga,RMSE_kr)
314
  rownames(height)<-c("GAM","GAM_KR")
315
  height<-as.matrix(height)
316
  barplot(height,ylim=c(0,105),ylab="RMSE in tenth deg C",beside=TRUE,
317
          legend.text=rownames(height),
318
          args.legend=list(x="topright"),
319
          main=paste("RMSE for date ",dates[i], sep=""))
320
  savePlot(paste("Barplot_results_RMSE_GAM_KR_",dates[i],out_prefix,".png", sep=""), type="png")
321
  }
322
  
323
# End of script##########
282 324

  
283
barplot2(mean_r,median_r,ylim=c(23,26),ylab="RMSE in tenth deg C") # put both on the same plot
284
#Collect var explained and p values for each var...
285 325

  
286
# End of script##########
287 326

  
288
names(results_table_RMSE)

Also available in: Unified diff