Revision 846e6174
Added by Benoit Parmentier over 10 years ago
climate/research/oregon/interpolation/multi_timescales_paper_interpolation_functions.R | ||
---|---|---|
5 | 5 |
#Functions used in the production of figures and data for the multi timescale paper are recorded. |
6 | 6 |
#AUTHOR: Benoit Parmentier # |
7 | 7 |
#DATE CREATED: 11/25/2013 |
8 |
#DATE MODIFIED: 03/18/2014
|
|
8 |
#DATE MODIFIED: 04/07/2014
|
|
9 | 9 |
#Version: 4 |
10 | 10 |
#PROJECT: Environmental Layers project # |
11 | 11 |
################################################################################################# |
... | ... | |
528 | 528 |
|
529 | 529 |
} |
530 | 530 |
|
531 |
extract_table_term_factor <- function(i,list_param){ |
|
532 |
#This function generate a linear model for proportion of hold out effect on accuracy |
|
533 |
#Add option to choose MAE later |
|
534 |
|
|
535 |
#First parse arguments |
|
536 |
interpolation_method <- list_param$list_interp_method[[i]] |
|
537 |
tb_mv <- list_param$tb_mv |
|
538 |
|
|
539 |
#Begin script: |
|
540 |
|
|
541 |
list_pred_mod_name <- unique(tb_mv$pred_mod) |
|
542 |
list_prop_cat <- unique(tb_mv$prop_month) |
|
543 |
list_pred_mod_name <- grep(c("mod_kr"),list_pred_mod_name,value=TRUE,invert=TRUE) |
|
544 |
list_mod_table <- vector("list",length=length(list_pred_mod_name)) |
|
545 |
tb_dat<- subset(tb_mv,tb_mv$method_interp==interpolation_method) |
|
546 |
|
|
547 |
for(j in 1:length(list_mod_table)){ |
|
548 |
mod <-lm(rmse~ as.factor(prop_month), |
|
549 |
data=subset(tb_dat,tb_dat$pred_mod==list_pred_mod_name[[j]])) |
|
550 |
term_table <- summary(mod)$coefficients |
|
551 |
list_mod_table[[j]] <- term_table |
|
552 |
} |
|
553 |
names(list_mod_table) <- list_pred_mod_name |
|
554 |
|
|
555 |
tx <- lapply(list_mod_table,function(x){x[,c(1,4)]}) |
|
556 |
tx <-lapply(tx, round,digit=3) |
|
557 |
|
|
558 |
#tx <- format(tx,digits=3) |
|
559 |
|
|
560 |
#column_tab <- paste(format(tx[[1]][,1],digits=3)," ", |
|
561 |
# "(",format(tx[[1]][,2],digits=3),")",sep="") |
|
562 |
#column_tab <-lapply(tx,function(x){paste(format(x[,1],digits=3)," ", |
|
563 |
# "(",format(x[,2],digits=3),")",sep="")}) |
|
564 |
column_tab <-lapply(tx,function(x){as.data.frame(paste(format(x[,1],digits=3)," ", |
|
565 |
"(",format(x[,2],digits=3),")",sep=""))}) |
|
566 |
|
|
567 |
table_method <- as.data.frame(do.call(cbindX,column_tab)) |
|
568 |
names(table_method) <- list_pred_mod_name |
|
569 |
table_method$method_interp <- rep(interpolation_method,nrow(table_method)) |
|
570 |
table_method$prop <- list_prop_cat |
|
571 |
|
|
572 |
mod_table_obj<- list(list_mod_table,table_method) |
|
573 |
names(mod_table_obj) <- c("list_mod_table","table_method") |
|
574 |
return(mod_table_obj) |
|
575 |
} |
|
576 |
|
|
577 |
|
|
578 |
calc_stat_from_tb_list <-function(i,list_param){ |
|
579 |
#Calculate statistics from validation and training out of raster_prediction_obj |
|
580 |
#If training is TRUE, then using training dataset |
|
581 |
|
|
582 |
tb <- list_param$list_tb[[i]] #raster prediction object to use |
|
583 |
stat <- list_param$stat |
|
584 |
training <- list_param$training |
|
585 |
|
|
586 |
#extract relevant information |
|
587 |
if(training==TRUE){ |
|
588 |
rownames(tb)<-NULL #remove row names |
|
589 |
} |
|
590 |
|
|
591 |
#Now summarize |
|
592 |
|
|
593 |
t<-melt(tb, |
|
594 |
measure=c("mae","rmse","r","me","m50"), |
|
595 |
id=c("pred_mod"), |
|
596 |
na.rm=T) |
|
597 |
|
|
598 |
stat_tb<-cast(t,pred_mod~variable,stat) |
|
599 |
return(stat_tb) |
|
600 |
} |
|
601 |
|
|
602 |
|
|
531 | 603 |
################### END OF SCRIPT ################### |
532 | 604 |
|
533 | 605 |
|
Also available in: Unified diff
multi timescale paper revisions draft3, changes to function scripts