Project

General

Profile

« Previous | Next » 

Revision 4823a232

Added by Benoit Parmentier about 11 years ago

modifications, contribution of covariates, figures and analyses for paper 1, OR

View differences:

climate/research/oregon/interpolation/contribution_of_covariates_paper_interpolation.R
63 63
met_stations_outfiles_obj_file<-"/data/project/layers/commons/data_workflow/output_data_365d_gam_fus_lst_test_run_07172013/met_stations_outfiles_obj_gam_fusion__365d_gam_fus_lst_test_run_07172013.RData"
64 64
CRS_locs_WGS84<-CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +towgs84=0,0,0") #Station coords WGS84
65 65
y_var_name <- "dailyTmax"
66
out_prefix<-"analyses_09092013"
66
out_prefix<-"analyses_09232013"
67 67

  
68 68
#method_interpolation <- "gam_daily"
69 69
covar_obj_file_1 <- "covar_obj__365d_gam_day_lst_comb3_08132013.RData"
......
122 122
###Table 3a, baseline 1: s(lat,lon) 
123 123
#Change here !!! need  to reorder rows based on  mod first
124 124
model_col<-c("Baseline1","Elevation","Northing","Easting","LST","DISTOC","Forest","CANHEIGHT","LST*Forest","LST*CANHEIGHT") # 
125
names_table_col<-c("ΔMAE","ΔRMSE","ΔME","Δr","Model")
125 126
df3a<- as.data.frame(sapply(table_data2,FUN=function(x) x-x[1]))
126 127
df3a<- round(df3a,digit=3) #roundto three digits teh differences
127 128
df3a$Model <-model_col
......
131 132
###Table 3b, baseline 2: s(lat,lon) + s(elev)
132 133

  
133 134
model_col<-c("Baseline2","Northness","Eastness","LST","DISTOC","Forest","CANHEIGHT","LST*Forest","LST*CANHEIGHT")
134
names_table_col<-c("ΔMAE","ΔRMSE","ΔME","Δr","Model")
135 135

  
136 136
df3b <- as.data.frame(sapply(table_data1,FUN=function(x) x-x[1])) #difference between baseline (line 1) and other models
137 137
df3b <- round(df3b,digit=3) #roundto three digits the differences
......
223 223

  
224 224
### Figure 1: Oregon study area
225 225
#3 parameters from output
226
infile_monthly<-list_outfiles$monthly_covar_ghcn_data #outile4 from database_covar script
227
infile_daily<-list_outfiles$daily_covar_ghcn_data  #outfile3 from database_covar script
228
infile_locs<- list_outfiles$loc_stations_ghcn #outfile2? from database covar script
226
#infile_monthly<-list_outfiles$monthly_covar_ghcn_data #outile4 from database_covar script
227
#infile_daily<-list_outfiles$daily_covar_ghcn_data  #outfile3 from database_covar script
228
#infile_locs<- list_outfiles$loc_stations_ghcn #outfile2? from database covar script
229 229

  
230 230
ghcn_dat <- readOGR(dsn=dirname(met_stations_obj$monthly_covar_ghcn_data),
231 231
        sub(".shp","",basename(met_stations_obj$monthly_covar_ghcn_data)))
......
346 346
                      title_plot,y_lab_text,add_CI)
347 347
names(list_param_plot)<-c("list_dist_obj","col_t","pch_t","legend_text","mod_name","x_tick_labels","metric_name",
348 348
                          "title_plot","y_lab_text","add_CI")
