The aim of this project is to analyze a given time series data set and forecast it using the Prophet Forecasting System developed by Meta.
The data set used in this project is the built-in data set co2 available in R. The data set represents monthly atmospheric carbon dioxide concentrations observed at Mauna Loa Observatory in Hawaii.
## [1] 1959 1
## [1] 1997 12
## [1] 12
The dataset begins in 1959 and contains monthly observations of atmospheric CO₂ levels.
The plot shows a clear upward trend in atmospheric carbon dioxide levels along with a repeating seasonal pattern.
## Loading required package: Rcpp
## Loading required package: rlang
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
time_values <- time(co2)
date_values <- as.Date(as.yearmon(time_values))
co2_dataframe <- data.frame(
ds = date_values,
y = as.numeric(co2)
)
head(co2_dataframe)## ds y
## 1 1959-01-01 315.42
## 2 1959-02-01 316.31
## 3 1959-03-01 316.50
## 4 1959-04-01 317.56
## 5 1959-05-01 318.13
## 6 1959-06-01 318.00
Prophet requires the data to be stored in a dataframe with two columns: ds (date) and y (value).
## Disabling weekly seasonality. Run prophet with weekly.seasonality=TRUE to override this.
## Disabling daily seasonality. Run prophet with daily.seasonality=TRUE to override this.
Prophet automatically detects long-term trends and seasonal patterns.
future_dates <- make_future_dataframe(prophet_model,
periods = 24,
freq = "month")
forecast_results <- predict(prophet_model, future_dates)
head(forecast_results)## ds trend additive_terms additive_terms_lower additive_terms_upper
## 1 1959-01-01 315.3626 -0.0775880 -0.0775880 -0.0775880
## 2 1959-02-01 315.4469 0.5946394 0.5946394 0.5946394
## 3 1959-03-01 315.5230 1.2325855 1.2325855 1.2325855
## 4 1959-04-01 315.6073 2.4609156 2.4609156 2.4609156
## 5 1959-05-01 315.6888 3.0206586 3.0206586 3.0206586
## 6 1959-06-01 315.7731 2.3515302 2.3515302 2.3515302
## yearly yearly_lower yearly_upper multiplicative_terms
## 1 -0.0775880 -0.0775880 -0.0775880 0
## 2 0.5946394 0.5946394 0.5946394 0
## 3 1.2325855 1.2325855 1.2325855 0
## 4 2.4609156 2.4609156 2.4609156 0
## 5 3.0206586 3.0206586 3.0206586 0
## 6 2.3515302 2.3515302 2.3515302 0
## multiplicative_terms_lower multiplicative_terms_upper yhat_lower yhat_upper
## 1 0 0 314.8084 315.7393
## 2 0 0 315.5727 316.5162
## 3 0 0 316.2826 317.2115
## 4 0 0 317.6122 318.5148
## 5 0 0 318.2027 319.1561
## 6 0 0 317.6363 318.5848
## trend_lower trend_upper yhat
## 1 315.3626 315.3626 315.2850
## 2 315.4469 315.4469 316.0415
## 3 315.5230 315.5230 316.7556
## 4 315.6073 315.6073 318.0682
## 5 315.6888 315.6888 318.7095
## 6 315.7731 315.7731 318.1247
The model forecasts CO₂ levels for the next 24 months.
The dark line represents predicted values, while the shaded region represents uncertainty intervals.
## Warning: `aes_string()` was deprecated in ggplot2 3.0.0.
## ℹ Please use tidy evaluation idioms with `aes()`.
## ℹ See also `vignette("ggplot2-in-packages")` for more information.
## ℹ 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.
This shows the trend and seasonal components of the model.
This project used the Prophet forecasting system to analyze the atmospheric CO₂ data. The data has a strong upward trend and clear yearly seasonality. The forecast indicates that CO₂ levels will continue to rise if the current trends persist.
Prophet Documentation
https://facebook.github.io/prophet/
R Markdown Documentation
https://rmarkdown.rstudio.com