library(seasonal)
10 Year Forecast of AirPassengers seasonality
m <- seas(AirPassengers, x11.appendfcst = "yes", forecast.maxlead = 120)
plot(series(m, "x11.adjustfac"))
# Some speed comparison of fwrite and feather: | |
library(data.table) | |
library(feather) | |
# On an AWS EC2 m4.10xlarge with 40 cores: | |
# with 100 mio | |
size <- 100000000 | |
iris2 <- data.table(iris[sample(1:nrow(iris), size, replace = TRUE), ]) |
library(seasonal)
10 Year Forecast of AirPassengers seasonality
m <- seas(AirPassengers, x11.appendfcst = "yes", forecast.maxlead = 120)
plot(series(m, "x11.adjustfac"))
``` r | |
library(seasonal) | |
m <- seas(AirPassengers, regression.variables = c("const", "seasonal"), regression.aictest = NULL) | |
monthplot(m) | |
``` | |
![](https://i.imgur.com/v0jYXoO.png) | |
``` r |
### Preparing the Time Trip
library(timemachine)
# assuming EXP is available one period before
# (for demonstration only)
swiss_history2 <- swiss_history %>%
mutate(pub_date = if_else(var == "EXP", add_to_date(pub_date, "-1 quarter"), pub_date)) %>%
#' Secondary Axis in ggplot2 | |
#' | |
#' To use a secondary axis in ggplot, the data shown on the right axis needs to | |
#' be transformed. Use `sec_scale` to calculate the scale adjutments. Use | |
#' `apply_sec_scale` to apply the scale adjutments within ggplot. See | |
#' examples. | |
#' | |
#' @param df1 a ts-boxable object, plotted on the left axis | |
#' @param df2 a ts-boxable object, plotted on the right axis | |
#' @param x numeric vector |
Location | Fertility | Agriculture | Examination | Education | Catholic | Infant.Mortality | |
---|---|---|---|---|---|---|---|
Courtelary | 80.2 | 17 | 15 | 12 | 9.96 | 22.2 | |
Delemont | 83.1 | 45.1 | 6 | 9 | 84.84 | 22.2 | |
Franches-Mnt | 92.5 | 39.7 | 5 | 5 | 93.4 | 20.2 | |
Moutier | 85.8 | 36.5 | 12 | 7 | 33.77 | 20.3 | |
Neuveville | 76.9 | 43.5 | 17 | 15 | 5.16 | 20.6 | |
Porrentruy | 76.1 | 35.3 | 9 | 7 | 90.57 | 26.6 | |
Broye | 83.8 | 70.2 | 16 | 7 | 92.85 | 23.6 | |
Glane | 92.4 | 67.8 | 14 | 8 | 97.16 | 24.9 | |
Gruyere | 82.4 | 53.3 | 12 | 7 | 97.67 | 21 |
library(tsbox)
suppressMessages(library(quantmod))
suppressMessages(library(ggplot2))
ts_fred <- function(..., class = "data.frame") {
symb <- c(...)
dta.env <- new.env()
suppressMessages(getSymbols(symb, env = dta.env, src = "FRED"))
z <- data.table::rbindlist(lapply(as.list(dta.env), ts_dt), idcol = "id")
It's relatively straigtforward to read the Gapminder data directly from the Systema Globalis repo into R. Here's the code to produce an extract with the Gapminder core variables.
The result is stored below and can be accessed by:
gapminder <- read.csv("https://gist.githubusercontent.com/christophsax/8d2814a7d3e464d020e38a9cb468930b/raw/361889b5ea7830e2bf8f28f40239a2a08765432d/gapminder.csv", stringsAsFactors = FALSE)
library(ggplot2)