From 63d2a9c0a016459936c51416b1e1855efde3b250 Mon Sep 17 00:00:00 2001 From: Mateusz Staniak Date: Tue, 10 Jul 2018 16:50:03 +0000 Subject: [PATCH] version 0.9.3 --- DESCRIPTION | 8 ++++---- MD5 | 12 ++++++------ NEWS.md | 6 +++++- R/simulations_kendall_rw.R | 8 ++++---- README.md | 20 ++++++++++++++------ inst/doc/behaviour.html | 36 ++++++++++++++++++------------------ inst/doc/kendall_rws.html | 30 +++++++++++++++--------------- 7 files changed, 66 insertions(+), 54 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 7cc8ea9..5f1a547 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: kendallRandomWalks Title: Simulate and Visualize Kendall Random Walks and Related Distributions -Version: 0.9.2 +Version: 0.9.3 Authors@R: person("Mateusz", "Staniak", email = "mateusz.staniak@math.uni.wroc.pl", role = c("aut", "cre")) Description: Kendall random walks are a continuous-space Markov chains generated by the Kendall generalized convolution. This package provides tools @@ -11,13 +11,13 @@ Depends: R (>= 3.3) License: MIT + file LICENSE Encoding: UTF-8 LazyData: true -Imports: ggplot2, dplyr, tidyr, EnvStats, tibble, nleqslv +Imports: ggplot2, dplyr, tibble, actuar RoxygenNote: 6.0.1 Suggests: knitr, rmarkdown, testthat, covr VignetteBuilder: knitr NeedsCompilation: no -Packaged: 2018-06-05 18:33:35 UTC; mtst +Packaged: 2018-07-10 17:32:39 UTC; mtst Author: Mateusz Staniak [aut, cre] Maintainer: Mateusz Staniak Repository: CRAN -Date/Publication: 2018-06-06 11:17:55 UTC +Date/Publication: 2018-07-10 17:50:03 UTC diff --git a/MD5 b/MD5 index c3c7ece..9898bcc 100644 --- a/MD5 +++ b/MD5 @@ -1,21 +1,21 @@ -802161c45338e0f65405afc5c1e31b88 *DESCRIPTION +f7f6b43c736ef5b0400aa2373dcde4fd *DESCRIPTION 127cbfaba59733e6a2c6a1cb068efef0 *LICENSE bf40ddb040e1475489436cc818624dbd *NAMESPACE -d2b472e46a573de5a3285e5a9ddcc53c *NEWS.md +b82814236c9c10a99ac34f46fc32918f *NEWS.md 321cb795d29c29dd544278a672d66d3a *R/barrier_crossing.R 44742a93c96bea8c1e66ebddf3ee3b11 *R/exact_ladder_moments.R 0c0ea4b64e63a12cf1c77d1e192a3586 *R/kendallRandomPackage.R -342bab9561ad2b935f5ef3d3363b1951 *R/simulations_kendall_rw.R +ccb7d17464092e945420bf1a6d0a7685 *R/simulations_kendall_rw.R 0cdf1ddbbe6db456b3e2761647dbc7cb *R/stable_kendall_distribution.R ecc63136d6a466f61e1ed491dad20450 *R/stable_kendall_fit.R -b6b60ec945f8a1a226a2bcb0d375a493 *README.md +a418d728965ce0877432a58f9c2c7afe *README.md b84cc913d6ce0d3aaec243382c8dfe9d *build/vignette.rds a48fdecfe2262ed77d8b61e89c783509 *inst/doc/behaviour.R 7161eac5f4c752b0251bead321523c98 *inst/doc/behaviour.Rmd -95472fdbb4e06f604fc52498a3335f38 *inst/doc/behaviour.html +ad854ec301fd3e50eef4fb93a9d4a793 *inst/doc/behaviour.html 57b6d03ded5319bbee71626929038290 *inst/doc/kendall_rws.R a2ba97d109c7e774099396657baf7dee *inst/doc/kendall_rws.Rmd -11a135a403e922a11064872a6a20344e *inst/doc/kendall_rws.html +e51e0c4975e233bfc10da4c19d516d50 *inst/doc/kendall_rws.html 90cfad0d498cc81140a99dcad617506f *man/Qn.Rd bac14a58926029a0fea03be2cf7e4b67 *man/U.Rd dce1d5e75d456212d0000537beb067d8 *man/Z.Rd diff --git a/NEWS.md b/NEWS.md index f02d52e..3581c71 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,8 +1,12 @@ +# kendallRandomPackagae 0.9.3 + +* `EnvStats` dependency replaced by `actuar`. + # kendallRandomPackage 0.9.2 * Functions for transformations and summaries of simulations of Kendall random walks (`summarise_kendall_rw` and `mutate_kendall_rw`). - + # kendallRandomPackage 0.9.1 * Numerical computation of G function (so also Williamson transform) diff --git a/R/simulations_kendall_rw.R b/R/simulations_kendall_rw.R index b8d3772..bb28ad9 100644 --- a/R/simulations_kendall_rw.R +++ b/R/simulations_kendall_rw.R @@ -53,14 +53,14 @@ simulateOneTrajectory <- function(trajectory_length, step_dist, alpha, symmetric = FALSE, ...) { Y <- step_dist(trajectory_length, ...) if(symmetric) { - theta <- EnvStats::rpareto(trajectory_length, - 1, - 2*alpha)*sample(c(-1, 1), + theta <- actuar::rpareto1(trajectory_length, + 2*alpha, + 1)*sample(c(-1, 1), trajectory_length, prob = c(0.5, 0.5), replace = TRUE) } else { - theta <- EnvStats::rpareto(trajectory_length, 1, 2*alpha) + theta <- actuar::rpareto1(trajectory_length, 2*alpha, 1) } Xn <- vector("numeric", trajectory_length ) diff --git a/README.md b/README.md index b3fc6a2..0f060ab 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ -# kendallRandomPackage +# kendallRandomWalks +[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/kendallRandomWalks)](https://cran.r-project.org/package=kendallRandomWalks) +[![Total Downloads](http://cranlogs.r-pkg.org/badges/grand-total/kendallRandomWalks?color=orange)](https://cranlogs.r-pkg.org/badges/grand-total/kendallRandomWalks) [![Travis-CI Build Status](https://travis-ci.org/mstaniak/kendallRandomPackage.svg?branch=master)](https://travis-ci.org/mstaniak/kendallRandomPackage) [![Coverage Status](https://img.shields.io/codecov/c/github/mstaniak/kendallRandomPackage/master.svg)](https://codecov.io/github/mstaniak/kendallRandomPackage?branch=master) @@ -8,26 +10,32 @@ Simulations and distributions related to Kendall random walks: [visit dedicated project page on Researchgate](https://www.researchgate.net/project/First-order-Kendall-maximal-autoregressive-processes-and-their-applications) -Install the newest version: +To get started, install stable CRAN version ->devtools::install_github("mstaniak/kendallRandomPackage") +> install.packages("kendallRandomWalks") + +or the newest version from Github: + +> devtools::install_github("mstaniak/kendallRandomPackage") Help: ->?kendallRandomPackage +> ?kendallRandomPackage Main functionalities: * `simulate_kendall_rw` functions simulates Kendall random walks for a given step distribution. The simulation can be then plotted using generic `plot` function. * `transform_kendall_rw` function allows user to play with different scalings and transformations of Kendall random walks to study its properties related to convergence. + * `summarise_kendall_rw` and `mutate_kendall_rw` functions allow user to modify or summarise simulated trajectories. * `ladder_moment` and `ladder_height` functions help study distribution of first ladder moment and first ladder height empirically. * `ladder_moment_pmf` gives exact PMF for first ladder moment. * `pkend`, `dkend`, `qkend` and `rkend` are typical functions related to the stable Kendall distribution. * `g_function` calculates Williamson transform numerically. -See vignette for examples. +See vignettes for examples. If you have a feature request or you found a bug, please leave an issue. -The goal of this package is to let anyone interested in Kendall convolution/generalized convolutions get familiar with them through visual means and experimentation. + +The goal of this package is to let anyone interested in Kendall convolution/generalized convolutions get familiar with them through visual means and experimentation and aid research in this area by providing tools for simulations. Acknowledgement diff --git a/inst/doc/behaviour.html b/inst/doc/behaviour.html index 5712caa..f06ea60 100644 --- a/inst/doc/behaviour.html +++ b/inst/doc/behaviour.html @@ -81,34 +81,34 @@

