Site icon R-bloggers

Introducing healthyR.ts: A Comprehensive R Package for Time Series Analysis

[This article was first published on Steve's Data Tips and Tricks, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
< section id="introduction" class="level1">

Introduction

Hello everyone,

I’m excited to give you an overview of healthyR.ts, an R package designed to simplify and enhance your time series analysis experience. Just like my healthyR package, it is designed to be user friendly.

< section id="what-is-healthyr.ts" class="level1">

What is healthyR.ts?

healthyR.ts is a robust package that integrates seamlessly with your existing R environment, providing a comprehensive toolkit for time series analysis. Its goal is to streamline the workflow, allowing you to focus on insights rather than the intricacies of implementation.

< section id="key-features" class="level1">

Key Features

< section id="versatile-functionality" class="level2">

1. Versatile Functionality

healthyR.ts comes packed with functions to handle various aspects of time series analysis, from basic preprocessing to advanced modeling and forecasting. Whether you need to decompose your series, detect anomalies, or fit complex models, healthyR.ts has got you covered.

< section id="user-friendly-interface" class="level2">

2. User-Friendly Interface

The package is designed with usability in mind. Functions are well-documented and intuitive, making it easier for users at all levels to implement sophisticated time series techniques. You can find a comprehensive list of functions and their detailed descriptions in the Reference Section.

< section id="seamless-integration" class="level2">

3. Seamless Integration

healthyR.ts integrates smoothly with other popular R packages, enhancing its utility and flexibility. This allows you to leverage the strengths of multiple tools within a single workflow, optimizing your analysis process.

< section id="latest-updates" class="level1">

Latest Updates

We’re continually working to improve healthyR.ts, adding new features and refining existing ones based on user feedback and advancements in the field. Check out the Latest News Section to stay updated with the most recent changes and enhancements.

< section id="installation" class="level1">

Installation

You can install the released version of healthyR.ts from CRAN with:

install.packages("healthyR.ts")

And the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("spsanderson/healthyR.ts")
< section id="getting-started" class="level1">

Getting Started

Let’s take a quick look at how you can use healthyR.ts for a variety of problems. Here’s a simple example to get you started:

First, let’s load in our libraries:

library(healthyR.ts)
library(tidyverse)
library(timetk)
library(rsample)

Now, let’s generate some sample data:

# Generate
set.seed(123)
df <- ts_random_walk()

Let’s take a look at our data:

glimpse(df)
Rows: 10,000
Columns: 4
$ run   <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1…
$ x     <dbl> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 1…
$ y     <dbl> -0.056047565, -0.023017749, 0.155870831, 0.007050839, 0.01292877…
$ cum_y <dbl> 943.9524, 922.2248, 1065.9727, 1073.4887, 1087.3676, 1273.8582, …

Now let’s review the function we just used. Here is some information about the ts_random_walk function:

< section id="syntax" class="level2">

Syntax:

ts_random_walk(
  .mean = 0,
  .sd = 0.1,
  .num_walks = 100,
  .periods = 100,
  .initial_value = 1000
)
< section id="arguments" class="level2">

Arguments:

< section id="visualize" class="level2">

Visualize

Now, let’s visualize our data:

df |>
   ggplot(
       mapping = aes(
           x = x
           , y = cum_y
           , color = factor(run)
           , group = factor(run)
        )
    ) +
    geom_line(alpha = 0.8) +
    ts_random_walk_ggplot_layers(df)

library(dplyr)
library(ggplot2)

df |>
    group_by(x) |>
    summarise(
        min_y = min(cum_y),
        max_y = max(cum_y)
    ) |>
    ggplot(
        aes(x = x)
    ) +
    geom_line(aes(y = max_y), color = "steelblue") +
    geom_line(aes(y = min_y), color = "firebrick") +
    geom_ribbon(aes(ymin = min_y, ymax = max_y), alpha = 0.2) +
    ts_random_walk_ggplot_layers(df)

Now we have just gone over how to use a function to generate a simple random walk, this is only scratching the surface of what this package can do. I am going to go over a few more examples and try to break things up into sections.

< section id="examples" class="level1">

Examples

< section id="generating-functions" class="level2">

Generating Functions

We have already gone over how to generate a simple random walk, but there are other functions that can be used to generate data. Here are examples:

< section id="ts_brownian_motion" class="level3">

ts_brownian_motion

# Generate
set.seed(123)
bm <- ts_brownian_motion()
glimpse(bm)
Rows: 1,010
Columns: 3
$ sim_number <fct> sim_number 1, sim_number 2, sim_number 3, sim_number 4, sim…
$ t          <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,…
$ y          <dbl> 0.00000000, 0.00000000, 0.00000000, 0.00000000, 0.00000000,…
bm |>
  ts_brownian_motion_plot(
    .date_col = t,
    .value_col = y,
    .interactive = TRUE
    )
To leave a comment for the author, please follow the link and comment on their blog: Steve's Data Tips and Tricks.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Exit mobile version