logo

Section 1: Introduction

1.1 Air Passengers Dataset

In this project, we will look into the dataset called AirPassengers in R that records the monthly total of international airline passengers from January 1949 to December 1960. The figures in the data represent the number of passengers in thousands. It is loaded automatically or can be accessed by

data("AirPassengers")

1.2 Time Series plot

On the first plot above, we clearly see an overall upward trend as time goes by. We can also observe that for every year, peaks occur around mid-year and are generally lower at the start or end of the year. Its trend and seasonal behaviour is further confirmed by the second plot which is its decomposition.

Meta’s Prophet is a forecasting system that works best with time series that have strong seasonal effects and several seasons of historical data.

Section 2: Forecasting using Meta’s Prophet

# Have time series set up as an R dataframe
library(zoo)
## Warning: package 'zoo' was built under R version 4.3.3
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
APdataframe <- data.frame(
    ds = as.Date(as.yearmon(time(AirPassengers))),
    y = as.numeric(AirPassengers)
)
# Load prophet
library(prophet)
## Warning: package 'prophet' was built under R version 4.3.3
## Loading required package: Rcpp
## Warning: package 'Rcpp' was built under R version 4.3.3
## Loading required package: rlang
## Warning: package 'rlang' was built under R version 4.3.3
# Use prophet function to fit the model
pro = prophet(APdataframe)
## Disabling weekly seasonality. Run prophet with weekly.seasonality=TRUE to override this.
## Disabling daily seasonality. Run prophet with daily.seasonality=TRUE to override this.
# Make dataframe with future dates for forecasting (I used 120 months which is equivalent to 10 years)
future = make_future_dataframe(pro, 120,freq = "month", include_history = TRUE)
# Run predict function and plot results
forecast = predict(pro, future)
plot(pro, forecast)

Probably as expected, plot above shows same pattern in the next 10 years as it did the past 29 years with peaks reaching 875,000 passengers by 1970.

# Forecast broken down into trend and yearly seasonality 
prophet_plot_components(pro, forecast)

Let’s see results of prediction for up to 2010:

## Warning: `select_()` was deprecated in dplyr 0.7.0.
## ℹ Please use `select()` instead.
## ℹ The deprecated feature was likely used in the prophet package.
##   Please report the issue at <https://github.com/facebook/prophet/issues>.
## This warning is displayed once per session.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

From 1980, we see that peak has reached around 1.25 million passengers and from 2000 onwards we see that it has consistently been more than 2 million passengers.

Image below shows graph of world air passenger traffic evolution from 1980 to 2020 in billions. With green being international passengers, dark blue being domestic passengers and light blue being total passengers. We can see that it follows the overall upward trend until 2020 where it went crashing down becaue of the pandemic.

Image from: https://www.iea.org/data-and-statistics/charts/world-air-passenger-traffic-evolution-1980-2020

This is very interesting as prediction from Prophet has only reached around 1.25 million by 1980 however from the actual data, it was already 2 million. This is likely due to the accelerate real world growth compared to the trend observed.