Simulate complex numbers with given distributions for the modulus and the argument and real numbers with given distributions for the absolute value and the sign. Some of the values may be partially or fully specified.

sim_complex(abs, arg, absgen = "runif", absarg = list(0, 1),
arggen = runif, argarg = list(-pi, pi), ...)

sim_real(abs, sign, signprob = 0.5, absgen = "runif",
absarg = list(0, 1), ...)

## Arguments

abs vector of absolute values. vector of signs (1 or -1). probability for a positive sign. vector of arguments (of complex numbers). generator for the absolute values, a function or a character string naming a function. arguments for absgen. generator for the arguments of the complex numbers, a function or a string naming a function. arguments for arggen. not used, simplifies the call from sim_numbers.

## Details

sim_real simulates real numbers by simulating separately their absolute values and signs. sim_complex simulates complex numbers by simulating separately their moduli and arguments.

Both functions replace NA's in argument abs with values simulated by the function specified by absgen. Arguments for absgen are specified by the (possibly named) list absarg.

Similarly, sim_complex replaces NA's in argument arg with values simulated according to arggen and argarg.

Further, sim_real replaces NA's in argument sign with a random sample of ones and minus ones, where the probability for the positive value is signprob.

Only NA entries in abs, arg and sign are filled with simulated values, the remaining entries are left unchanged. This means that some (and even all) values may be specified partially or completely.

abs is combined with arg or sign to create the result. These arguments are expected to be of matching shape and length but this is not enforced and the usual recycling rules will apply if this is not the case (not recommended to rely on this).

The default range for the (complex) argument is (-pi,pi).

## Value

for sim_real, a vector of real numbers

for sim_complex, a vector of complex numbers

## Note

Currently the shape of the result for sim_real is the same as that of argument abs. But sim_complex always returns a vector. Probably this inconsistency should be removed.

sim_numbers which offers more flexible interface to these functions.

## Examples

## x[1] is fixed to 1, x[2] is negative with random magnitude:
x <- sim_real(c(1,NA,NA,NA), c(1, -1, NA, NA))

## z[1] fixed to 1, the remaining elements of z
## have random magnitude and fixed arguments:
z <- sim_complex(c(1,NA,NA,NA), c(0, pi/2, pi, -pi/2))

## without restrictions
sim_complex(rep(NA,4))#> [1] -0.7159858-0.1564620i  0.3306168-0.6981991i  0.7150111-0.5036719i
#> [4] -0.0585658-0.1648462isim_real(rep(NA,4))#> [1] -0.40353812  0.06366146  0.38870131 -0.97554784
## moduli unrestricted; arguments restricted
sim_complex(rep(NA,4), c(0, pi/2, pi, -pi/2))#> [1]  0.98053967+0.0000000i  0.00000000+0.7415215i -0.05144628+0.0000000i
#> [4]  0.00000000-0.5302125i