Project

General

Profile

« Previous | Next » 

Revision b0b0ba02

Added by Benoit Parmentier almost 11 years ago

multi timescale function script, small update

View differences:

climate/research/oregon/interpolation/multi_timescales_paper_interpolation_functions.R
4 4
# interpolation code.
5 5
#Functions used in the production of figures and data for the multi timescale paper are recorded.
6 6
#AUTHOR: Benoit Parmentier                                                                      #
7
#DATE: 11/25/2013            
7
#DATE CREATED: 11/25/2013            
8
#DATE MODIFIED: 12/04/2013            
8 9
#Version: 1
9 10
#PROJECT: Environmental Layers project                                       #
10 11
#################################################################################################
......
29 30

  
30 31
#### FUNCTION USED IN SCRIPT
31 32

  
32
function_analyses_paper <-"multi_timescales_paper_interpolation_functions_11252013.R"
33
function_analyses_paper <-"multi_timescales_paper_interpolation_functions_11022013.R"
33 34

  
34 35
plot_transect_m2<-function(list_trans,r_stack,title_plot,disp=FALSE,m_layers){
35 36
  #This function creates plot of transects for stack of raster images.
......
103 104
  return(list_trans_data)
104 105
}
105 106

  
107
### Need to improve this function!!!
108
calc_stat_prop_tb_diagnostic <-function(names_mod,names_id,tb){
109
  
110
  t<-melt(subset(tb,pred_mod==names_mod),
111
          measure=c("mae","rmse","r","me","m50"), 
112
          id=names_id,
113
          na.rm=T)
114
  char_tmp <-rep("+",length=length(names_id)-1)
115
  var_summary <-paste(names_id,sep="",collapse=char_tmp)
116
  var_summary_formula <-paste(var_summary,collpase="~variable")
117
  avg_tb<-cast(t,var_summary_formula,mean)
118
  sd_tb<-cast(t,var_summary_formula,sd)
119
  n_tb<-cast(t,var_summary_formula,length)
120
  #n_NA<-cast(t,dst_cat1~variable,is.na)
121
  
122
  #### prepare returning object
123
  prop_obj<-list(tb,avg_tb,sd_tb,n_tb)
124
  names(prop_obj) <-c("tb","avg_tb","sd_tb","n_tb")
125
  
126
  return(prop_obj)
127
}
128

  
129
#Calculate the difference between training and testing in two different data.frames. Columns to substract are provided.
130
diff_df<-function(tb_s,tb_v,list_metric_names){
131
  tb_diff<-vector("list", length(list_metric_names))
132
  for (i in 1:length(list_metric_names)){
133
    metric_name<-list_metric_names[i]
134
    tb_diff[[i]] <-tb_s[,c(metric_name)] - tb_v[,c(metric_name)]
135
  }
136
  names(tb_diff)<-list_metric_names
137
  tb_diff<-as.data.frame(do.call(cbind,tb_diff))
138
  return(tb_diff)
139
}
106 140

  
107 141
### generate filter for Moran's I function in raster package
108 142
autocor_filter_fun <-function(no_lag=1,f_type="queen"){

Also available in: Unified diff