Hi all,
I am sorry for bothering the list, but I hope one of its members can help me.
Currently I am doing a spectral analysis with the help of R. The spectral
density I have calculated as follows:
(The vector q contain some testing numbers.)
> q <-
c(28,28,26,19,16,24,26,24,24,29,29,27,31,26,38,23,13,14,28,19,19,17,22,2,4,5,7,8,14,14,23,23)
> N <- length(q)
> Fourier <- fft(q)/N
> Fourier2 <- ( Re(Fourier)^2 + Im(Fourier)^2) * 2
> SpecDen <- array(0,dim=c(0,N/2-1))
> for (i in 2:(N/2+1))
+ {
+ SpecDen[i-1] <- Fourier2[i]
+ }> SpecDen[N/2] <- SpecDen[N/2]/2
> k <- c(1:(N/2))
> freq <- (N/k)^-1
> plot(freq,SpecDen, type="l", lwd=1, col="blue")
To check if this computation is correct I have summed all Spectral Densities
(SpecDen) and they were equal to the variance, correct thus.
Now I want to test if the peaks I get in this spectrum are statistically
significant. For this I want to use an autoregressive order 1 process (AR1). For
that I have used the following code:
> spec <- ar(q, aic = TRUE, order.max = 1, method="yule-walker")
> f<-seq(0,1/2*3.1415,by=1/2*3.1415/255)
> lines(f,ARSdf(spec$ar), type="l", lwd=2, col="red")
Now I get two lines, which should be somewhat of the same order. In this case
(for this vector) the difference is already a factor 4. But if I use for example
the USTobacco data, the difference is way to large. So I suspect, somewhere in
my use of the ar() function I make a thinking mistake. For example, maybe the
ar() function does not return spectral densities?
Can anybody help me?
Thank you for your time and consideration.
[[alternative HTML version deleted]]