STAT 451, Day 19

Visualizing Patterns over Time

Unemployment Data, step chart with R

The Unemployment example gives a good idea how to work with R to smooth time series data using LOESS.

Try the author's program loess.R or try

Activity Five: loess.Rmd

Unemployment Data, step chart with R

What does the function lines() do?

What does the function scatter.smooth() do?

Recall Time Series Models

Basic Models

  • Additive model \[ Y_t=T_t+S_t+I_t \]
  • Multiplicative model \[ Y_t=T_t*S_t*I_t \]

What would a log transformation to to the multiplicative model?

Recall Time Series Models

In R

decompose( )

Or

stl()

Johnson & Johnson stock price with R

library(astsa) 
plot(jj, type="o", ylab="Quarterly 
     Earnings per Share")

plot of chunk unnamed-chunk-3

Johnson & Johnson stock price with R

library(astsa) 

plot(log(jj), type="o", ylab="Quarterly 
     Earnings per Share")

plot of chunk unnamed-chunk-4

Time Series random error - white noise

x <- ts(rnorm(50))
plot(x)

plot of chunk unnamed-chunk-5

Johnson & Johnson stock price, decompose with R

Using the Additive Model. Not so good!

plot(decompose(jj, "additive"))

plot of chunk unnamed-chunk-6

Johnson & Johnson stock price, decompose with R

Using the Multiplicative Model. This is better!

plot(decompose(jj, "multiplicative"))

plot of chunk unnamed-chunk-7

Johnson & Johnson stock price, decompose

Note: If we take the log() of the time series the heteroskedasticity is removed.

plot(decompose(log(jj),"additive"))

plot of chunk unnamed-chunk-8