Summarizes random walk data by computing statistical measures.
Value
A tibble containing the summarized statistics for each group, including mean, median, range, quantiles, variance, standard deviation, and more.
Details
This function requires that the input data frame contains a column named 'walk_number' and that the value to summarize is provided. It computes statistics such as mean, median, variance, and quantiles for the specified value variable. #' This function summarizes a data frame containing random walk data by computing various statistical measures for a specified value variable, grouped by a specified grouping variable. It checks for necessary attributes and ensures that the data frame is structured correctly.
Examples
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
# Example data frame
walk_data <- random_normal_walk(.initial_value = 100)
# Summarize the walks
summarize_walks(walk_data, cum_sum_y, walk_number) |>
glimpse()
#> Registered S3 method overwritten by 'quantmod':
#> method from
#> as.zoo.data.frame zoo
#> Rows: 25
#> Columns: 16
#> $ walk_number <fct> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, …
#> $ fns <chr> "random_normal_walk", "random_normal_walk", "random_nor…
#> $ fns_name <chr> "Random Normal Walk", "Random Normal Walk", "Random Nor…
#> $ mean_val <dbl> 99.80155, 101.30383, 99.70486, 99.51205, 100.70323, 98.…
#> $ median <dbl> 99.89343, 101.38847, 99.69436, 99.46174, 100.45287, 98.…
#> $ range <dbl> 1.3355731, 1.8197017, 1.3602687, 1.9534922, 1.6387156, …
#> $ quantile_lo <dbl> 99.23697, 100.22654, 99.20644, 98.85699, 100.02862, 97.…
#> $ quantile_hi <dbl> 100.44387, 101.99223, 100.33103, 100.59969, 101.55541, …
#> $ variance <dbl> 0.14980060, 0.17470409, 0.11660368, 0.21372752, 0.29829…
#> $ sd <dbl> 0.3894828, 0.4206133, 0.3436272, 0.4652235, 0.5496136, …
#> $ min_val <dbl> 99.18578, 100.20030, 99.06826, 98.74089, 99.98771, 96.8…
#> $ max_val <dbl> 100.52136, 102.02001, 100.42853, 100.69438, 101.62643, …
#> $ harmonic_mean <dbl> 99.80005, 101.30210, 99.70369, 99.50991, 100.70027, 98.…
#> $ geometric_mean <dbl> 99.80080, 101.30297, 99.70428, 99.51098, 100.70175, 98.…
#> $ skewness <dbl> -0.03882987, -0.89501255, 0.25871945, 0.70775424, 0.305…
#> $ kurtosis <dbl> -1.24842071, 0.72826850, -0.88539156, -0.02993314, -1.5…
summarize_walks(walk_data, y) |>
glimpse()
#> Warning: There was 1 warning in `dplyr::summarize()`.
#> ℹ In argument: `geometric_mean = exp(mean(log(y)))`.
#> Caused by warning in `log()`:
#> ! NaNs produced
#> Rows: 1
#> Columns: 15
#> $ fns <chr> "random_normal_walk"
#> $ fns_name <chr> "Random Normal Walk"
#> $ mean_val <dbl> -0.004516498
#> $ median <dbl> -0.005050845
#> $ range <dbl> 0.6278678
#> $ quantile_lo <dbl> -0.1957323
#> $ quantile_hi <dbl> 0.1873037
#> $ variance <dbl> 0.009748807
#> $ sd <dbl> 0.09876074
#> $ min_val <dbl> -0.3043135
#> $ max_val <dbl> 0.3235543
#> $ harmonic_mean <dbl> 0.3463741
#> $ geometric_mean <dbl> NaN
#> $ skewness <dbl> 0.001151875
#> $ kurtosis <dbl> -0.05099986
# Example with missing value variable
# summarize_walks(walk_data, NULL, group) # This will trigger an error.