challenge_4
Adithya Parupudi
Author

Adithya Parupudi

Published

August 18, 2022

Code
library(tidyverse)

knitr::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE)

Read in data

Code
feds<-read_csv("_data/FedFundsRate.csv",
                        show_col_types = FALSE)
feds
# A tibble: 904 × 10
    Year Month   Day Federal F…¹ Feder…² Feder…³ Effec…⁴ Real …⁵ Unemp…⁶ Infla…⁷
   <dbl> <dbl> <dbl>       <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>
 1  1954     7     1          NA      NA      NA    0.8      4.6     5.8      NA
 2  1954     8     1          NA      NA      NA    1.22    NA       6        NA
 3  1954     9     1          NA      NA      NA    1.06    NA       6.1      NA
 4  1954    10     1          NA      NA      NA    0.85     8       5.7      NA
 5  1954    11     1          NA      NA      NA    0.83    NA       5.3      NA
 6  1954    12     1          NA      NA      NA    1.28    NA       5        NA
 7  1955     1     1          NA      NA      NA    1.39    11.9     4.9      NA
 8  1955     2     1          NA      NA      NA    1.29    NA       4.7      NA
 9  1955     3     1          NA      NA      NA    1.35    NA       4.6      NA
10  1955     4     1          NA      NA      NA    1.43     6.7     4.7      NA
# … with 894 more rows, and abbreviated variable names
#   ¹​`Federal Funds Target Rate`, ²​`Federal Funds Upper Target`,
#   ³​`Federal Funds Lower Target`, ⁴​`Effective Federal Funds Rate`,
#   ⁵​`Real GDP (Percent Change)`, ⁶​`Unemployment Rate`, ⁷​`Inflation Rate`
# ℹ Use `print(n = ...)` to see more rows

Briefly describe the data

Code
colnames(feds)
 [1] "Year"                         "Month"                       
 [3] "Day"                          "Federal Funds Target Rate"   
 [5] "Federal Funds Upper Target"   "Federal Funds Lower Target"  
 [7] "Effective Federal Funds Rate" "Real GDP (Percent Change)"   
 [9] "Unemployment Rate"            "Inflation Rate"              

All are numeric columns and the last columns have NA values.

Code
print(summarytools::dfSummary(feds,
                        varnumbers = FALSE,
                        plain.ascii  = FALSE, 
                        style        = "grid", 
                        graph.magnif = 0.70, 
                        valid.col    = FALSE),
      method = 'render',
      table.classes = 'table-condensed')

Data Frame Summary

feds

Dimensions: 904 x 10
Duplicates: 0
Variable Stats / Values Freqs (% of Valid) Graph Missing
Year [numeric]
Mean (sd) : 1986.7 (17.2)
min ≤ med ≤ max:
1954 ≤ 1987.5 ≤ 2017
IQR (CV) : 28 (0)
64 distinct values 0 (0.0%)
Month [numeric]
Mean (sd) : 6.6 (3.5)
min ≤ med ≤ max:
1 ≤ 7 ≤ 12
IQR (CV) : 6 (0.5)
12 distinct values 0 (0.0%)
Day [numeric]
Mean (sd) : 3.6 (6.8)
min ≤ med ≤ max:
1 ≤ 1 ≤ 31
IQR (CV) : 0 (1.9)
29 distinct values 0 (0.0%)
Federal Funds Target Rate [numeric]
Mean (sd) : 5.7 (2.6)
min ≤ med ≤ max:
1 ≤ 5.5 ≤ 11.5
IQR (CV) : 4 (0.5)
63 distinct values 442 (48.9%)
Federal Funds Upper Target [numeric]
Mean (sd) : 0.3 (0.1)
min ≤ med ≤ max:
0.2 ≤ 0.2 ≤ 1
IQR (CV) : 0 (0.5)
4 distinct values 801 (88.6%)
Federal Funds Lower Target [numeric]
Mean (sd) : 0.1 (0.1)
min ≤ med ≤ max:
0 ≤ 0 ≤ 0.8
IQR (CV) : 0 (2.4)
4 distinct values 801 (88.6%)
Effective Federal Funds Rate [numeric]
Mean (sd) : 4.9 (3.6)
min ≤ med ≤ max:
0.1 ≤ 4.7 ≤ 19.1
IQR (CV) : 4.2 (0.7)
466 distinct values 152 (16.8%)
Real GDP (Percent Change) [numeric]
Mean (sd) : 3.1 (3.6)
min ≤ med ≤ max:
-10 ≤ 3.1 ≤ 16.5
IQR (CV) : 3.5 (1.1)
113 distinct values 654 (72.3%)
Unemployment Rate [numeric]
Mean (sd) : 6 (1.6)
min ≤ med ≤ max:
3.4 ≤ 5.7 ≤ 10.8
IQR (CV) : 2.1 (0.3)
71 distinct values 152 (16.8%)
Inflation Rate [numeric]
Mean (sd) : 3.7 (2.6)
min ≤ med ≤ max:
0.6 ≤ 2.8 ≤ 13.6
IQR (CV) : 2.7 (0.7)
106 distinct values 194 (21.5%)

Generated by summarytools 1.0.1 (R version 4.2.1)
2022-09-04

