create_dgp | R Documentation |
DGP
(data-generating process)Create a DGP which can generate()
data in an Experiment.
create_dgp(.dgp_fun, .name = NULL, ...)
.dgp_fun |
The user-defined data-generating process function. |
.name |
(Optional) An optional name for the |
... |
User-defined default arguments to pass to |
A new DGP object.
# create an example DGP function
dgp_fun <- function(n, beta, rho, sigma) {
cov_mat <- matrix(c(1, rho, rho, 1), byrow = TRUE, 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 <- create_dgp(.dgp_fun = dgp_fun,
.name = "Linear Gaussian DGP",
# additional named parameters to pass to dgp_fun() by default
n = 50, beta = c(1, 0), rho = 0, sigma = 1)
print(dgp)
data_uncorr <- dgp$generate()
cor(data_uncorr$X)
data_corr <- dgp$generate(rho = 0.7)
cor(data_corr$X)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.