#Some functions for the ESSRES statistic lecture #Handle with care, they are basically untested. tlaepple@awi.de 12.May.09 #Blocksampling with given blocklength blocksample<-function(data,blocklength=10) { nblock<-ceiling(length(data)/blocklength) #Determine how many blocks we need starts<-floor(runif(nblock,min=1,max=length(data)-blocklength+1)) #random startpoints of the blocks index<-rep(1:blocklength,nblock) + rep(starts,each=blocklength) #create an index vector containing all blocks return(data[index[1:length(data)]]) #Only keep length(data) points } #Effective DOF dof.effective<-function(n,a1) { return(n/(1+2/n*1/(1-a1)*(a1*(n-1/(1-a1))-a1^n*(1-1/(1-a1))))) } #Optimal block length lopt<-function(n,a1) { return(ceiling((6^(0.5)*a1/(1-a1)^2)^(2/3)*n^(1/3))) } #lag-1 scatterplot lagscatterplot<-function(data,...) { plot(data[-1],data[-length(data)],xlab="",ylab="",pch=20, ...) abline(a=0,b=1,lwd=2,col="grey") }