Linear Transformations
linear_transform.Rd
shift()
a distribution by adding a constant, or multiply()
a
distribution by a constant. flip()
is a specific case of multiplying
a distribution by -1
, resulting in "flipping" the distribution about 0.
Value
A distribution, shifted or multiplied by the constant. Specifically, a distribution with subclass "shift", "scale", or "flip".
Details
Specifically, if X
is a random variable coming from a
distribution, then the resulting distributions are as follows:
For
shift()
, is the distribution ofX + constant
.For
multiply()
, is the distribution ofX * constant
.For
flip()
, is the distribution of-X
.
Although the multiply()
function accepts negative constants,
the corresponding "scale" distribution class only holds positive
constants, delegating a potential negative sign to the "flip" class.
Examples
d_pois <- distionary::dst_pois(1.1)
d_norm <- distionary::dst_norm(4, 1)
d_unif <- distionary::dst_unif(0, 1)
# Shift a Poisson distribution by 1.
shift(d_pois, 1)
#> [1] "shift" "dst"
#>
#> components :
#> $distribution
#> [1] "pois" "parametric" "dst"
#>
#> name :
#> [1] "pois"
#>
#> $shift
#> [1] 1
#>
d_pois + 1
#> [1] "shift" "dst"
#>
#> components :
#> $distribution
#> [1] "pois" "parametric" "dst"
#>
#> name :
#> [1] "pois"
#>
#> $shift
#> [1] 1
#>
# Multiply a Uniform distribution by 2.
multiply(d_unif, 2)
#> [1] "scale" "dst"
#>
#> components :
#> $distribution
#> [1] "unif" "parametric" "dst"
#>
#> name :
#> [1] "unif"
#>
#> $scale
#> [1] 2
#>
d_unif * 2
#> [1] "scale" "dst"
#>
#> components :
#> $distribution
#> [1] "unif" "parametric" "dst"
#>
#> name :
#> [1] "unif"
#>
#> $scale
#> [1] 2
#>
# Flip a Normal distribution.
flip(d_norm)
#> [1] "negative" "dst"
#>
#> distribution :
#> [1] "norm" "parametric" "dst"
#>
#> name :
#> [1] "norm"
-d_norm
#> [1] "negative" "dst"
#>
#> distribution :
#> [1] "norm" "parametric" "dst"
#>
#> name :
#> [1] "norm"
# Combine multiple operations:
4 - 2 * d_pois
#> [1] "shift" "dst"
#>
#> components :
#> $distribution
#> [1] "negative" "dst"
#>
#> distribution :
#> [1] "scale" "dst"
#>
#> components :
#> $distribution
#> [1] "pois" "parametric" "dst"
#>
#> name :
#> [1] "pois"
#>
#> $scale
#> [1] 2
#>
#>
#> $shift
#> [1] 4
#>