• Labs icon Lab
  • Data
Labs

Forecast Future Values in R

Time series analysis is a powerful technique used to analyze patterns over time and make predictions based on past data. In this lab, you'll apply powerful forecasting tools like ARIMA, ETS, and Prophet, visualize results using both static and interactive charts, and tune and improve the models.

Labs

Path Info

Level
Clock icon Advanced
Duration
Clock icon 35m
Published
Clock icon May 09, 2025

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. Challenge

    ## Generate Time Series Forecasts Using Prophet

    This lab guides you through the full process of forecasting future values using R, starting from model generation, all the way to tuning and evaluation. You will use the PersonalFinance.xlsx dataset to forecast financial trends like income, expenses, and savings.

    Throughout the lab, you'll apply powerful forecasting tools like ARIMA, ETS, and Prophet, and visualize results using both static and interactive charts.

    Before diving in, the lab ensures all necessary packages are installed and loaded. You will also load the dataset to begin working with time series data.

    💾 Notes:
    Before running any validation tests, make sure to save your changes to tsanalysis.R.
    Use Cmd + S (on macOS) or Ctrl + S (on Windows/Linux) in RStudio to save the file.

    Unsaved changes will not be detected by the validation checks.

    You will work in the file called tsanalysis.R. If you get stuck while working on a task, you have the option to look at the task solution. You can find it by expanding the Feedback section from each task.

  2. Challenge

    ## Forecast and Visualize Future Values with ARIMA

    After cleaning and preparing your data, it's time to start forecasting!

    In this step, you’ll use the ARIMA model to predict future values in your dataset. This is one of the most popular methods for time series forecasting. You'll fit the model automatically, generate forecasts, and then visualize those predictions to interpret patterns and uncertainty.

    By the end of this step, you'll have produced both static and interactive visualizations of your forecasted values.

    What You Will Do

    1. Fit an ARIMA model using auto.arima()
      Automatically select the best model configuration based on your time series data.

    2. Generate forecasts with prediction intervals
      Use the forecast() function to generate 12 future periods of predictions along with upper and lower bounds to quantify uncertainty.

    3. Visualize forecasts using autoplot()
      Quickly create a time series chart showing your forecast and confidence intervals.

    4. Create interactive plots with dygraph()
      Use the dygraphs package to explore your forecast dynamically with zooming, tooltips, and more.

    By completing this step, you'll learn how to go from model fitting to presenting forecasts in both static and interactive formats. This is a core skill in time series analysis.

  3. Challenge

    ## Tune and Improve Forecasting Models

    Once you've built your initial forecasting models, it's time to improve and evaluate them. This step focuses on tuning your models and comparing their performance using both statistical metrics and error-based accuracy scores.

    You'll start by applying a Box-Cox transformation to stabilize variance in your time series, a crucial step for models like ARIMA that assume constant variance. Then, you'll manually configure and fit both ARIMA and ETS models, giving you full control over their behavior.

    To identify the best model, you'll evaluate and compare:

    • Forecast accuracy using accuracy() metrics:

      • RMSE (Root Mean Squared Error): Measures the standard deviation of the forecast errors. Lower values indicate better fit. RMSE penalizes larger errors more heavily than MAE.

      • MAE (Mean Absolute Error): Measures the average magnitude of the forecast errors. Unlike RMSE, it treats all errors equally. Lower MAE means the model is more consistently close to actual values.

      • MAPE (Mean Absolute Percentage Error): Expresses forecast error as a percentage, making it easier to interpret across different scales. A MAPE below 10% is often considered excellent, 10--20% is good, and above 20% may need improvement.

    • Model quality and complexity using information criteria like:

      • AIC (Akaike Information Criterion): Helps you compare models based on fit and complexity --- lower is better.

      • BIC (Bayesian Information Criterion): Similar to AIC but penalizes complexity more strongly.

    By the end of this step, you'll not only have better-tuned models --- you'll also know how to interpret and compare them objectively to choose the most reliable forecast.

  4. Challenge

    ## Congratulations and Key Takeaways

    🎉 Congratulations! You've completed the Forecast Future Values in R lab!

    Over the past few tasks, you've built a full time series forecasting workflow --- from raw data to validated model comparisons. Here's what you accomplished and why it matters:


    ✅ What You Learned:

    • Prepared your data for forecasting using Prophet and ARIMA-friendly formats

    • Fitted automated and manually tuned models using both Prophet, ARIMA, and ETS techniques

    • Generated forecasts for future periods

    • Visualized predictions with both static (ggplot2) and interactive (dygraph) charts

    • Compared models using accuracy metrics like RMSE, MAE, and MAPE

    • Evaluated model complexity using AIC and BIC to make informed decisions


    📈 Why It Matters:

    Forecasting is a critical skill in data science, finance, operations, and many other domains. The ability to prepare time series data, choose the right model, and communicate trends clearly can help drive smarter, forward-looking decisions.

    By completing this lab, you've built a foundation for creating, tuning, and evaluating forecasting models using R --- and you're ready to apply these skills to real-world data.


    🙌 Nice work --- you've just taken a big step toward mastering time series forecasting in R!
    Keep experimenting, keep improving, and keep forecasting!

Ana Voicu is a software developer passionate about databases, Business Intelligence, and data science. She works on developing enterprise level Business Intelligence solutions for various types of industries, with a focus on performance optimization, pattern recognition, efficient analysis of the business processes, and interactive visualizations.

What's a lab?

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Provided environment for hands-on practice

We will provide the credentials and environment necessary for you to practice right within your browser.

Guided walkthrough

Follow along with the author’s guided walkthrough and build something new in your provided environment!

Did you know?

On average, you retain 75% more of your learning if you get time for practice.