Skip to contents

Create a new DGP (data-generating process).

Usage

create_dgp(.dgp_fun, .name = NULL, ...)

Arguments

.dgp_fun

The data-generating process function.

.name

(Optional) The name of the DGP.

...

Arguments to pass into .dgp_fun().

Value

A new instance of DGP.

Examples

# create an example DGP function
dgp_fun <- function(n, beta, rho, sigma) {
  cov_mat <- matrix(c(1, rho, rho, 1), byrow = T, nrow = 2, ncol = 2)
  X <- MASS::mvrnorm(n = n, mu = rep(0, 2), Sigma = cov_mat)
  y <- X %*% beta + rnorm(n, sd = sigma)
  return(list(X = X, y = y))
}

# create DGP (with uncorrelated features)
dgp_uncorr <- create_dgp(.dgp_fun = dgp_fun,
                         .name = "Uncorrelated Linear Gaussian DGP",
                         # additional named parameters to pass to dgp_fun()
                         n = 200, beta = c(1, 0), rho = 0, sigma = 1)
# create DGP (with correlated features)
dgp_corr <- create_dgp(.dgp_fun = dgp_fun,
                       .name = "Correlated Linear Gaussian DGP",
                       # additional named parameters to pass to dgp_fun()
                       n = 200, beta = c(1, 0), rho = 0.7, sigma = 1)

# create DGP from a function in the built-in DGP library
dgp <- create_dgp(.dgp_fun = dgpoix::linear_gaussian_dgp,
                  .name = "Linear Gaussian DGP",
                  # additional named parameters to pass to linear_gaussian_dgp()
                  n = 100, p_obs = 10, err = rnorm)