library(astsa)

Johnson & Johnson Quarterly Earnings Per Share: 1960-1980

data(jj)
plot(jj,type='o',main='J&J Quarterly Earnings Per Share: 1960-1980',
     ylab='Earnings',xlab='Quarter')

Flu Data

data(flu)
plot(flu,type='o',main='Monthly Pneumonia & Influenza Deaths in USA',
     ylab='Deaths per 10000',xlab='Months')

Global Temperature

data(globtemp)
plot(globtemp,type='o',main='Global mean land-ocean deviation from Average Temp: 1880-2015',ylab='Temperature Deviation',xlab='Years')

Global Temperature (Land Only)

data(globtempl)
plot(globtempl,type='o',main='Global mean land deviation from Average Temp: 1880-2015',ylab='Temperature Deviation',xlab='Years')

Star Data

data(star)
plot(star,
     main='Magnitude of star taken at midnight for 600 consecutive days',
     ylab='Magnitude',xlab='Days')

Random Walk

x <- NULL
x[1] <- 0
for (i in 2:1000) {x[i] = x[i-1] + rnorm(1)}

random_walk <- ts(x)  # convert x vector to time series
plot(random_walk,main='A Random Walk', xlab='Days',lwd=2)

acf(random_walk)  # we see that `random_walk` is not stationary. 

plot(diff(random_walk)) # remove trend component from time series to generate white noise

acf(diff(random_walk))

Lab: Simulating MA(2) process

# Generate noise
noise=rnorm(10000)

# Introduce a variable
ma_2=NULL

# Loop for generating MA(2) process

for(i in 3:10000){
    ma_2[i]=noise[i]+0.7*noise[i-1]+0.2*noise[i-2]
}

# Shift data to left by 2 units
moving_average_process=ma_2[3:10000]

# Put time series structure on a vanilla data
moving_average_process=ts(moving_average_process)

# Partition output graphics as a multi frame of 2 rows and 1 column
par(mfrow=c(2,1))

# plot the process and plot its ACF
plot(moving_average_process, main='A moving average process of order 2', ylab=' ', col='blue',lwd=2)
acf(moving_average_process, main='Correlogram of a moving average process of order 2',lwd=2)