fishertest <- function(x,Lag.max=50) { #x is a time series to be tested whether it is a white noise by using #the Fisher test #Output: The Fisher test statistic and P-value pgram <- Mod(fft(x))^2/length(x)/2/pi pgram <- pgram[-1] #delete the zero frequency component pgram <- pgram[1:floor(length(x)/2)] #take the first half Fisher <- max(pgram)/mean(pgram) #Fisher statistic P.value <- 1-exp(-exp(-Fisher+log(length(pgram)))) list(Fisher.stat=Fisher, P.value=P.value) }