### Statistics 6871 - Time Series

### Lab 8

### Introduction to Spectral Analysis

### Again note that Splus is case sensitive!

###########################################################################################

# One frequency example.

t <- (0:256)

A <- 5

phi <- 0

nu <- 1/24

omega <- 2*pi*nu

x.t <- A*sin(omega*t + phi)

tsplot(x.t)

par(mfrow=c(2,2))

spectrum(x.t)

spectrum(x.t, spans=3)

spectrum(x.t, spans=c(3,3))

spectrum(x.t, spans=c(3,5))

# Two frequencies.

t <- (0:256)

A.1 <- 5

A.2 <- 10

phi <- 0

nu.1 <- 1/24

nu.2 <- 1/6

omega.1 <- 2*pi*nu.1

omega.2 <- 2*pi*nu.2

y.t <- A.1*sin(omega.1*t + phi) + A.2*sin(omega.2*t + phi)

tsplot(y.t)

par(mfrow=c(2,2))

spectrum(y.t)

spectrum(y.t, spans=3)

spectrum(y.t, spans=c(3,3))

spectrum(y.t, spans=c(3,5))

# For the inventory data.

It <- rts(scan("I:\\Courswrk\\Stat\\esuess\\Stat6871\\Data_p\\Inventory.txt"))

par(mfrow=c(2,2))

spectrum(It)

spectrum(It, spans=3)

spectrum(It, spans=c(3,3))

spectrum(It, spans=c(3,5))

 

 

 

 

 

 


webmaster: Eric A. Suess    Last Edited: Tuesday, April 25, 2000