Simulate real or complex numbers using polar form
sim_complex.Rd
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.
Arguments
- abs
vector of absolute values.
- sign
vector of signs (1 or -1).
- signprob
probability for a positive sign.
- arg
vector of arguments (of complex numbers).
- absgen
generator for the absolute values, a function or a character string naming a function.
- absarg
arguments for
absgen
.- arggen
generator for the arguments of the complex numbers, a function or a string naming a function.
- argarg
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).
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.
See also
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.1539519-0.4043646i 0.5765018-0.3482634i 0.2310613-0.8969438i
#> [4] -0.4011607-0.6512398i
sim_real(rep(NA,4))
#> [1] -0.3697421 -0.4132802 -0.9771892 -0.5342905
## moduli unrestricted; arguments restricted
sim_complex(rep(NA,4), c(0, pi/2, pi, -pi/2))
#> [1] 0.37558134+0.000000000i 0.00000000+0.009561688i -0.05548728+0.000000000i
#> [4] 0.00000000-0.783357202i