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. Examples 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: ts_brownian_motion # Generate set.seed(123) bm ts_brownian_motion_plot( .date_col = t, .value_col = y, .interactive = TRUE ) ts_geometric_brownian_motion gm ts_brownian_motion_plot( .date_col = t, .value_col = y, .interactive = TRUE ) Plotting Functions The package also includes a variety of plotting functions to help you visualize your data. Here are a few examples: ts_vva_plot # Generate set.seed(123) df filter(run == 1) glimpse(df) Rows: 200 Columns: 4 \$ run 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1… \$ x 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 1… \$ y -0.056047565, -0.023017749, 0.155870831, 0.007050839, 0.01292877… \$ cum_y 943.9524, 922.2248, 1065.9727, 1073.4887, 1087.3676, 1273.8582, … ts_vva_plot( .data = df, .date_col = x, .value_col = cum_y ) \$data \$data\$augmented_data_tbl # A tibble: 600 × 3 x name value 1 1 Cum_y 944. 2 1 Velocity NA 3 1 Acceleration NA 4 2 Cum_y 922. 5 2 Velocity -21.7 6 2 Acceleration NA 7 3 Cum_y 1066. 8 3 Velocity 144. 9 3 Acceleration 165. 10 4 Cum_y 1073. # ℹ 590 more rows \$plots \$plots\$static_plot Warning: Removed 2 rows containing missing values or values outside the scale range (`geom_line()`). \$plots\$interactive_plot Filtering Functions ts_compare_data Compare data over time periods: data_tbl select(-index) ts_compare_data( .data = data_tbl , .date_col = date_col , .start_date = "1955-01-01" , .end_date = "1955-12-31" , .periods_back = "2 years" ) |> summarise_by_time( .date_var = date_col , .by = "year" , visits = sum(value) ) # A tibble: 2 × 2 date_col visits 1 1953-01-01 2700 2 1955-01-01 3408 ts_time_event_analysis_tbl tst ts_event_analysis_plot( .plot_type = "mean", .plot_ci = TRUE, .interactive = FALSE ) Simulator ts_arima_simiulator Simulate an arima model and visualize the results: output " />
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

# 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.

# 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.

# Key Features

## 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.

## 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.

## 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.

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.

# 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")```

# 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:

## Syntax:

```ts_random_walk(
.mean = 0,
.sd = 0.1,
.num_walks = 100,
.periods = 100,
.initial_value = 1000
)```

## Arguments:

• `.mean`: The desired mean of the random walks
• `.sd`: The standard deviation of the random walks
• `.num_walks`: The number of random walks you want generated
• `.periods`: The length of the random walk(s) you want generated
• `.initial_value`: The initial value where the random walks should start

## 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.

# Examples

## 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:

### `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
)```