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.
First we must plot the time series to get a general understanding.
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.
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 313.2 323.5 335.2 337.1 350.3 366.8
## [1] 1959 1
## [1] 1997 12
## [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.
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.
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.
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.