Mateusz Staniak

walks <- simulate_kendall_rw(1000, 1000, rnorm, 0.5, T)

Example trajectory

plot(walks, max_id = 1)
-

+

Number of unique states

ggplot(summarise_kendall_rw(walks, n_distinct), aes(x = aggregated)) +
   # geom_histogram() +
   theme_bw() +
   geom_density()
-

+

Jumps

diffs <- mutate_kendall_rw(walks, function(x) x - lag(x))
 diffs
 #> # A tibble: 1,000,000 x 2
 #> # Groups:   sim_id [1,000]
-#>    sim_id     sim
-#>     <int>   <dbl>
-#>  1      1  NA    
-#>  2      1  -1.02 
-#>  3      1   0.   
-#>  4      1  -0.478
-#>  5      1   3.88 
-#>  6      1  -5.04 
-#>  7      1  26.0  
-#>  8      1   0.   
-#>  9      1   0.   
-#> 10      1   0.   
+#>    sim_id    sim
+#>     <int>  <dbl>
+#>  1      1  NA   
+#>  2      1  -1.02
+#>  3      1   0.  
+#>  4      1  -2.15
+#>  5      1   0.  
+#>  6      1  34.4 
+#>  7      1   0.  
+#>  8      1   0.  
+#>  9      1   0.  
+#> 10      1   0.  
 #> # ... with 999,990 more rows
 diffs2 <- mutate_kendall_rw(walks, function(x) x - lag(x), F)
 plot(diffs2, max_id = 10)
