Introduction to alfred

Onno Kleen

2019-04-01

A quick introduction for downloading FRED and ALFRED data.

Installation

You may install the last stable release via CRAN or the latest development version from github.

install.packages("alfred")
# or
install.packages("devtools")
devtools::install_github("onnokleen/alfred")

Usage

Downloading data is straightforward (for real-time data from ALFRED see below):

library(alfred)
df <- get_fred_series("INDPRO", "indpro")

The output is a data frame

head(df)
##         date indpro
## 1 1919-01-01 5.0124
## 2 1919-02-01 4.7908
## 3 1919-03-01 4.6524
## 4 1919-04-01 4.7355
## 5 1919-05-01 4.7632
## 6 1919-06-01 5.0678

This can be readily used, i.e. for plotting

library(ggplot2)
ggplot(df) +
  geom_line(aes(x = date, y = indpro))

Vintage data

When using get_alfred_series for downloading real-time data sets, there will be an additional column for the respective vintage dates.

df_vintages <-
  get_alfred_series("GDPC1", "rgdp",
                    observation_start = "2007-05-31",
                    realtime_start = "2008-05-31", realtime_end = "2009-03-30")
head(df_vintages)
##         date realtime_period    rgdp
## 1 2007-07-01      2008-05-31 11658.9
## 2 2007-10-01      2008-05-31 11675.7
## 3 2008-01-01      2008-05-31 11701.9
## 4 2007-07-01      2008-06-26 11658.9
## 5 2007-10-01      2008-06-26 11675.7
## 6 2008-01-01      2008-06-26 11703.6

Because of its output being a tidy data frame, it is easy to visualise revisions by

library(ggplot2)

ggplot(df_vintages) +
  geom_line(aes(x = date, y = rgdp, colour = as.factor(realtime_period))) +
  theme_bw() +
  theme(
    legend.title = element_blank(),
    legend.position = "bottom"
  )