Zeitreihenanalyse - Übung 7

From StatWiki

Jump to: navigation, search

Exercise

Test whether a seasonal trend component is present in the Amazon returns.

Call:
lm(formula = r ~ cos(omega * t) + sin(omega * t) + cos(2 * omega * 
    t) + sin(2 * omega * t) + cos(3 * omega * t) + sin(3 * omega * 
    t) + cos(4 * omega * t) + sin(4 * omega * t) + cos(5 * omega * 
    t) + sin(5 * omega * t) + cos(6 * omega * t))

Residuals:
     Min       1Q   Median       3Q      Max 
-0.48724 -0.10489 -0.01984  0.11082  0.78618 

Coefficients:
                     Estimate Std. Error t value Pr(>|t|)
(Intercept)         0.0239023  0.0178812   1.337    0.184
cos(omega * t)      0.0041200  0.0252879   0.163    0.871
sin(omega * t)      0.0115978  0.0252879   0.459    0.647
cos(2 * omega * t)  0.0228528  0.0252879   0.904    0.368
sin(2 * omega * t) -0.0325973  0.0252879  -1.289    0.200
cos(3 * omega * t) -0.0004001  0.0252879  -0.016    0.987
sin(3 * omega * t) -0.0213723  0.0252879  -0.845    0.400
cos(4 * omega * t) -0.0183579  0.0252879  -0.726    0.469
sin(4 * omega * t)  0.0100402  0.0252879   0.397    0.692
cos(5 * omega * t) -0.0291981  0.0252879  -1.155    0.250
sin(5 * omega * t)  0.0105670  0.0252879   0.418    0.677
cos(6 * omega * t)  0.0118431  0.0178812   0.662    0.509

Residual standard error: 0.2099 on 126 degrees of freedom
Multiple R-squared: 0.04522,	Adjusted R-squared: -0.03813 
F-statistic: 0.5425 on 11 and 126 DF,  p-value: 0.8709 

Exercise

pdf(rpdf)
rsa=readdataSK("RSAFSNA.csv", "csv")
y.log=log(rsa$VALUE)
y.diff <- diff(y.log); plot(y.diff,xlab="",ylab="",type="l")

n=nrow(rsa)

m <- floor(n/2) # number of frequencies
# floor = the largest integer not greater than
y.dft <- fft(y.diff) # use the fast Fourier transform
y.dft <- y.dft[2:(m+1)] # excl. k=0, k=m+1, m+2, …,n-1

y.p <- (1/(2*pi*n))*(Mod(y.dft))^2 # Mod = modulus
f <- (2*pi/n)*(1:m) # vector of m Fourier frequencies
plot(f,y.p,type="l",xlab="",ylab="",ylim=c(0,0.04), axes=T)
# x=pretty(f)
# axis(1,f[1:5],sapply(1:m, function(x) parse(text=paste(x,"*frac(2*pi, n)",sep="")))[1:5],padj=0.5)

#