349
debug(plot_dst_MAE)
349
#undebug(plot_dst_MAE)
350 350
plot_dst_MAE(list_param_plot)
351 351
title(xlab="Distance to closest fitting station (km)")
352 352

  
......
384 384
legend_text <- c("GAM","Kriging","GWR")
385 385
mod_name<-c("mod1","mod1","mod1")#selected models
386 386
add_CI <- c(TRUE,TRUE,TRUE)
387
CI_bar <- c(TRUE,TRUE,TRUE)
387 388
#add_CI <- c(TRUE,FALSE,FALSE)
388 389

  
389 390
##### plot figure 4 for paper
......
398 399
par(mfrow=c(row_mfrow,col_mfrow))
399 400

  
400 401
metric_name<-"mae"
401
list_param_plot<-list(list_prop_obj,col_t,pch_t,legend_text,mod_name,metric_name,add_CI)
402
names(list_param_plot)<-c("list_prop_obj","col_t","pch_t","legend_text","mod_name","metric_name","add_CI")
402
list_param_plot<-list(list_prop_obj,col_t,pch_t,legend_text,mod_name,metric_name,add_CI,CI_bar)
403
names(list_param_plot)<-c("list_prop_obj","col_t","pch_t","legend_text","mod_name","metric_name","add_CI","CI_bar")
403 404

  
404 405
#debug(plot_prop_metrics)
405 406
plot_prop_metrics(list_param_plot)
......
409 410

  
410 411
#now figure 4b
411 412
metric_name<-"rmse"
412
list_param_plot<-list(list_prop_obj,col_t,pch_t,legend_text,mod_name,metric_name,add_CI)
413
names(list_param_plot)<-c("list_prop_obj","col_t","pch_t","legend_text","mod_name","metric_name","add_CI")
413
list_param_plot<-list(list_prop_obj,col_t,pch_t,legend_text,mod_name,metric_name,add_CI,CI_bar)
414
names(list_param_plot)<-c("list_prop_obj","col_t","pch_t","legend_text","mod_name","metric_name","add_CI","CI_bar")
414 415
plot_prop_metrics(list_param_plot)
415 416
title(main="RMSE for hold out and methods",
416 417
      xlab="Hold out validation/testing proportion",
......
483 484

  
484 485
col_t<-c("red","blue","black")
485 486
pch_t<- 1:length(col_t)
486

  
487 487
##Make this a function???
488 488
y_range<-range(prop_obj_kriging$avg_tb$rmse,prop_obj_kriging_s$avg_tb$rmse)
489 489
#y_range<-range(prop_obj_gam$avg_tb$rmse,prop_obj_gam_s$avg_tb$rmse)
490
plot(prop_obj_gam$avg_tb$rmse ~ prop_obj_gam$avg_tb$prop, ylab="",xlab="",type="b",col=c("red"),pch=pch_t[1],ylim=y_range,lty=2)
491
lines(prop_obj_gam_s$avg_tb$rmse ~ prop_obj_gam_s$avg_tb$prop, ylab="",xlab="",type="b",pch=pch_t[1],ylim=y_range,col=c("red"))
492
lines(prop_obj_gwr_s$avg_tb$rmse ~ prop_obj_gwr_s$avg_tb$prop, ylab="",xlab="",type="b",ylim=y_range,pch=pch_t[3],col=c("black"))
493
lines(prop_obj_gwr$avg_tb$rmse ~ prop_obj_gam$avg_tb$prop, ylab="",xlab="",type="b",ylim=y_range,pch=pch_t[3],,col=c("black"),lty=2)
494
lines(prop_obj_kriging$avg_tb$rmse ~ prop_obj_kriging$avg_tb$prop,ylab="",xlab="", type="b",ylim=y_range,pch=pch_t[2],,col=c("blue"),lty=2)
495
lines(prop_obj_kriging_s$avg_tb$rmse ~ prop_obj_kriging_s$avg_tb$prop,ylab="",xlab="",type="b",ylim=y_range,pch=pch_t[2],col=c("blue"))
490
#plot(prop_obj_gam$avg_tb$rmse ~ prop_obj_gam$avg_tb$prop, ylab="",xlab="",type="b",col=c("red"),pch=pch_t[1],ylim=y_range,lty=2)
491
#lines(prop_obj_gam_s$avg_tb$rmse ~ prop_obj_gam_s$avg_tb$prop, ylab="",xlab="",type="b",pch=pch_t[1],ylim=y_range,col=c("red"))
492
#lines(prop_obj_gwr_s$avg_tb$rmse ~ prop_obj_gwr_s$avg_tb$prop, ylab="",xlab="",type="b",ylim=y_range,pch=pch_t[3],col=c("black"))
493
#lines(prop_obj_gwr$avg_tb$rmse ~ prop_obj_gam$avg_tb$prop, ylab="",xlab="",type="b",ylim=y_range,pch=pch_t[3],,col=c("black"),lty=2)
494
#lines(prop_obj_kriging$avg_tb$rmse ~ prop_obj_kriging$avg_tb$prop,ylab="",xlab="", type="b",ylim=y_range,pch=pch_t[2],,col=c("blue"),lty=2)
495
#lines(prop_obj_kriging_s$avg_tb$rmse ~ prop_obj_kriging_s$avg_tb$prop,ylab="",xlab="",type="b",ylim=y_range,pch=pch_t[2],col=c("blue"))
496 496

  
497 497
plot_ac_holdout_prop<- function(l_prop,l_col_t,l_pch_t,add_CI,y_range){
498 498
  
......
515 515
l_col_t <- c("red","red","black","black","blue","blue")
516 516
l_pch_t <- c(1,1,3,3,2,2)
517 517
l_lty_t <- c(2,1,1,2,2,1)
518
add_CI <- c(TRUE,TRUE,FALSE,FALSE,FALSE,FALSE)
518
add_CI <- c(FALSE,FALSE,FALSE,FALSE,FALSE,FALSE)
519
#add_CI <- c(TRUE,TRUE,TRUE,TRUE,TRUE,TRUE)
519 520
y_range<-c(0.5,3)
520 521

  
521 522
plot_ac_holdout_prop(l_prop,l_col_t,l_pch_t,add_CI,y_range)
522 523

  
523
legend_text <- c("GAM","Kriging","GWR","training","testing")
524
legend_text <- c("GAM","Kriging","GWR")
525
#legend_text <- c("GAM","Kriging","GWR","training","testing")
524 526

  
527
#legend("topleft",legend=legend_text, 
528
#       cex=0.9, pch=c(pch_t,NA,NA),col=c(col_t,"white","white"),lty=c(NA,NA,NA,1,2),bty="n")
525 529
legend("topleft",legend=legend_text, 
526
       cex=0.9, pch=c(pch_t,NA,NA),col=c(col_t,NA,NA),lty=c(NA,NA,NA,1,2),bty="n")
530
       cex=0.9, pch=c(pch_t),col=c(col_t),lty=c(1,1,1),bty="n")
531
legend_text_data <-c("training","testing")
532
legend("top",legend=legend_text_data, 
533
       cex=0.9, lty=c(1,2),bty="n")
534

  
527 535
title(main="Training and testing RMSE for hold out and methods",
528 536
      xlab="Hold out validation/testing proportion",
529 537
      ylab="RMSE (C)")
climate/research/oregon/interpolation/contribution_of_covariates_paper_interpolation_functions.R
370 370
  list_mod_name<-list_param$mod_name
371 371
  metric_name<-list_param$metric_name
372 372
  add_CI <- list_param$add_CI
373
  CI_bar <- list_param$CI_bar
373 374
  
374 375
  for (i in 1:length(list_obj)){
375 376
    
......
387 388
    x<- l$avg_tb$prop
388 389
    y_sd <- unlist(as.data.frame(sd_tb)) #sd_tb
389 390
    
390
    ciw <-y_sd
391 391
    #ciw2   <- qt(0.975, n) * y_sd2 / sqrt(n)
392
    if (CI_bar[i]==TRUE){
393
      ciw   <- qt(0.975, no) * y_sd / sqrt(no)
394
    }else{
395
      ciw <-y_sd
396
    }
392 397
    
393 398
    #plotCI(y=y, x=x, uiw=ciw, col="red", main=paste(" MAE for ",mod_name,sep=""), barcol="blue", lwd=1,
394 399
    #       ylab="RMSE (C)", xlab=xlab_text)
......
450 455
  axis(1,at=1:length(stat_tb[,1]),labels=stat_tb[,1])
451 456
}
452 457

  
453
plot_prop_metrics <-function(list_param){
454
  #
455
  #list_dist_obj: list of dist object 
456
  #col_t: list of color for each 
457
  #pch_t: symbol for line
458
  #legend_text: text for line and symbol
459
  #mod_name: selected models
460
  #
461
  ## BEGIN ##
462
  
463
  list_obj<-list_param$list_prop_obj
464
  col_t <-list_param$col_t 
465
  pch_t <- list_param$pch_t 
466
  legend_text <- list_param$legend_text
467
  list_mod_name<-list_param$mod_name
468
  metric_name<-list_param$metric_name
469
  
470
  for (i in 1:length(list_obj)){
471
    
472
    l<-list_obj[[i]]
473
    mod_name<-list_mod_name[i]
474
    avg_tb<-subset(l$avg_tb,pred_mod==mod_name,select=metric_name) #selecte relevant accuarcy metric
475
    n_tb<-subset(l$n_tb,pred_mod==mod_name,select=metric_name) 
476
    sd_tb<-subset(l$sd_tb,pred_mod==mod_name,select=metric_name) #l$sd_abs_tb[,metric_name]
477
    
478
    #xlab_text<-"holdout proportion"
479
    
480
    no <- unlist(as.data.frame(n_tb))
481
    y <- unlist(as.data.frame(avg_tb))
482
    
483
    x<- l$avg_tb$prop
484
    y_sd <- unlist(as.data.frame(sd_tb)) #sd_tb
485
    
486
    ciw <-y_sd
487
    #ciw2   <- qt(0.975, n) * y_sd2 / sqrt(n)    
488
    ciw   <- qt(0.975, no) * y_sd / sqrt(no)
489
    
490
    if(i==1){
491
      plotCI(y=y, x=x, uiw=ciw, col=col_t[i], barcol="blue", lwd=1,
492
             ylab="", xlab="")
493
      lines(y~x, col=col_t[i],pch=pch_t[i],type="b")      
494
    }else{
495
      lines(y~x, col=col_t[i],pch=pch_t[i],type="b")
496
    }
497
    
498
  }
499
  legend("topleft",legend=legend_text, 
500
         cex=1.2, pch=pch_t,col=col_t,lty=1,bty="n")
501
  #axis(1,at=1:length(stat_tb[,1]),labels=stat_tb[,1])
502
  
503
}
504

  
505 458
#Calculate the difference between training and testing in two different data.frames. Columns to substract are provided.
506 459
diff_df<-function(tb_s,tb_v,list_metric_names){
507 460
  tb_diff<-vector("list", length(list_metric_names))

Also available in: Unified diff