Project

General

Profile

« Previous | Next » 

Revision 25388c36

Added by Benoit Parmentier about 11 years ago

contribution of covariates fig and tables for paper, functions used in script

View differences:

climate/research/oregon/interpolation/contribution_of_covariates_paper_interpolation_functions.R
65 65
  return(tb_list_tmp) #this is  a data.frame
66 66
}
67 67

  
68
calc_stat_from_raster_prediction_obj <-function(raster_prediction_obj,stat){
69
  tb <-raster_prediction_obj$tb_diagnostic_v  #Kriging methods
68
calc_stat_from_raster_prediction_obj <-function(raster_prediction_obj,stat,training=FALSE){
69
  #Calculate statistics from validation and training out of raster_prediction_obj
70
  #If training is TRUE, then using training dataset
71
  
72
  #extract relevant information
73
  if(training==TRUE){
74
    tb <- extract_from_list_obj(raster_prediction_obj$validation_mod_obj,"metrics_s")
75
    rownames(tb)<-NULL #remove row names
76
  }else{
77
    tb <- raster_prediction_obj$tb_diagnostic_v
78
  }
79
  
80
  #Now summarize
70 81
  
71 82
  t<-melt(tb,
72 83
          measure=c("mae","rmse","r","me","m50"), 
......
549 560
  return(tb_list_tmp) #this is  a data.frame
550 561
}
551 562

  
563
calc_stat_month_from_raster_prediction_obj <-function(raster_prediction_obj,stat){
564
  #Calculate monthly averages from tb
565
  #Function
566
  #tb must have a month column month
567
  add_month_tag<-function(tb){
568
    date<-strptime(tb$date, "%Y%m%d")   # interpolation date being processed
569
    month<-strftime(date, "%m")          # current month of the date being processed
570
  }
571
  
572
  ## Beging ##
573
  tb<-raster_prediction_obj$tb_diagnostic_v
574
  tb$month<-add_month_tag(tb)
575
  
576
  t<-melt(tb,
577
          measure=c("mae","rmse","r","me","m50"), 
578
          id=c("pred_mod","month"),
579
          na.rm=T)
580
  
581
  stat_tb<-cast(t,pred_mod+month~variable,stat)
582
  return(stat_tb)
583
}
584

  
552 585

  
553 586
################### END OF SCRIPT ###################
554 587

  

Also available in: Unified diff