Skip to contents

Using this function, a distribution, given as a ddf object, can be convolved with itself \(n\) times.

Usage

conv_n(dist, n, desc = NULL)

Arguments

dist

A ddf object, the distribution.

n

A positive integer specifying the number of convolutions to perform.

desc

The description for the resulting ddf object. (optional)

Value

\(n\)-fold convolution as a ddf object.

Details

The \(n\)-fold convolution of a function \(f\) here is defined by letting \(f^{\ast 1} = f\) and then recursively setting \(f^{\ast (n+1)} = f^{\ast n} \ast f\) for all \(n \ge 1\). For more details on the convolution, see conv().

See also

Other convolution functions: conv(), convolve_cpp()

Examples

# Calculate the distribution of the sum of
# throwing a dice four times
conv_n(ddf(1:6), 4, desc = "Distribution of throwing a dice four times")
#> Distribution of throwing a dice four times 
#> 
#> Support:
#>  [1]  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#> 
#> Probabilities:
#>  [1] 0.0007716049 0.0030864198 0.0077160494 0.0154320988 0.0270061728
#>  [6] 0.0432098765 0.0617283951 0.0802469136 0.0964506173 0.1080246914
#> [11] 0.1126543210 0.1080246914 0.0964506173 0.0802469136 0.0617283951
#> [16] 0.0432098765 0.0270061728 0.0154320988 0.0077160494 0.0030864198
#> [21] 0.0007716049
# Model a symmetric random walk starting at 0
# with step size 1 of length 4
conv_n(rademacher(), 4)
#> 4-fold convolution of Rademacher distribution 
#> 
#> Support:
#> [1] -4 -2  0  2  4
#> 
#> Probabilities:
#> [1] 0.0625 0.2500 0.3750 0.2500 0.0625