- Prophet - Home
- Prophet - Introduction
- Prophet - Basics of Time Series
- Prophet - Environment Setup
- Prophet - Installation
- Prophet - Installation in R
- Prophet - Getting Started
- Prophet Fundamentals
- Prophet - Data Preparation
- Prophet Useful Resources
- Prophet - Useful Resources
- Prophet - Discussion
Python Prophet - Installation in R
Prophet library in R can be installed directly from CRAN (the official R package repository). This is the recommended method as it installs Prophet along with all necessary dependencies like rstan.
Installing Prophet from CRAN
Open the R console or RStudio and run the following command to install Prophet.
install.packages('prophet')
R will automatically install Prophet and any missing dependencies. After the installation is complete, verify the installation by loading the package and checking the version.
To verify the installation, run the following command −
library(prophet)
packageVersion('prophet')
Following will be the output, displaying the installed version.
[1] '1.1.5'
Testing Prophet in R
After installing Prophet in R, we will verify it with a simple example. Here's a basic script to check if Prophet is working correctly.
Load the library −
library(prophet)
Create a sample dataset −
df >- data.frame(
ds = seq(as.Date('2020-01-01'), by = 'day', length.out = 100),
y = 1:100
)
This creates a data frame with dates from January 1, 2020, to April 9, 2020, and a numeric variable (y) that increases by 1 each day.
Fit the Prophet model −
m <- prophet(df)
Print a success message −
print("Prophet is working correctly!")
Following will be the output which confirms that Prophet is working properly.
[1] "Prophet is working correctly!"
Platform-Specific Tips for Installing Prophet in R
Following are some platform-specific tips for installing Prophet in R −
Windows: Install Rtools, which provides the necessary build tools for compiling packages. Download it here: Rtools for Windows
macOS − To make sure the necessary development tools are installed run the following command in the terminal.
xcode-select --install
Linux − Additional development packages might be required to compile the package. Run the following command −
sudo apt-get install r-base-dev
Using cmdstanr as the Backend for Prophet
Alternatively, cmdstanr can be used as the backend for Prophet instead of the default rstan. cmdstanr is an R interface to CmdStan, which is the C++ implementation of Stan. After installing Prophet, follow the steps below to set up and use cmdstanr.
Install cmdstanr and required dependencies −
install.packages(c("cmdstanr", "posterior"), repos = c("https://mc-stan.org/r-packages/", getOption("repos")))
If cmdstan is not yet installed, run the following command −
cmdstanr::install_cmdstan()
If cmdstan is already installed, point cmdstanr to your existing cmdstan path −
cmdstanr::set_cmdstan_path(path = "<your_existing_cmdstan_path>")
Finally, set the R_STAN_BACKEND environment variable to CMDSTANR:
Sys.setenv(R_STAN_BACKEND = "CMDSTANR")
Updating or Removing Prophet in R
Once Prophet is installed, it may need to be updated to the latest version or removed completely.
Updating Prophet
To update the package to the latest version, use the following command −
update.packages('prophet')
The R language will check for any available updates for the package and install them automatically if needed.
Removing Prophet
To remove Prophet, just use the following command −
remove.packages('prophet')
Conclusion
In this chapter, we covered how to install Prophet in R and verify that it's working. We also looked at using cmdstanr for better performance if needed. In the next chapter, we'll look at how to load your data and start making forecasts using Prophet.