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.37422, 99.14832, 99.30183, 99.54731, 100.00967, 100.…
#> $ median <dbl> 99.22507, 99.12260, 99.14530, 99.56916, 100.03673, 100.…
#> $ range <dbl> 1.6702035, 1.7192108, 1.3793621, 1.0936667, 0.7246319, …
#> $ quantile_lo <dbl> 98.72405, 98.55386, 98.64469, 98.97943, 99.68817, 99.86…
#> $ quantile_hi <dbl> 100.27413, 100.11414, 99.95320, 100.03119, 100.24455, 1…
#> $ variance <dbl> 0.24567887, 0.14426274, 0.17370115, 0.08828192, 0.02889…
#> $ sd <dbl> 0.4956600, 0.3798194, 0.4167747, 0.2971227, 0.1699798, …
#> $ min_val <dbl> 98.67767, 98.49835, 98.60665, 98.95722, 99.66696, 99.85…
#> $ max_val <dbl> 100.34787, 100.21756, 99.98601, 100.05089, 100.39159, 1…
#> $ harmonic_mean <dbl> 99.37178, 99.14689, 99.30010, 99.54644, 100.00938, 100.…
#> $ geometric_mean <dbl> 99.37300, 99.14760, 99.30096, 99.54688, 100.00952, 100.…
#> $ skewness <dbl> 0.529493030, 0.913117028, 0.180208987, -0.190895194, -0…
#> $ kurtosis <dbl> -1.14650249, 0.87761015, -1.32915687, -0.84946617, -0.7…
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.0005154536
#> $ median <dbl> 0.002946834
#> $ range <dbl> 0.6436037
#> $ quantile_lo <dbl> -0.1943871
#> $ quantile_hi <dbl> 0.1900136
#> $ variance <dbl> 0.009756546
#> $ sd <dbl> 0.09877523
#> $ min_val <dbl> -0.314552
#> $ max_val <dbl> 0.3290517
#> $ harmonic_mean <dbl> -0.04812531
#> $ geometric_mean <dbl> NaN
#> $ skewness <dbl> -0.09677662
#> $ kurtosis <dbl> -0.07893013
# Example with missing value variable
# summarize_walks(walk_data, NULL, group) # This will trigger an error.