Skip to contents

Simulates a territory in the form of a grid with its contiguity, a distribution of individuals across the cells, and a context for different sizes.

Usage

gen_grid(
  x_int,
  y_int,
  contiguityType = "Queen",
  nbIndividuals = x_int * y_int,
  nbMinEmptyZones = 0L,
  nbMetropolises = 0L,
  propInMetropolises = 0.4,
  quantitatives_mat = c(0, 1),
  qualitatives_list = NULL,
  nbQuantitatives = 0L,
  seed = NULL
)

simple_grid(x_int, y_int = x_int, avgPersonsPerCell = 100, seed = NULL)

Arguments

x_int, y_int

dimensions of the grid (positive integers)

contiguityType

type of contiguity to apply for the grid. Two options:

  • "Rook": two cells are contiguous if they share a side.

  • "Queen": two cells are contiguous if they share a side or a vertex.

nbIndividuals

Number of individuals to distribute (strictly positive integer).

nbMinEmptyZones

Number of zones where no individuals should be present. Default is 0. nbMinEmptyZones + nbMetropolises must be smaller than x_int * y_int. (positive integer)

nbMetropolises

Number of zones that should be more populated. Default is 0. nbMinEmptyZones_int + nbMetropolises_int must be smaller than x_int * y_int. (positive integer)

propInMetropolises

Proportion of individuals found in metropolises (if any). (floating point in [0,1])

quantitatives_mat

Characteristics of quantitative variables to generate. If it's a vector, it must be of size 2. The first element indicates the mean, and the second element indicates the standard deviation. If nbQuantitatives > 0, as many i.i.d. variables will be generated with the data specified in the vector. If it's a matrix, it should have 2 columns. The first column corresponds to the means of the independent quantitative variables to be generated. The second column corresponds to the standard deviation of these variables. Each row corresponds to a variable. All quantitative variables follow a normal distribution. (vector of size 2, matrix with 2 columns, or NULL)

qualitatives_list

List of vectors where each vector contains the categories of the qualitative variables to generate. Each qualitative variable will be generated by drawing uniformly from its categories. (list of vectors or NULL)

nbQuantitatives

If quantitatives_mat is a vector, indicates the number of quantitative variables to generate with the characteristics defined in quantitatives_mat. Ignored otherwise. (positive or zero integer)

seed

indicates if the random seed should be fixed before generating values. NULL (default) if the seed must not be fixed. Otherwise must be an integer. (integer)

avgPersonsPerCell

A number representing the average number of individuals in a cell. Must be positive and finite. We have nbIndividuals ≈ x_int * y_int * avgPersonsPerCell. (positive real)

Value

a list including:

  1. contiguity: grid's contiguity matrix

  2. distribution: a dataframe specifying the distribution of sizes across different cells. Contains:

    • nbIndividuals: number of individuals in the zone. The sum equals nbElems_int.

    • emptyFixedZone: TRUE if the zone has been fixed as empty, FALSE otherwise.

    • metropolis: TRUE if the zone is a metropolis, FALSE otherwise.

  3. context: a dataframe where each row corresponds to the context/data related to an individual, and each column is a variable.

Functions

  • simple_grid(): simpler version with "Queen" contiguity, no mandatory empty zones, and no metropolis, and for context 3 quantitative variables with different means and variances

Examples

simple_grid(2L, 3L, 100.0, 123L)
#> $contiguity
#>       (1,1) (2,1) (1,2) (2,2) (1,3) (2,3)
#> (1,1)  TRUE  TRUE  TRUE  TRUE FALSE FALSE
#> (2,1)  TRUE  TRUE  TRUE  TRUE FALSE FALSE
#> (1,2)  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
#> (2,2)  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
#> (1,3) FALSE FALSE  TRUE  TRUE  TRUE  TRUE
#> (2,3) FALSE FALSE  TRUE  TRUE  TRUE  TRUE
#> 
#> $repartition
#>   nbIndividuals emptyFixedZone metropolis
#> 1           106          FALSE      FALSE
#> 2           102          FALSE      FALSE
#> 3            96          FALSE      FALSE
#> 4            92          FALSE      FALSE
#> 5           100          FALSE      FALSE
#> 6           104          FALSE      FALSE
#> 
#> $context
#>      quant_1   quant_2    quant_3
#> 1 -1.6505465 11.339175  -6.127438
#> 2 -0.3497542 13.266288  -5.181410
#> 3  0.7564064  9.386457 -14.997505
#> 4 -0.5388092  7.931617   6.015526
#> 5  0.2272919 -3.215745  -7.422180
#> 6  0.4922286  9.535295  -8.863157
#>