Visualizing Patterns over Time

Statistics 4868/6610 Data Visualization

Prof. Eric A. Suess

2/1/2015

Introduction

Today in the computer lab we will go over some examples of time series data using

  • R
  • tableau

Examples from the book

Recall that the data files and relate R code can be downloaded from the book's website. Book

We will look as some of the examples from Chapter 4

Hot Dog Eating, bargraphs with R

The Hot Dog Eating example gives a good idea how to work with R to make bargraphs.

Try the author's program bars.R

  • Note the use of the for loop and the if-then-else statement to color specific bars in the graph
  • Note the use of the time labeling.

Hot Dog Eating, bargraphs with tableau

Reproduce the graph from bars.R that is on page 96 using tableau.

First note that the hot-dogs-contest-winners.csv file is considered a Text File by tableau.

The Columns shelf will be Year and the Rows shelf will be SUM(Dogs eaten).

To color code the years with a new recoded, drag New record to the Marks Color.

Hot Dog Eating, map movie with tableau

Now produce a map movie of the Hot Dog Eating data showing the changing country of origin by time.

Longitude is the Column

Latitute if the Row

And Year is the Pages

Hot Dog Eating, stacked bargraphs with R

The Hot Dog Eating example gives a good idea how to work with R to make bargraphs.

Try the author's program stackedbars.R

FlowingData subscribers, time plot with R

The FlowingData Subscribers example give a good idea of how to work with R to make time plots.

Try the author's program scatter.R

What does type=“h” do in a plot() command?

What does the points() command do?

FlowingData subscribers, time plot with tableau

Now reproduce the graph from scatter.R that is on page 116 using tableau.

First note that the flowingdata_subscribers.csv file is considered a Text File by tableau.

The Columns shelf will be DAY(Date) and the Rows shelf will be SUM(Subscribers).

Change the Marks to Bar and change the Size.

World Population, time plot with tableau

Reproduce the graph from timeseries.R that is on page 120 using tableau.

US Postage, step chart with R

The US Postage example gives a good idea how to work with R to make step charts.

A step chart is for data in time that changes at a spcific time. US Postage rates change on specific dates.

Try the author's program step.R

US Postage, step chart with R

Reproduce the plots on page 126.

What does type=“s” do in a plot() command?

What does the points() command do?

Smoothing Data with R

When looking at time series data it is common to examine time series plots for an underlying trend. The trend may linear or nonliear or may be periodic.

The use of linear regression is common to see linear and nonlinear (quadratic, cubic, etc.) trends.

The use of LOESS is commonly used when the data is not periodic. LOESS is locally weighted scatterplot smoothing.

LOESS gives an easy way to smooth the data. Small slices are fitted with a low-degree polynomial, then the small curves a put together.

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

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?

In R

decompose( )

Johnson & Johnson stock price with R

library(astsa) 

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

plot of chunk unnamed-chunk-1

Johnson & Johnson stock price with R

library(astsa) 

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

plot of chunk unnamed-chunk-2

Johnson & Johnson stock price, decompose with R

plot(decompose(jj))

plot of chunk unnamed-chunk-3

Johnson & Johnson stock price, ACF with R

acf(jj)

plot of chunk unnamed-chunk-4

Johnson & Johnson stock price, PCF with R

pacf(jj)

plot of chunk unnamed-chunk-5