sim_pop: Simulating population from a data generating process

View source: R/simulation.R

sim_popR Documentation

Simulating population from a data generating process

Description

This function can be used to generate population data from a data generating process for testing downscaling.

Usage

sim_pop(
  n,
  J = 2,
  tt = 2,
  k = 2,
  alphas = matrix(stats::runif(tt * (J - 1)), tt, J) * 2,
  xmat = matrix(stats::rnorm(n * k), n, k),
  betas = matrix(stats::rnorm(k * J), k, J)
)

Arguments

n

Number of spatial observations n.

J

Number of population types J. Defaults to two

tt

Number of time steps to simulate T. Defaults to two.

k

Number of covariates to simulate k. Defaults to two.

alphas

Matrix of dimensions T \times J. Provides the true values for all \alpha_{jt}. Defaults to a random uniform matrix.

xmat

Matrix of dimensions n \times k. Provides the values for the matrix X. Defaults to a matrix of random, normally distributed values (with zero mean and uniform variance).

betas

Matrix of dimensions k \times J. Provides the values for \beta_1,...,\beta_J. Defaults to a matrix of random, normally distributed values (with zero mean and uniform variance).

Details

The generated Poisson model over J distinct population tyes (with j',j = 1,...,J) takes the form:

y_{ijt} = \exp{\exp(\alpha_{jt} + X_i \beta_{j})}

with X_i being the i-th row of the n \times k matrix X. \beta_j is the k \times J matrix of population type specific slope parameters. \alpha_{jt} are population type specific intercepts, which are typically optimised using the bias correction method. These are assumed to vary over time.

The function generates the NT \ times J matrix Y. Based on this, the function generates a set of targets T_{jt} for downscaling. These are calculated by:

T_{jt} = \sum^n_{i=1} y_{ijt}

The output of this function can be directly used in downscale_pop.

Value

A list with the generated \alpha (alphas), X (xmat), \beta (betas), Y (Y), and T (targets). The returned values are in long format as required by downscale_pop.

Examples

dgp1 = sim_pop(n = 100)

tkrisztin/downscalr documentation built on June 2, 2025, 1:16 a.m.