generators: Generator functions

Description Usage Arguments Details See Also Examples

Description

These functions are intended to be used with sim_gen and not interactively. They are designed to draw random numbers according to the setting of grouping variables.

Usage

1
2
3
4
5
6
7
8
9
gen_norm(mean = 0, sd = 1, name = "e")

gen_v_norm(mean = 0, sd = 1, name = "v")

gen_v_sar(mean = 0, sd = 1, rho = 0.5, type = "rook", name)

gen_v_ar1(mean = 0, sd = 1, rho = 0.5, groupVar = "idD", timeVar = "idT", name)

gen_generic(generator, ..., groupVars = NULL, name)

Arguments

mean

the mean passed to the random number generator, for example rnorm.

sd

the standard deviation passed to the random number generator, for example rnorm.

name

name of variable as character in which random numbers are stored.

rho

the correlation used to create the variance covariance matrix for a SAR process - see cell2nb.

type

either "rook" or "queen". See cell2nb for details.

groupVar

a variable name identifying groups.

timeVar

a variable name identifying repeated measurements.

generator

a function producing random numbers.

...

arguments passed to generator.

groupVars

names of variables as character. Identify groups within random numbers are constant.

Details

gen_norm is used to draw random numbers from a normal distribution where all generated numbers are independent.

gen_v_norm and gen_v_sar will create an area-level random component. In the case of v_norm, the error component will be from a normal distribution and i.i.d. from an area-level perspective (all units in an area will have the same value, all areas are independent). v_sar will also be from a normal distribution, but the errors are correlated. The variance covariance matrix is constructed for a SAR(1) - spatial/simultanous autoregressive process. mvrnorm is used for the random number generation. gen_v_norm and gen_v_sar expect a variable idD in the data identifying the areas.

gen_generic can be used if your world is not normal. You can specify 'any' function as generator, like rnorm. Arguments in ... are matched by name or position. The first argument of generator is expected to be the number of random numbers (not necessarily named n) and need not to be specified.

See Also

sim_gen, sim_gen_x, sim_gen_e, sim_gen_ec, sim_gen_v, sim_gen_vc, cell2nb

Examples

1
2
3
4
5
6
7
8
9
sim_base() %>% sim_gen_x() %>% sim_gen_e() %>% sim_gen_v() %>% sim_gen(gen_v_sar(name = "vSP"))

# Generic interface
set.seed(1)
dat1 <- sim(base_id() %>%
  sim_gen(gen_generic(rnorm, mean = 0, sd = 4, name = "e")))
set.seed(1)
dat2 <- sim(base_id() %>% sim_gen_e())
all.equal(dat1, dat2)

saeSim documentation built on Feb. 7, 2022, 5:07 p.m.