Project

General

Profile

« Previous | Next » 

Revision dc5bfc17

Added by Benoit Parmentier almost 12 years ago

Validation, added function to plot boxplot, results over year 2010 for Venezuela

View differences:

climate/research/oregon/interpolation/GAM_fusion_function_multisampling_validation_metrics.R
109 109

  
110 110
}
111 111

  
112
#### Function to create a data.frame from validation obj
113
extract_from_list_obj<-function(obj_list,list_name){
114
  list_tmp<-vector("list",length(obj_list))
115
  for (i in 1:length(obj_list)){
116
    tmp<-obj_list[[i]][[list_name]] #double bracket to return data.frame
117
    list_tmp[[i]]<-tmp
118
  }
119
  tb_list_tmp<-do.call(rbind,list_tmp) #long rownames
120
  return(tb_list_tmp) #this is  a data.frame
121
}
122

  
123
#### Function to plot boxplot from data.frame table of accuracy metrics
124

  
125
boxplot_from_tb <-function(tb_diagnostic,metric_names,out_prefix){
126
  #now boxplots and mean per models
127
  mod_names<-unique(tb_diagnostic$pred_mod) #models that have accuracy metrics
128
  t<-melt(tb_diagnostic,
129
          #measure=mod_var, 
130
          id=c("date","pred_mod","prop"),
131
          na.rm=F)
132
  avg_tb<-cast(t,pred_mod~variable,mean)
133
  
134
  median_tb<-cast(t,pred_mod~variable,median)
135
  tb<-tb_diagnostic
136
  tb_mod_list<-vector("list",length(mod_names))
137
  for(i in 1:length(mod_names)){            # Reorganizing information in terms of metrics 
138
    mod_name_tb<-paste("tb_",mod_names[i],sep="")
139
    tb_mod<-subset(tb, pred_mod==mod_names[i])
140
    assign(mod_name_tb,tb_mod)
141
    tb_mod_list[[i]]<-tb_mod
142
  }
143
  names(tb_mod_list)<-mod_names
144
  mod_metrics<-do.call(cbind,tb_mod_list)
145
  for (j in 1:length(metric_names)){
146
    metric_ac<-metric_names[j]
147
    mod_pat<-glob2rx(paste("*.",metric_ac,sep=""))   
148
    mod_var<-grep(mod_pat,names(mod_metrics),value=TRUE) # using grep with "value" extracts the matching names     
149
    #browser()
150
    test<-mod_metrics[mod_var]
151
    png(paste("boxplot_metric_",metric_ac, out_prefix,".png", sep=""))
152
    boxplot(test,outline=FALSE,horizontal=FALSE,cex=0.5,
153
            ylab=paste(metric_ac,"in degree C",sep=" "))
154
    dev.off()
155
  }
156
  summary_obj<-list(avg_tb,median_tb)
157
  return(summary_obj)  
158
}
159

  
160
## Function to display metrics by months/seasons
161
boxplot_from_tb <-function(tb_diagnostic,metric_names,out_prefix){
162
  #Add code here...
163
}
164

  
112 165
####################################
113 166
############ END OF SCRIPT #########

Also available in: Unified diff