# This routine is for doing biPlots of time series data that were not sampled at exact # same time. It is based on two series of data. It searches times in first series and then # identifies closest data point in second series that within some minimum distance of first point. Does # not assume any particular ordering of the time series. maxx is the maximum amount of time that # program is allowed to search for matching timepoint in second series and lagg allows # search for points at some lagged distance (and is added to maxx) # # zz and zzz specify which columns to use as y in each of the two data sets. Time(x) is assumed to # be the first column # detre=1 means detrend series using locfit function and plot residuals # plotst <-function(x1,x2,zz=2,zzz=2,maxx=10,lagg=0,detre=1) { tempx1_as.matrix(x1) tempx2_as.matrix(x2) xname1_name.cols(x1) xname2_name.cols(x2) txa_as.vector(tempx1[,1][!is.na(tempx1[,1])]) txb_as.vector(tempx2[,1][!is.na(tempx2[,1])]) tya_as.vector(tempx1[,zz][!is.na(tempx1[,zz])]) tyb_as.vector(tempx2[,zzz][!is.na(tempx2[,zzz])]) ## Detrend by locfit.raw if(detre==1) { fit_locfit.raw(txa,tya,alpha=.2,deg=c(0,3)) tya_residuals(fit) fit_locfit.raw(txb,tyb,alpha=.2,deg=c(0,3)) tyb_residuals(fit) } pairsa_length(txa) pairsb_length(txb) maxx_maxx+lagg prs_ matrix(NA,nrow=pairsa,ncol=2) for(i in 1:pairsa){ prs[i,1]_tya[i] diff_0 y2val_NA p1_txa[i] cmin_1000 for(j in 1:pairsb){ p2_txb[j] diff_abs(p1-p2) lagt_p1-p2 if (diff<=cmin & lagt >=lagg) { y2val_tyb[j] cmin_diff } if (cmin<= maxx) {prs[i,2]_y2val} # Below bracket closes pairsb loop } # Below bracket closes pairsa loop } #closes scipt exportData(prs,"Plotout.xls",type="EXCEL") plot(prs,xlab = xname1[zz], ylab = xname2[zzz]) title(paste(xname2[zzz],"as a function of ",xname1[zz]," lagged by ", as.character(lagg),"Years")) }