manipulating.Rmd
library(distplyr) #> #> Attaching package: 'distplyr' #> The following object is masked from 'package:stats': #> #> sd library(magrittr) library(tibble)
distplyr provides a vocabulary of verbs for manipulating distributions.
Unary operations:
condition()
(under development): Restrict the possible values that a random variable can take.+
/-
or shift()
(under development): Add a constant to a random variable.*
//
or scale()
(under development): Multiply a constant to a random variable.Binary operations:
graft_left()
and graft_right()
: Replace the upper or lower tail of a distribution with another distribution.n-ary operations:
mix()
: Make a mixture distribution from two or more distributions.Each of these take a distribution as its first argument(s), and return a distribution, making them pipeable.
Consider an empirical distribution of Ozone measurements from the airquality
dataset:
We can graft a GPD to either end:
o3_with_tails <- o3_raw %>% graft_right(dst_gpd(100, 30, 1), sep_y = 100) plot(o3_raw, "survival", n = 1001, to = 160) plot(o3_with_tails, "survival", n = 1001, lty = 2, add = TRUE)