-

+

Time with no change of state

diffs3 <- mutate_kendall_rw(diffs2, function(x) as.numeric(x != 0), F)
 diffs <- diffs3$simulation
@@ -123,18 +123,18 @@ 

Mateusz Staniak

geom_density() + theme_bw() + ggtitle("Distribution of time with no state-change (by simulation)")
-

+

ggplot(lengths, aes(x = length)) +
   geom_density() +
   theme_bw() +
   ggtitle("Distribution of time with no state-change (aggregated)")
-

+

ggplot(subset(lengths, sim_id < 10), aes(x = id, y = length, color = as.factor(sim_id))) +
   geom_point() +
   theme_bw() +
   geom_line() +
   ggtitle("Time with no state-change in time")
-

+

diff --git a/inst/doc/kendall_rws.html b/inst/doc/kendall_rws.html index 87538f8..20bf18b 100644 --- a/inst/doc/kendall_rws.html +++ b/inst/doc/kendall_rws.html @@ -12,7 +12,7 @@ - + Kendall random walks @@ -70,7 +70,7 @@

Kendall random walks

Mateusz Staniak

-

2018-06-05

+

2018-07-10

@@ -86,9 +86,9 @@

Simulate and plot

#> Step distribution: runif #> Alpha parameter: 0.25 plot(kendall_rws) -

+

plot(simulate_kendall_rw(10, 100, rnorm, 0.76), level = 300)
-

+

Symmetric

kendall_rws_sym <- simulate_kendall_rw(10, 100, rnorm, 0.76, T)
 kendall_rws_sym
@@ -98,40 +98,40 @@ 

Simulate and plot

#> Step distribution: rnorm #> Alpha parameter: 0.76 plot(kendall_rws_sym)
-

+

Barrier crossing

kendall_rws2 <- simulate_kendall_rw(1000, 100, runif, 0.25)
 ladder_moments <- ladder_moment(kendall_rws2, 1000)
 ladder_moments
-#> Mean of the distribution:  15.726 
-#> Standard deviation of the distribution:  9.839397 
+#> Mean of the distribution:  14.25 
+#> Standard deviation of the distribution:  8.692241 
 #> Number of observations:  1000 
 #> Times the level was not crossed:  0 
 #> Quantiles of the distribution: 
 #>   0%  10%  20%  30%  40%  50%  60%  70%  80%  90% 100% 
-#>    3    6    8   10   11   13   15   19   23   29   64
+#>  3.0  5.0  7.0  9.0 10.0 12.0 14.0 17.0 20.2 25.0 60.0
 plot(ladder_moments)
 #> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
-

+


 ladder_heights <- ladder_height(kendall_rws2, 2000)
 ladder_heights
-#> Mean of the distribution:  8438489 
-#> Standard deviation of the distribution:  181627127 
+#> Mean of the distribution:  1865133 
+#> Standard deviation of the distribution:  27607151 
 #> Number of observations:  1000 
 #> Times the level was not crossed:  0 
 #> Quantiles of the distribution: 
 #>           0%          10%          20%          30%          40% 
-#> 2.001583e+03 2.374325e+03 3.013069e+03 3.928392e+03 5.260592e+03 
+#> 2.004828e+03 2.465329e+03 3.087317e+03 4.115649e+03 5.290184e+03 
 #>          50%          60%          70%          80%          90% 
-#> 7.180237e+03 1.095814e+04 1.862697e+04 4.335170e+04 1.705180e+05 
+#> 7.761361e+03 1.124483e+04 2.135192e+04 4.450611e+04 2.145657e+05 
 #>         100% 
-#> 5.583728e+09
+#> 7.522588e+08
 plot(ladder_heights)
 #> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
-

+

Exact first ladder moments distribution with \(G(a)\) computed numerically.

y <- seq(10, 10000, 50)
 ladders <- sapply(y,