Code
str(feds)
spec_tbl_df [904 × 10] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
 $ Year                        : num [1:904] 1954 1954 1954 1954 1954 ...
 $ Month                       : num [1:904] 7 8 9 10 11 12 1 2 3 4 ...
 $ Day                         : num [1:904] 1 1 1 1 1 1 1 1 1 1 ...
 $ Federal Funds Target Rate   : num [1:904] NA NA NA NA NA NA NA NA NA NA ...
 $ Federal Funds Upper Target  : num [1:904] NA NA NA NA NA NA NA NA NA NA ...
 $ Federal Funds Lower Target  : num [1:904] NA NA NA NA NA NA NA NA NA NA ...
 $ Effective Federal Funds Rate: num [1:904] 0.8 1.22 1.06 0.85 0.83 1.28 1.39 1.29 1.35 1.43 ...
 $ Real GDP (Percent Change)   : num [1:904] 4.6 NA NA 8 NA NA 11.9 NA NA 6.7 ...
 $ Unemployment Rate           : num [1:904] 5.8 6 6.1 5.7 5.3 5 4.9 4.7 4.6 4.7 ...
 $ Inflation Rate              : num [1:904] NA NA NA NA NA NA NA NA NA NA ...
 - attr(*, "spec")=
  .. cols(
  ..   Year = col_double(),
  ..   Month = col_double(),
  ..   Day = col_double(),
  ..   `Federal Funds Target Rate` = col_double(),
  ..   `Federal Funds Upper Target` = col_double(),
  ..   `Federal Funds Lower Target` = col_double(),
  ..   `Effective Federal Funds Rate` = col_double(),
  ..   `Real GDP (Percent Change)` = col_double(),
  ..   `Unemployment Rate` = col_double(),
  ..   `Inflation Rate` = col_double()
  .. )
 - attr(*, "problems")=<externalptr> 

Tidy Data (as needed)

replacing NA with 0

Code
feds<- feds %>% replace_na(list(`Federal Funds Target Rate`=0, 
                                `Federal Funds Upper Target`=0, 
                                `Federal Funds Lower Target`=0, 
                                `Inflation Rate`=0, 
                                `Real GDP (Percent Change)` =0,
                                `Unemployment Rate` =0,
                                `Effective Federal Funds Rate`=0))

checking for comments at EOF

Code
tail(feds)
# A tibble: 6 × 10
   Year Month   Day Federal Fu…¹ Feder…² Feder…³ Effec…⁴ Real …⁵ Unemp…⁶ Infla…⁷
  <dbl> <dbl> <dbl>        <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>
1  2016    12     1            0    0.5     0.25    0.54       0     4.7     2.2
2  2016    12    14            0    0.75    0.5     0          0     0       0  
3  2017     1     1            0    0.75    0.5     0.65       0     4.8     2.3
4  2017     2     1            0    0.75    0.5     0.66       0     4.7     2.2
5  2017     3     1            0    0.75    0.5     0          0     0       0  
6  2017     3    16            0    1       0.75    0          0     0       0  
# … with abbreviated variable names ¹​`Federal Funds Target Rate`,
#   ²​`Federal Funds Upper Target`, ³​`Federal Funds Lower Target`,
#   ⁴​`Effective Federal Funds Rate`, ⁵​`Real GDP (Percent Change)`,
#   ⁶​`Unemployment Rate`, ⁷​`Inflation Rate`

Identify variables that need to be mutated

Renaming column names as they are too long

Code
colnames(feds)
 [1] "Year"                         "Month"                       
 [3] "Day"                          "Federal Funds Target Rate"   
 [5] "Federal Funds Upper Target"   "Federal Funds Lower Target"  
 [7] "Effective Federal Funds Rate" "Real GDP (Percent Change)"   
 [9] "Unemployment Rate"            "Inflation Rate"              
Code
feds<-feds %>% 
  rename("TargetRate" = `Federal Funds Target Rate`, 
         "UpperTarget"=`Federal Funds Upper Target`, 
         "EffectiveRate"=`Effective Federal Funds Rate`,
         "GDP%Change"=`Real GDP (Percent Change)`,
         "InflationRate"=`Inflation Rate`)
feds
# A tibble: 904 × 10
    Year Month   Day TargetRate UpperT…¹ Feder…² Effec…³ GDP%C…⁴ Unemp…⁵ Infla…⁶
   <dbl> <dbl> <dbl>      <dbl>    <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>
 1  1954     7     1          0        0       0    0.8      4.6     5.8       0
 2  1954     8     1          0        0       0    1.22     0       6         0
 3  1954     9     1          0        0       0    1.06     0       6.1       0
 4  1954    10     1          0        0       0    0.85     8       5.7       0
 5  1954    11     1          0        0       0    0.83     0       5.3       0
 6  1954    12     1          0        0       0    1.28     0       5         0
 7  1955     1     1          0        0       0    1.39    11.9     4.9       0
 8  1955     2     1          0        0       0    1.29     0       4.7       0
 9  1955     3     1          0        0       0    1.35     0       4.6       0
10  1955     4     1          0        0       0    1.43     6.7     4.7       0
# … with 894 more rows, and abbreviated variable names ¹​UpperTarget,
#   ²​`Federal Funds Lower Target`, ³​EffectiveRate, ⁴​`GDP%Change`,
#   ⁵​`Unemployment Rate`, ⁶​InflationRate
# ℹ Use `print(n = ...)` to see more rows