Introduction to alfred

Onno Kleen

2017-06-09

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

df
## # A tibble: 1,180 x 2
##          date indpro
##        <date>  <dbl>
##  1 1919-01-01 5.0346
##  2 1919-02-01 4.8121
##  3 1919-03-01 4.6730
##  4 1919-04-01 4.7565
##  5 1919-05-01 4.7843
##  6 1919-06-01 5.0902
##  7 1919-07-01 5.3962
##  8 1919-08-01 5.4797
##  9 1919-09-01 5.3684
## 10 1919-10-01 5.3128
## # ... with 1,170 more rows

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")
df_vintages
## # A tibble: 57 x 3
##          date realtime_period    rgdp
##        <date>          <date>   <dbl>
##  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
##  7 2007-07-01      2008-07-31 11625.7
##  8 2007-10-01      2008-07-31 11620.7
##  9 2008-01-01      2008-07-31 11646.0
## 10 2008-04-01      2008-07-31 11700.6
## # ... with 47 more rows

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"
  )