logo

Introduction

In this project, I analyse the CO2 time series dataset available in R. This time series looks at the atmospheric carbon dioxide concentrations which was measured by the Mauna Loa Observatory in Hawaii. The analysis of this time series includes looking at its trend and seasonality.

Exploring the data

First we must plot the time series to get a general understanding.

plot(co2, main = "Monthly Atmospheric CO2", ylab = "CO2 concentration(ppm)", xlab = "Year")

This plot shows as the years go on the co2 concentration increases showing an upward trend as well as a pattern which shows that there is seasonality.

Properties of the time series

summary(co2)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   313.2   323.5   335.2   337.1   350.3   366.8
start(co2)
## [1] 1959    1
end(co2)
## [1] 1997   12
frequency(co2)
## [1] 12

With this we can see that the time series begins in January 1959 and ends December 1997 - 38 years and there are 12 obsrvations per year meaning the data is recorded monthly.

Preparing the data for Prophet

The data must be stored in a dataframe with two columns called ds (contains the dates) and y (contains the observed values) in order to use the Prophet forecasting model.

library(prophet)
library(zoo)

co2_data <- data.frame(
    ds = as.Date(as.yearmon(time(co2))),
    y = as.numeric(co2)    
         )

Now the Prophet model can be used on the dataset. Prophet is a forecasting model that divides a time series into components like trend and seasonality allowing the predictions of future values.

Forecasting with Prophet

co2_model <- prophet(co2_data)

Now predictions (future forecasting) can be made.

future_dates <- make_future_dataframe(co2_model, periods = 12, freq = "month")
co2_forecast <- predict(co2_model, future_dates)

This forecast can now be plotted to see any trends.

plot(co2_model, co2_forecast)

Forecast components

prophet_plot_components(co2_model, co2_forecast)

Conclusion

After analysing the current time series and forecasting the data shows an upward trend and a repeating seasonal pattern which suggests that CO2 levels are likely to continue to increase in the same manner as the years increase.